• Register
Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

What is an error-first callback

0 votes
22 views
What is an error-first callback?
asked Aug 16 in Node.js by Ankush Mittal

1 Answer

0 votes
Error-first callback:- Error-first callback is used to pass an error and data. The first argument to these functions is an error object and the subsequent arguments represent associated data. So, you can check the first argument that is the error object to see if something went wrong and may be handle it. In case there is no error you can use the subsequent arguments and go ahead.

Following example of error-first callback:-

var post = new Post({title: 'test'});
post.save(function(err,calback){
  if(err){
     //handle error and return
  }
  //go ahead with `calback`
});
answered Aug 22 by Developerhelpway (1,000 points)
...