apidoc vs documentation vs jsdoc vs swagger-jsdoc
Generating API Documentation for JavaScript Projects
apidocdocumentationjsdocswagger-jsdocSimilar Packages:

Generating API Documentation for JavaScript Projects

apidoc, documentation, jsdoc, and swagger-jsdoc are tools designed to automate the creation of API documentation from source code comments, but they target different standards and workflows. jsdoc is the legacy standard for general JavaScript library documentation, generating static HTML from JSDoc tags. documentation is a modern, modular alternative that supports JSDoc syntax but outputs flexible formats like Markdown and JSON, often used in modern build pipelines. apidoc focuses specifically on REST APIs, using its own unique comment block syntax to generate a standalone, interactive documentation site. swagger-jsdoc acts as a bridge, extracting Swagger (OpenAPI) definitions from JSDoc comments to produce a swagger.json file, which is then rendered by UI tools like Swagger UI or Redoc.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
apidoc09,650556 kB843 years agoMIT
documentation05,7981.88 MB2043 years agoISC
jsdoc015,4651.47 MB460a year agoApache-2.0
swagger-jsdoc01,789710 kB474 months agoMIT

Generating API Documentation: apidoc vs documentation vs jsdoc vs swagger-jsdoc

When building JavaScript applications, keeping API documentation in sync with code is a constant challenge. Writing separate wiki pages or Word docs leads to driftβ€”the code changes, but the docs don't. The solution is to generate documentation directly from source code comments. However, not all generators are built the same. jsdoc, documentation, apidoc, and swagger-jsdoc take very different approaches to this problem. Let's break down how they work, where they shine, and when to avoid them.

πŸ“ Comment Syntax: Standard JSDoc vs Custom Blocks

The first thing you notice is how you write comments. This dictates how easy it is to onboard new developers and whether you can reuse comments for other tools (like IDE tooltips).

jsdoc and documentation both use the industry-standard JSDoc syntax. This is the same syntax your IDE uses to show tooltips when you hover over a function. It's verbose but universally understood.

// jsdoc & documentation syntax
/**
 * Calculates the total price including tax.
 * @param {number} price - The base price.
 * @param {number} taxRate - The tax rate (e.g., 0.2 for 20%).
 * @returns {number} The final total.
 */
function calculateTotal(price, taxRate) {
  return price * (1 + taxRate);
}

apidoc uses its own custom block syntax (@api). It is more concise for REST endpoints but is not recognized by IDEs for type hinting. You effectively write two sets of comments if you want IDE support.

// apidoc syntax
/**
 * @api {post} /orders Create a new order
 * @apiName CreateOrder
 * @apiGroup Orders
 * @apiParam {Number} userId The ID of the user.
 * @apiSuccess {Number} id The new order ID.
 */

swagger-jsdoc also uses standard JSDoc tags, but specifically looks for Swagger/OpenAPI definitions embedded within them. It mixes standard description tags with specific @swagger blocks.

// swagger-jsdoc syntax
/**
 * @swagger
 * /orders:
 *   post:
 *     summary: Create a new order
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userId:
 *                 type: integer
 */

πŸ—οΈ Output Format: Static Sites vs JSON Specs

What you get out of the tool matters just as much as what you put in. Are you building a website? A JSON file for a gateway? A Markdown file for GitHub?

jsdoc generates a traditional, multi-page static HTML website. It includes a navigation sidebar, search index, and detailed class hierarchies. It feels like old-school library docs.

# jsdoc output
# Generates: out/index.html, out/global.html, out/MyClass.html
jsdoc myCode.js -d ./out

documentation is format-agnostic. It can generate HTML, but its superpower is generating Markdown (perfect for README.md) or JSON. This makes it easy to plug into modern static site generators like Gatsby or Next.js.

// documentation usage in a build script
const documentation = require('documentation');

// Generate Markdown
const md = await documentation.build(['src/*.js'], {
  format: 'md',
  shallow: true
});

apidoc generates a single-page application (SPA) style HTML site designed specifically for browsing API endpoints. It includes a built-in "Send Request" button to test APIs directly from the docs.

# apidoc output
# Generates: docs/index.html with interactive "Send" buttons
apidoc -i src/ -o docs/

swagger-jsdoc does not generate HTML. It only produces a swagger.json or yaml file. You must pair this with a separate viewer like Swagger UI or Redoc to actually see the documentation.

// swagger-jsdoc output
const swaggerJsdoc = require('swagger-jsdoc');
const spec = swaggerJsdoc(options);
// spec is a JSON object. Save it to file:
fs.writeFileSync('swagger.json', JSON.stringify(spec));
// Then load swagger.json into Swagger UI separately.

πŸ”Œ Ecosystem & Integration

How these tools fit into your wider architecture is a key decision factor.

jsdoc is the grandfather of the group. It works everywhere but feels heavy. It doesn't integrate well with modern bundlers without plugins. It is often seen in older Node.js libraries.

documentation is built for the modern web. It works as a CLI, a Node.js module, or a Gulp/Grunt plugin. Because it outputs JSON/Markdown, it fits easily into CI/CD pipelines that deploy to Netlify or Vercel.

apidoc is a standalone tool. It doesn't care about your build system; you run it, and it spits out HTML. This is simple but can be annoying if you want to customize the theme heavily or inject analytics.

swagger-jsdoc is part of the massive OpenAPI ecosystem. If your company uses microservices, API Gateways, or auto-generates client code (SDKs) for other teams, this is the only choice that fits. The JSON it produces is a standard contract.

πŸ› οΈ Real-World Scenarios

Scenario 1: Internal Library for Other Developers

You are building a utility library used by other frontend teams. They need to read docs quickly and see types.

  • βœ… Best choice: documentation
  • Why? You can generate a clean Markdown file to drop into your GitHub repo, or a sleek HTML site. The JSDoc syntax ensures their IDEs still give them autocomplete.
// Using documentation to update README.md automatically
const docs = await documentation.build(['lib/*.js'], { format: 'md' });
fs.writeFileSync('README.md', docs);

Scenario 2: Public REST API for External Partners

You are exposing a REST API to external customers. They need to test endpoints and see clear request/response examples.

  • βœ… Best choice: apidoc
  • Why? The generated site has built-in testing capabilities. Partners can try the API right in the browser without setting up Postman.
// apidoc example in controller
/**
 * @api {get} /user/:id Get User Info
 * @apiSuccess {String} name User's full name.
 */
app.get('/user/:id', getUser);

Scenario 3: Enterprise Microservices with Strict Governance

Your organization requires all APIs to follow the OpenAPI standard for security scanning and client generation.

  • βœ… Best choice: swagger-jsdoc
  • Why? It produces the standard swagger.json required by your API Gateway. You can then plug that JSON into Redoc for a beautiful read-only view.
// swagger-jsdoc definition
const options = {
  definition: {
    openapi: '3.0.0',
    info: { title: 'My API', version: '1.0.0' },
  },
  apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJsdoc(options);

Scenario 4: Legacy Node.js Module Maintenance

You are taking over an old Node.js project that already has thousands of JSDoc comments.

  • βœ… Best choice: jsdoc
  • Why? Rewriting all comments to fit apidoc or swagger syntax is too risky. Stick with the tool that already understands the existing comments.
# Running legacy jsdoc
jsdoc -c conf.json -r src/

⚠️ Critical Considerations

The "Double Work" Problem with apidoc

If you choose apidoc, remember that its @api tags are not standard. Your VS Code or WebStorm won't use them for type checking or autocomplete. You might end up writing standard JSDoc for your IDE and apidoc blocks for your docs. This doubles the maintenance burden.

The "Viewer" Requirement for swagger-jsdoc

swagger-jsdoc is not a documentation site generator; it is a definition generator. If you pick this, you must also plan how to host the viewer. Will you use swagger-ui-express in your Node app? Will you host Redoc on S3? This adds an extra step compared to apidoc or jsdoc, which give you HTML immediately.

Maintenance Status

jsdoc is stable but moves very slowly. New ES features sometimes take a long time to be fully supported in its parser. documentation is more active and handles modern JavaScript syntax (like flow types or newer ES6 features) more gracefully. Always check the current issue tracker if you are using cutting-edge syntax.

πŸ“Š Summary Table

Featurejsdocdocumentationapidocswagger-jsdoc
SyntaxStandard JSDocStandard JSDocCustom @apiJSDoc + Swagger YAML
Primary OutputStatic HTMLHTML, Markdown, JSONInteractive HTMLJSON / YAML (OpenAPI)
IDE Supportβœ… Excellentβœ… Excellent❌ None (Custom tags)⚠️ Partial
API Testing❌ No❌ Noβœ… Built-in❌ (Requires Swagger UI)
Best ForLegacy libs, general JSModern libs, READMEsStandalone REST APIsEnterprise, OpenAPI ecosystems

πŸ’‘ Final Recommendation

Think about who is reading the docs and what they need to do.

  • Building a library for other JS developers? Use documentation. It gives you flexible outputs and plays nice with IDEs.
  • Publishing a public REST API for quick consumption? Use apidoc. The built-in "try it out" feature is a huge win for developer experience.
  • Working in a regulated enterprise environment? Use swagger-jsdoc. The OpenAPI standard is non-negotiable for tooling integration.
  • Stuck on an old project? Stick with jsdoc until you have time to refactor.

Don't overcomplicate it. If you just need a README, documentation is the lightest, most modern path. If you need a full API portal, apidoc or the swagger combo is the way to go.

How to Choose: apidoc vs documentation vs jsdoc vs swagger-jsdoc

  • apidoc:

    Choose apidoc if you are building a standalone REST API and want a quick, self-contained documentation site without needing to integrate with a larger ecosystem. It is ideal for teams that prefer its specific, concise comment syntax over standard JSDoc and do not require OpenAPI compliance for tooling integration.

  • documentation:

    Choose documentation if you need a modern, fast, and flexible pipeline that supports JSDoc syntax but requires outputs beyond static HTML, such as Markdown for GitHub READMEs or JSON for custom processing. It is best for projects that value active maintenance, modular architecture, and integration into modern build tools like Vite or Rollup.

  • jsdoc:

    Choose jsdoc only if you are maintaining a legacy project that already relies on it or if you need strict compatibility with older TypeScript-JSDoc hybrid patterns that other tools might not fully support. For new projects, avoid it in favor of documentation due to jsdoc's slower development cycle and dated output styles.

  • swagger-jsdoc:

    Choose swagger-jsdoc if your organization requires OpenAPI (Swagger) compliance for API governance, client SDK generation, or integration with gateways like Kong or AWS API Gateway. It is the correct choice when you need to separate the definition generation (from code) from the visualization (handled by Swagger UI).

README for apidoc

apiDoc

apiDoc creates a documentation from API descriptions in your source code.

validate NPM version Join the chat at https://gitter.im/apidoc/talk

Documentation: apidocjs.com

Live DEMO

Installation

$ npm install -g apidoc

Usage

Add some apidoc comments anywhere in your source code:

/**
 * @api {get} /user/:id Request User information
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {Number} id User's unique ID.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */

Now generate the documentation from src/ into doc/.

$ apidoc -i src/ -o doc/

This repository contains and example folder from which you can generate a very complete documentation on an example api endpoint. It also contains best practice hints (in the footer.md file).

$ git clone https://github.com/apidoc/apidoc && cd apidoc
$ npm install --prod
$ ./bin/apidoc -i example -o /tmp/doc
$ $BROWSER /tmp/doc

Programmatic usage

You can generate the documentation programmatically:

import path from 'path'
import { createDoc } from 'apidoc'

const doc = createDoc({
  src: path.resolve(__dirname, 'src'),
  dest: path.resolve(__dirname, 'doc'), // can be omitted if dryRun is true
  // if you don't want to generate the output files:
  dryRun: true,
  // if you don't want to see any log output:
  silent: true,
})

if (typeof doc !== 'boolean') {
  // Documentation was generated!
  console.log(doc.data) // the parsed api documentation object
  console.log(doc.project) // the project information
}

Install type definitions (see @types/apidoc):

$ npm install -D @types/apidoc

Docker image

You can use apidoc in Docker like this:

# first build the image after cloning this repository
docker build -t apidoc/apidoc .
# run it
docker run --rm -v $(pwd):/home/node/apidoc apidoc/apidoc -o outputdir -i inputdir

Supported programming languages

  • C#, Go, Dart, Java, JavaScript, PHP, Scala (all DocStyle capable languages):

    /**
      * This is a comment.
      */
    
  • Clojure:

    ;;;;
    ;; This is a comment.
    ;;;;
    
  • CoffeeScript:

    ###
    This is a comment.
    ###
    
  • Elixir:

    #{
    # This is a comment.
    #}
    
  • Erlang:

    %{
    % This is a comment.
    %}
    
  • Perl

    #**
    # This is a comment.
    #*
    
    =pod
    This is a comment.
    =cut
    
  • Python

    """
    This is a comment.
    """
    
  • Ruby

    =begin
    This is a comment.
    =end
    

Plugins (extend apiDoc)

apiDoc will auto include installed plugins.

  • apidoc-plugin-schema Generates and inject apidoc elements from api schemas. npm install apidoc-plugin-schema

For details and an example on how to implement your own plugin, please view apidoc-plugin-test.

Support

Please create a new issue if you have a suggestion/question or if you found a problem/bug.

Contributing

apiDoc is a collaborative project. Pull requests are welcome. Please see the CONTRIBUTING file.

Build tools

Integration

Converter