Home >> Tutorials >> Error First Callback

Error first callback Node js

  1. First argument of the callback is reserved for an error object. If an error occurred, it will be returned by the first err argument.
  2. Second argument of the callback is reserved for any successful response data.If no error occurred, err will be set to null and data will be returned in the second argument.
fs.readFile('my_text_file.txt', function(err, data) {
// If an error occurred, handle it (throw etc)
if(err) {
	console.log('Error Found:' + err);
	throw err;
}
// Otherwise, log the data
console.log(data);
});
Full Stack Tutorials

Author @FullStackTutorials | View all Articles