Error first callback - Node.js

Error first callback - The first argument of the callback is reserved for an error object.
A callback function is called error first callback in node, where
  • 1st argument of the callback is reserved for an error object, If an error occurred.
  • 2nd argument of the callback is reserved for any successful response data. If no error occurred.
Example:
fs.readFile('my_text_file.txt', function(error, data) {
	// If an error occurred, handle it (throw error)
	if (error) {
		console.log('Error found:', error);
		throw error;
	}
	// Otherwise, console the data
	console.log(data);
});