apidoc and swagger-jsdoc are both tools designed to generate API documentation directly from source code comments, reducing the need for separate documentation files. apidoc uses a custom set of tags to produce static HTML pages, focusing on simplicity and human readability. swagger-jsdoc adheres to the OpenAPI Specification (formerly Swagger), generating a JSON or YAML definition file that can be rendered by compatible UI tools. While both aim to keep docs in sync with code, they serve different ends of the API lifecycle — one prioritizes quick static views, and the other enables machine-readable contracts for client generation and testing.
Both apidoc and swagger-jsdoc solve the same core problem — keeping API documentation close to the implementation code — but they diverge sharply in standards, output, and ecosystem support. For frontend architects, the choice often depends on whether you need human-readable pages or a machine-readable contract for tooling. Let's compare how they handle common engineering requirements.
apidoc uses its own custom comment syntax.
@api, @apiName, and @apiParam.// apidoc: Custom tags
/**
* @api {get} /user/:id Get User
* @apiName GetUser
* @apiGroup User
* @apiParam {Number} id User's unique ID.
*/
swagger-jsdoc uses the OpenAPI Specification (via JSDoc).
@swagger blocks.// swagger-jsdoc: OpenAPI tags
/**
* @swagger
* /users/{id}:
* get:
* summary: Get User
* parameters:
* - in: path
* name: id
* schema:
* type: integer
*/
apidoc generates a complete static website.
doc/ folder with HTML, CSS, and JS.# apidoc: Generate static site
apidoc -i src/ -o doc/
# Result: ./doc/index.html is ready to serve
swagger-jsdoc generates a JSON or YAML specification file.
swagger-ui-express) to render.// swagger-jsdoc: Generate spec object
const swaggerSpec = swaggerJsdoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Result: JSON spec served at /api-docs/swagger.json
apidoc is typically a build-time tool.
// apidoc: package.json script
{
"scripts": {
"build:docs": "apidoc -i src/ -o public/docs/"
}
}
swagger-jsdoc often runs at runtime or build time.
// swagger-jsdoc: Express middleware setup
const swaggerUi = require('swagger-ui-express');
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Docs served directly by the Node.js application
apidoc is primarily for human reading.
// apidoc: Manual type definition needed
// No automatic generation from apidoc comments
interface User {
id: number;
name: string;
}
swagger-jsdoc enables automatic client generation.
openapi-typescript can create types from the JSON spec.# swagger-jsdoc: Generate types from spec
npx openapi-typescript http://localhost:3000/api-docs/swagger.json -o src/types/api.ts
# Result: TypeScript interfaces generated automatically
While the standards differ, both tools share core philosophies and capabilities. Here are key overlaps:
// Both: Documentation lives in comments
/**
* Documentation here...
*/
function getUser() { /*...*/ }
// Both: Can be used with any Node.js server
// No framework lock-in for the documentation generator itself
// apidoc: template customization
// swagger-jsdoc: custom CSS in Swagger UI options
// Both: CLI tools return error codes on failure
// Useful for CI/CD pipelines
// Both: Widely used in production environments
// Community support available via GitHub issues
| Feature | Shared by apidoc and swagger-jsdoc |
|---|---|
| Source | 💬 Code comments |
| Compatibility | 🚀 Framework agnostic |
| Customization | 🧩 Theming and templates |
| Validation | ✅ Syntax checking |
| Ecosystem | 👥 Mature communities |
| Feature | apidoc | swagger-jsdoc |
|---|---|---|
| Standard | 📜 Custom tags | 🌐 OpenAPI Specification |
| Output | 📄 Static HTML | 📋 JSON/YAML Spec |
| Viewer | 🖥️ Built-in | 🔌 Requires separate UI |
| Client Gen | ❌ Not supported | ✅ Supported (via OpenAPI tools) |
| Workflow | ⚙️ Build step | 🔄 Build or Runtime |
| Frontend Value | 📖 Human reading | 🤖 Machine-readable contract |
apidoc is like a quick sketch pad 📝 — great for getting human-readable docs up fast with minimal setup. Ideal for internal tools, microservices without public contracts, or teams that do not need automated client generation.
swagger-jsdoc is like a formal blueprint 🏗️ — perfect for teams that treat API specs as contracts. Shines in environments where frontend types, contract testing, and API gateways rely on the OpenAPI standard.
Final Thought: If your frontend team needs to generate TypeScript types or validate API responses automatically, swagger-jsdoc is the clear choice. If you just need a simple page for humans to read without extra tooling, apidoc gets the job done with less configuration.
Choose swagger-jsdoc if your team relies on the OpenAPI ecosystem for tooling, such as automatic TypeScript client generation, contract testing, or integration with API gateways. It is the better fit for production-grade services where machine-readable specs are required for frontend consumption, CI/CD validation, or third-party developer portals.
Choose apidoc if you need a lightweight, zero-config solution for generating static HTML documentation quickly without worrying about the OpenAPI standard. It is ideal for internal tools, prototypes, or projects where human readability is the only goal and there is no need for automated client SDK generation or strict contract validation.
This library reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.
Imagine having API files like these:
/**
* @openapi
* /:
* get:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a mysterious string.
*/
app.get('/', (req, res) => {
res.send('Hello World!');
});
The library will take the contents of @openapi (or @swagger) with the following configuration:
const swaggerJsdoc = require('swagger-jsdoc');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Hello World',
version: '1.0.0',
},
},
apis: ['./src/routes*.js'], // files containing annotations as above
};
const openapiSpecification = swaggerJsdoc(options);
The resulting openapiSpecification will be a swagger tools-compatible (and validated) specification.

You are viewing swagger-jsdoc v6 which is published in CommonJS module system.
npm install swagger-jsdoc --save
Or
yarn add swagger-jsdoc
By default swagger-jsdoc tries to parse all docs to it's best capabilities. If you'd like to you can instruct an Error to be thrown instead if validation failed by setting the options flag failOnErrors to true. This is for instance useful if you want to verify that your swagger docs validate using a unit test.
const swaggerJsdoc = require('swagger-jsdoc');
const options = {
failOnErrors: true, // Whether or not to throw when parsing errors. Defaults to false.
definition: {
openapi: '3.0.0',
info: {
title: 'Hello World',
version: '1.0.0',
},
},
apis: ['./src/routes*.js'],
};
const openapiSpecification = swaggerJsdoc(options);
Click on the version you are using for further details: