npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-route-by-jsdoc

v0.2.1

Published

Generate Express routes and OpenAPI docs from JSDoc annotations

Readme

express-route-by-jsdoc

Generate Express routes and OpenAPI documentation directly from JSDoc comment blocks.

Installation

npm install express-route-by-jsdoc

Quick start

const express = require("express");
const routeGenerator = require("express-route-by-jsdoc");

const app = express();
app.use(express.json());

const options = {
  docs: {
    url: "/docs",
    json: "/docs.json",
  },
  swaggerDefinition: {
    info: {
      title: "Example API",
      version: "1.0.0",
      description: "Demo application for express-route-by-jsdoc",
    },
    host: "localhost:3100",
    basePath: "/api/v1",
    schemes: ["http"],
  },
  basedir: __dirname,
  files: ["./routes/*.js"],
};

routeGenerator(app, options);

const port = process.env.PORT || 3100;
app.listen(port, () => {
  console.log(`API ready at http://localhost:${port}`);
  console.log(`Swagger UI at http://localhost:${port}${options.docs.url}`);
});

See examples/basic-server for a runnable sample.

Options

| Option | Type | Description | | ------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | docs | { url: string, json?: string, ui?: object } | Optional Swagger UI mounting point. When provided, the UI is served at url and a JSON spec is exposed at json (defaults to {url}.json). | | swaggerDefinition | object | Base OpenAPI/Swagger definition. Supports legacy host, basePath, and schemes keys or modern openapi + servers. | | basedir | string | Absolute directory used to resolve the glob patterns. | | files | string[] | Glob patterns pointing at the controller files that contain JSDoc annotations. | | api.postprocess | (req, res, next) => void | Optional Express middleware appended after each generated route. Defaults to a wrapper that responds with { response, data }. |

Documenting routes

Annotate each handler with a JSDoc block. The generator looks for the tags below:

/**
 * Retrieve user information based on the supplied user id.
 * @route GET /users/{userid}
 * @group User - Operations about user data
 * @param {string} userid.path.required - user identifier - eg: wisit
 * @returns {object} 200 - Successful response with user payload
 * @returns {Error} default - Unexpected error
 */
module.exports = function getUser(req, res, next) {
  // populate `res.body` with the payload you want to return
  res.body = { id: req.params.userid };
  next();
};

Supported annotations

  • @route <METHOD> <path> defines the HTTP verb and relative path. Path parameters wrapped in {} are converted to Express parameters automatically.
  • @group <Name> - <description> controls the OpenAPI tag used for the operation.
  • @param {Type} name.location[.required] - description produces path/query/header parameters or a JSON request body (when location is body).
  • @returns {Type} status - description creates OpenAPI responses. Use default for non-specific status codes.

Response shape

When you do not supply a custom postprocess middleware, the generator replies with:

{
  "response": {
    "result": "true",
    "remark": "success",
    "code": 200
  },
  "data": {
    "...": "your handler payload"
  }
}

Override options.api.postprocess if you prefer a different envelope.

Upgrading from 0.0.4

  • Replaced the deprecated express-swagger-generator dependency with swagger-ui-express and a custom OpenAPI generator.
  • Swapped out doctrine-file for the actively maintained comment-parser library.
  • Added Jest + Supertest coverage, ESLint (flat config), and revamped examples.
  • Express 5 is now the default runtime. Ensure your project runs on Node.js 18 or newer.

Contributing

  1. Clone the repository and run npm install.
  2. Use npm test to execute the Jest suite.
  3. Run npm run lint before submitting a pull request.

Issues and pull requests are welcome!