Google News
logo
NodeJS - Interview Questions
What is an error-first callback in Node.js ?
Error-first callbacks in Node.js are used to pass errors and data. The very first parameter you need to pass to these functions has to be an error object while the other parameters represent the associated data. Thus you can pass the error object for checking if anything is wrong and handle it. In case there is no issue, you can just go ahead and with the subsequent arguments.
var myPost = new Post({title: 'freetimelearning'});
  myPost.save(function(err,myInstance){
    if(err){
       //handle error and return
     }
      //go ahead with `myInstance`
   });
Advertisement