With focus on how errors are handled:
There's the style that fs
promotes: One callback where the first argument is an error (if any), and the remaining are response values.
The core library confusingly doesn't always pass an error to the first argument of a callback. http.get
, for example.
Another style is to have two callbacks (callback & errback). Promoted by http://howtonode.org/control-flow-part-ii
I will certainly say that in most cases, you will see the following signature for callbacks.
function (err, result)
This is pretty much standard today.
But it also depends on what you need to "return" like in the createServer example where two objects are passed back to the callback.
createServer(function (req, res) {
});
This is mostly the exception and in most libraries you will see the first form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With