• Register

Share:- Whatsapp Facebook Facebook

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

Categories

0 votes
44 views
What is an error-first callback?
in Node.js by

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`
});
by (1.7k points)
...