Registry / devops / jsdoc-rest-api

jsdoc-rest-api

JSON →
library3.6.3jsnpmunverified

jsdoc-rest-api v3.6.3 generates a map of REST API endpoints from JSDoc annotations and automatically attaches them to an Express.js app. It reads source files with custom tags like @apiType, @apiPath, @apiBody, @apiKey, and @apiDescription, producing route registrations so developers never need to write app.get(), app.post(), etc. The package exports two functions: generateRoutes() returns the route map, and attachExpressAppEndpoints() binds them to an Express instance. It is a niche automation tool for Node.js/Express projects using JSDoc comments; updates are infrequent (last release 2020).

npm install jsdoc-rest-api
INSTALL
IMPORT
SIG · JSDOC-REST-API
J
jsdoc-rest-api
devopsjavascriptv3.6.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsdocRestApi
import jsdocRestApi from 'jsdoc-rest-api'
jsdocRestApi = require('jsdoc-rest-api')
ESM default import; the package does not ship TypeScript types. CommonJS require also works.
generateRoutes
const { generateRoutes } = require('jsdoc-rest-api')
const generateRoutes = require('jsdoc-rest-api/generateRoutes')
Named export available via destructuring; do not use subpath imports.
attachExpressAppEndpoints
const { attachExpressAppEndpoints } = require('jsdoc-rest-api')
import { attachExpressAppEndpoints } from 'jsdoc-rest-api'
Both named and default import of the object containing both functions work. TypeScript users should use require or skip type checking.

Initializes Express, attaches endpoints from JSDoc-annotated controller files, and starts the server.

const express = require('express'); const { attachExpressAppEndpoints } = require('jsdoc-rest-api'); const app = express(); app.use(express.json()); attachExpressAppEndpoints({ app: app, source: 'api/controllers/**/*Controller.js' }); app.all('*', (req, res) => { res.status(404).send('Not found'); }); const PORT = process.env.PORT || 3100; app.listen(PORT, () => { console.log(`REST API server running on port ${PORT}`); });
Debug
Known issues
gotchaThe @apiBody annotation expects a JSON object description string, not actual JSON; incorrect parsing can cause route handlers to fail.
fix
Write @apiBody as a JSON-like string, e.g., @apiBody {"title": "String"}. Validate that the library parses it correctly.
affects: >=3.0.0
gotchaThe @apiPath must start with a forward slash and can include Express-style route parameters (`:id`); otherwise routes may not match.
fix
Ensure @apiPath is like /api/resource/:id, not api/resource/:id or /api/resource/{id}.
affects: >=2.0.0
deprecatedThe generateRoutes() method is considered lower-level; attachExpressAppEndpoints() is the recommended entry point.
fix
Use attachExpressAppEndpoints() instead of manually calling generateRoutes() and wiring routes.
affects: >=3.0.0
gotchaAll controller files must be CommonJS modules exporting a class or function; ES module exports are not supported.
fix
Use module.exports = MyController in your controller files.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'app' of undefined
Passing an object without the 'app' key to attachExpressAppEndpoints.
fix
Ensure the argument is `{ app: expressApp, source: 'path' }`.
Error: No source files found matching glob pattern
The glob pattern provided does not match any existing files.
fix
Verify the source path relative to the project root, e.g., 'api/controllers/**/*Controller.js'.
SyntaxError: Unexpected token u in JSON at position 0
Invalid or missing @apiBody annotation causing JSON parsing failure.
fix
Check that @apiBody contains valid JSON-like string, e.g., @apiBody {"field": "String"}.
Upgrade
Version history
3.6.3latest on npm
Audit
Dependencies
expressrequiredThe library attaches endpoints to an Express app instance
globrequiredUsed internally to find source files matching the provided pattern
Agent activity
8 hits · last 30 days
node
8
Resources
jsdoc-rest-api — npm install jsdoc-rest-api · libregistry