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.
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.
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
*/
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.
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.
You are building a utility library used by other frontend teams. They need to read docs quickly and see types.
documentation// Using documentation to update README.md automatically
const docs = await documentation.build(['lib/*.js'], { format: 'md' });
fs.writeFileSync('README.md', docs);
You are exposing a REST API to external customers. They need to test endpoints and see clear request/response examples.
apidoc// apidoc example in controller
/**
* @api {get} /user/:id Get User Info
* @apiSuccess {String} name User's full name.
*/
app.get('/user/:id', getUser);
Your organization requires all APIs to follow the OpenAPI standard for security scanning and client generation.
swagger-jsdocswagger.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);
You are taking over an old Node.js project that already has thousands of JSDoc comments.
jsdocapidoc 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/
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.
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.
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.
| Feature | jsdoc | documentation | apidoc | swagger-jsdoc |
|---|---|---|---|---|
| Syntax | Standard JSDoc | Standard JSDoc | Custom @api | JSDoc + Swagger YAML |
| Primary Output | Static HTML | HTML, Markdown, JSON | Interactive HTML | JSON / YAML (OpenAPI) |
| IDE Support | β Excellent | β Excellent | β None (Custom tags) | β οΈ Partial |
| API Testing | β No | β No | β Built-in | β (Requires Swagger UI) |
| Best For | Legacy libs, general JS | Modern libs, READMEs | Standalone REST APIs | Enterprise, OpenAPI ecosystems |
Think about who is reading the docs and what they need to do.
documentation. It gives you flexible outputs and plays nice with IDEs.apidoc. The built-in "try it out" feature is a huge win for developer experience.swagger-jsdoc. The OpenAPI standard is non-negotiable for tooling integration.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.
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.
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.
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.
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).
apiDoc creates a documentation from API descriptions in your source code.
$ npm install -g apidoc
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
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
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
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
apiDoc will auto include installed plugins.
npm install apidoc-plugin-schemaFor details and an example on how to implement your own plugin, please view apidoc-plugin-test.
Please create a new issue if you have a suggestion/question or if you found a problem/bug.
apiDoc is a collaborative project. Pull requests are welcome. Please see the CONTRIBUTING file.
pip install flask-apidocnpm install grunt-apidoc.npm install gapidoc.npm install --save-dev webpack-apidoc.