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

docbagel

v1.0.0

Published

CLI that chunks local docs with LangChain and drafts OpenAPI specs via Gemini.

Readme

Docbagel

Docbagel is a CLI tool to generate JSDoc for you API routes, enabling easy to use & interactive SwaggerUI with OpenAPI specs.

PS: I initially intended it to work with Express & Node. Extending it to work with other frameworks is possible.

Prerequisites

  • Node.js 20 or newer

Installation

npm install -g docbagel

Provide your Gemini API key through GEMINI_API_KEY (or pass --set-api-key when invoking the CLI)

docbagel --set-api-key "your-gemini-api-key"
# or
npx docbagel --set-api-key "your-gemini-api-key"

Automatically setup config file for your tool, config available at user/<username>/.docbagel/config.

Project setup

  • Project Structure
/src
  index.js
  /controllers
    /user.controller(.js/.ts) # Where core business logic exists with API response structures and error handling
  /routers
    /user.router(.js/.ts) # Where routes are defined with route params, HTTP methods and middlewares.
  • SwaggerUI setup
npm i swagger-jsdoc swagger-ui-express
  • Config file swagger.js
import swaggerJSDoc from "swagger-jsdoc";
import { config } from "dotenv";
config();

const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
const port = process.env.PORT || 3000;
const host = process.env.API_BASE_URL || `${protocol}://localhost:${port}`;

const definition = {
  openapi: "3.0.0",
  info: {
    title: "Video Backend API",
    version: "1.0.0",
    description: "API documentation for Video backend",
  },
  servers: [
    {
      url: host,
      description:
        process.env.NODE_ENV === "production"
          ? "Production server"
          : "Local server",
    },
  ],
};

const options = {
  definition,
  apis: ["./src/routes/*.js", "./src/controllers/*.js", "./src/models/*.js"],
};

export const swaggerSpec = swaggerJSDoc(options);
  • Configure app.js
import express from "express";
import { swaggerSpec } from "./utils/swagger.js";
import swaggerUi from "swagger-ui-express";

const app = express();

app.get("/api-docs.json", (req, res) => {
  const baseUrl =
    process.env.API_BASE_URL || `${req.protocol}://${req.get("host")}`;
  const spec = { ...swaggerSpec, servers: [{ url: baseUrl }] };
  res.setHeader("Content-Type", "application/json");
  res.send(spec);
});

app.use(
  "/api-docs",
  swaggerUi.serve,
  swaggerUi.setup(undefined, {
    swaggerOptions: { url: "/api-docs.json" },
  })
);
app.listen(3000, () => {
  console.log(`App running a port 3000`);
});

Usage

Generate an OpenAPI spec from one or more local documents (supply multiple paths after -u) & output into a file where your routes are defined (using the flag -o):

_ Make sure the files already exist otherwise it will start creating new files with the content _

cd src
npx docbagel -u index.js controllers/user.controller.js -o routers/user.route.js

You can fine-tune the run with flags:

  • -i, --instructions – add high-level requirements for the spec output
  • -m, --model – override the Gemini model (default: gemini-1.5-pro-latest)
  • --chunk-size / --chunk-overlap – control text splitting before calling Gemini
  • -k, --api-key – supply the API key explicitly instead of the environment variable

You may need to make to make some minor fixes manually for missing brackets or comments

Make sure to add JSDoc for each respective route seprately above the code where the route is defined

Example

/**
 * @openapi
 * /api/v1/user/{id}:
 *   get:
 *     summary: Get User by ID
 *     tags: [User]
 *     responses:
 *       200:
 *         description: Return an User object using ID
 */
router.get("/user/[:id]", getUserById);
/**
 * @openapi
 * /api/v1/user/{name}:
 *   get:
 *     summary: Get User by name
 *     tags: [User]
 *     responses:
 *       200:
 *         description: Return an User object using name
 */
router.get("/user/[:name]", getUserByName);