I’m learning node, and one thing I can’t seem to figure out is callback signatures. It seems that most callbacks are typically of the form
function myCallback(err, doc)
which makes sense. But then I come across some other modules, like node-easyimage, which casually mention examples with different signatures, like
function myCallback(err, stdout, stderr)
There is no mention of which APIs expect which format of callbacks, so I end up digging through the code. But given that callback signatures are almost never mentioned; I feel like there is an unspoken rule that I haven’t read. Is there?
There’s no standard approach unfortunately, so you’ll just have to get accustomed to the techniques each package uses. This is a general Javascript issue and not just node.js, which is why TypeScript for example has such appeal.