Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to understand nodejs documentation. How to discover callback parameters

When I read this Node.js API docs, it raises a few questions for me.

  1. In this particular case, is the example they use the only thing that tells me that the 1 parameter in the callback is 'err'?
  2. Going forward do I assume that there is only the 'err' parameter in the callback unless otherwise noted?
  3. Seems to me to me the callback parameters should be listed in a common pattern, like here: "callback <Function>" in the header. Why am I wrong in that thinking?
like image 786
Pompey Magnus Avatar asked Dec 18 '25 05:12

Pompey Magnus


1 Answers

Documentation on fs:

The asynchronous form always takes a completion callback as its last argument. The arguments passed to the completion callback depend on the method, but the first argument is always reserved for an exception. If the operation was completed successfully, then the first argument will be null or undefined.

So, yes, assume callback to fs methods to have signature (err) unless noted otherwise. You should not assume this to be the signature of other packages, unless it is noted similarly.

Is there a standard doc producing tool like javadoc in javascript?

What options are available for documenting your Javascript code?

like image 132
Amadan Avatar answered Dec 20 '25 20:12

Amadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!