-
Notifications
You must be signed in to change notification settings - Fork 151
How to document a CommonJS module (module.exports)
Lloyd Brookes edited this page Oct 13, 2016
·
3 revisions
1. Say you have a CommonJS module you'd like to document.
function add (a, b) {
return a + b
}
module.exports = add
2. Given that jsdoc2md only generates markdown for documented identifiers and modules, you must document each identifier you want to appear in output - including the module. Therefore, you must use @module
at the top of file to document the module.
/**
* A module for adding two values.
* @module add-two-values
*/
/**
* Add two values.
*/
function add (a, b) {
return a + b
}
module.exports = add
3. Still, the add
function above will be documented as an inner of the module - we want it to be documented as the exported value. So, we explicitly declare it as exported by marking it as an @alias
of the module:
/**
* A module for adding two values.
* @module add-two-values
*/
/**
* Add two values.
* @alias module:add-two-values
*/
function add (a, b) {
return a + b
}
module.exports = add
4. This file will now appear in jsdoc2md output. Without the @module
tag it will not appear.
1. Never document module.exports
directly. It doesn't work. So, avoid this:
/**
* Add two values.
*/
module.exports = function add (a, b) {
return a + b
}
- Home
- How jsdoc2md works
- Additional jsdoc tags supported
- Cherry picking which documentation appears in output
- Showcase ...
- Create ...
- How To ...
- How to use with npm run
- How to use with gulp
- How to create one output file per class
- How to document a AMD module
- How to document a CommonJS module (exports)
- How to document a CommonJS module (module.exports)
- How to document an ES2015 module (multiple named exports)
- How to document an ES2015 module (single default export)
- How to document Promises (using custom tags)
- How to document a ToDo list
- How to document ES2017 features
- How to document TypeScript
- The @typicalname tag
- Linking to external resources
- Param list format options
- Listing namepaths
- Troubleshooting