Skip to the content.

JSDoc Basics

Click ★ if you like the project. Your contributions are heartily ♡ welcome.


An API documentation generator for JavaScript.

Installation and Setup

Step 01:

To install the latest version on npm globally

npm install -g jsdoc

To install the latest version on npm locally and save it in your package’s package.json file:

npm install --save-dev jsdoc

Step 02:

Create a package.json file inside jsdoc-example folder using below command

    npm init -y
{
  "name": "jsdoc-example",
  "version": "1.0.0",
  "description": "An API documentation generator for JavaScript.",
  "main": "index.js",
  "scripts": {
    "doc": "jsdoc -c jsdoc.json"
  },
  "keywords": [
    "documentation",
    "javascript"
  ],
  "author": "pradeep.vwa@gmail.com",
  "license": "ISC",
  "devDependencies": {
    "jsdoc": "^3.6.4"
  }
}

Step 03:

Create a jsdoc.json file inside jsdoc-example folder

{
    "source": {
        "include": ["src"],
        "includePattern": ".js$",
        "excludePattern": "(node_modules/|docs)"
    },
    "plugins": ["plugins/markdown"],
    "templates": {
        "cleverLinks": true,
        "monospaceLinks": true
    },
    "opts": {
        "recurse": true,
        "destination": "./docs",
        "template": "./custom-template",
        "tutorials": "./tutorials",
        "readme": "./README.md"
    }
}

Step 04:

Create a src folder and add the following code

/**
 * Class to create a person object
 */
class Person {
  /**
   * 
   * @param {Object} personInfo Information about the person 
   */
  constructor(personInfo) {
      /**
       * @property {string} name Person Name
       */
      this.name = personInfo.name;
      /**
       * @property {string} name Person Age
       */
      this.age = personInfo.age
  }
  
  /**
   * @property {Function} greet A greeting with the name and age
   * @returns void
   */
  greet() {
      console.log(`Hello, my name is ${this.name} and I am ${this.age}`);
  }
}

Now run jsdoc in your command line

    npm run doc

This will create the docs directory which contains the mini-documentation for the Person Class. Open the docs/index.html file in your browser

JSDoc Image

For more information