What is an error-first callback?

Technology CommunityCategory: Node.jsWhat is an error-first callback?
VietMX Staff asked 3 years ago

Error-first callbacks are used to pass errors and data. The first argument is always an error object that the programmer has to check if something went wrong. Additional arguments are used to pass data.

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