What is error-first callback?

Error-first callbacks are used to pass errors and data. If something goes wrong, the programmer has to check the first argument because it is always an error argument. Additional arguments are used to pass data.

fs.readFile(filePath, function(err, data) {    
  if (err) {  
    //handle the error  
  }  
  // use the data object  
});  

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *