How to use jsdoc in my script running on node.js?

I would like to use the jsdoc module to extract documentation records from some source code. I installed the jsdoc module and I can use jsdoc on the command line. But when I require("jsdoc") in my code, nodejs gives the Cannot find module 'jsdoc' error message.

I have nodejs v0.8.25 and JSDoc 3.3.0-alpha2. It is installed both locally and globally. I can use the jsdoc command and I have jsdoc in my node_modules folder. I do not see where the problem is.

Where can I find jsdoc documentation other than using it in the command line interface or how to document js source code. I need API documentation.

+8
javascript require jsdoc
source share
3 answers

I also wanted to use jsdoc as a library, and I came across the same problem as you. You didn’t do anything wrong, it was just not meant to be used as a library.

the problem is on the jsdoc github project page related to this. Hegemonic , a major contributor to JSDoc, said:

JSDoc is not intended to be used as a library

You might want to express your desire to create an API for nodejs on the issue related above.

require('jsdoc') crashes because the main field is not specified in jsdoc package.json . It may default to specifying "index.js" or "main.js", but there is also no such file.

+6
source share

It looks like you did not install jsdoc correctly. Run npm install -g jsdoc from the command line. If you run this in a new terminal window, there should be no problems in the default directory. I had problems when I tried to install the node module globally from my current working directory and for some reason the module does not install globally.

+1
source share

If you are talking about an automatic documentation tool in general, you can also use YUIDoc .

After these three steps, you will receive your automatic documentation:

  • Installation: npm -g install yuidocjs
  • Format your comments on YUIDoc Syntax Reference
  • In the console console yuidoc . on top of the JS source tree
-3
source share

All Articles