In node.js, it is considered the standard practice to handle errors in asynchronous functions by returning them as the first argument to the current function's callback. If there is an error, the first parameter is passed an Error object with all the details. Otherwise, the first parameter is null.
As we can see in above example, the callback is called with null as its first argument if there is no error. However, if there is an error, we create an Error object, which then becomes the callback's only parameter.
The callback function shows the reason for this: it allows a user to easily know whether or not an error occurred. If null was not the first argument passed on success, the user would need to check the object being returned and determine them whether or not the object constituted an error - a much more complex and less user-friendly approach.
When using callbacks, if an error comes up, pass it as the first argument. Otherwise, pass null first, and then your return arguments. On the receiving end, inside the callback function, check if the first parameter is non-null; if it is, handle it as an error.