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 🙏

© 2025 – Pkg Stats / Ryan Hefner

swagme

v1.1.2

Published

Node Js CLI tool that auto generates swagger api documentation for express and nextjs web servers. Takes advantage of the MVC Pattern

Readme

Swagme

Static Badge Static Badge Static Badge Static Badge Static Badge

About

Node Js CLI tool that auto generates swagger api documentation for express web and nextjs servers. Takes advantage of the MVC Pattern. Supports Mongoose, Prisma, and Drizzle database schemas.


Quick Start

This will interactively create swag.config.json, swagger.json and swagger.yml based on your project.

npx swagme

For Usage Instructions

npx swagme --help

Installation

npm install -g swagme

Prerequisites

Required Dependencies

Your project must have Express installed:

npm install express

Recommended Dependencies

For displaying Swagger documentation:

npm install swagger-ui-express yaml

Database Support (Optional)

Swagme can auto-generate schemas from your database models:

  • Mongoose: npm install mongoose
  • Prisma: npm install @prisma/client
  • Drizzle: npm install drizzle-orm

CLI Commands

Default Command

Run the full interactive setup (configure + build):

swagme

This will:

  • Create a swag.config.json configuration file
  • Scan your Express routes and database schemas
  • Generate swagger.json and swagger.yml files
  • Create a docs folder with route and schema definitions

npx swagme run

Run the full workflow with options for customization.

Usage:

npx swagme run [directory] [options]

Arguments:

  • [directory] - Working directory of the project (default: current directory)

Options:

  • -y, --auto - Auto configure and build without prompts
  • -c, --config - Only configure (create config file)
  • -b, --build - Only build swagger files
  • -r, --routes - Update routes (default: true)
  • -s, --schemas - Update schemas (default: true)
  • --scan - Scan project files for routes and schemas
  • --json - Build only swagger.json file
  • --yaml - Build only swagger.yml file

Examples:

# Interactive setup in current directory
npx swagme run

# Auto-configure without prompts
npx swagme run -y

# Build only, skip configuration
npx swagme run -b

# Scan project and build both JSON and YAML
npx swagme run --scan --json --yaml

# Build only JSON file
npx swagme run -b --json

# Build only YAML file
npx swagme run -b --yaml

# Run in specific directory
npx swagme run /path/to/project -y

npx swagme config

Generate only the configuration file without building documentation.

Usage:

npx swagme config [options]

Options:

  • -y, --auto - Auto configure without prompts
  • -p, --dir - Project directory/folder (default: current directory)

Examples:

# Interactive configuration
npx swagme config

# Auto-configure without prompts
npx swagme config -y

# Configure specific directory
npx swagme config -p /path/to/project

npx swagme build

Build swagger documentation files from existing configuration.

Usage:

npx swagme build [options]

Options:

  • -p, --dir - Project directory/folder (default: current directory)
  • --json - Build only swagger.json file
  • --yaml - Build only swagger.yml file
  • -r, --routes - Update routes (default: true)
  • -s, --schemas - Update schemas (default: true)
  • --scan - Scan project files for routes and schemas

Examples:

# Build with existing config
npx swagme build

# Build and scan project files
npx swagme build --scan

# Build only JSON
npx swagme build --json

# Build only YAML
npx swagme build --yaml

# Build without updating routes
npx swagme build --no-routes

# Build without updating schemas
npx swagme build --no-schemas

npx swagme del

Remove all swagme configuration files and folders.

Usage:

npx swagme del [options]

Options:

  • -p, --dir - Project directory/folder (default: current directory)
  • -y, --auto - Auto delete all swagme files and folders without confirmation prompt (default: false)

Examples:

# Delete swagme files from current directory (with confirmation prompt)
npx swagme del

# Auto-delete without confirmation prompt
npx swagme del -y

# Delete from specific directory
npx swagme del -p /path/to/project

# Auto-delete from specific directory without prompt
npx swagme del -p /path/to/project -y

Configuration File

The swag.config.json file stores your project settings:

{
  "name": "My API",
  "version": "1.0.0",
  "description": "API Documentation",
  "routes": "src/routes",
  "schema": "src/models",
  "docs": "docs",
  "main": "src/app.js",
  "database": "mongoose",
  "authorization": "bearer",
  "gitignore": true
}

Configuration Options:

  • name - API name
  • version - API version
  • description - API description
  • routes - Path to routes folder
  • schema - Path to database models/schemas folder
  • docs - Output folder for generated documentation
  • main - Main Express application file
  • database - Database type (mongoose, prisma, or drizzle)
  • authorization - Authorization type (e.g., bearer)
  • gitignore - Whether to add docs folder to .gitignore

Swagger UI Setup

Express.js Setup

const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');
const SwaggerUI = require('swagger-ui-express');
const YAML = require('yaml');

// Load swagger documentation
const swaggerdocs = YAML.parse(
  fs.readFileSync(path.join(__dirname, 'swagger.yml'), 'utf-8')
);
// Or use JSON: const swaggerdocs = require('./swagger.json');

// Swagger documentation endpoint
app.use('/api/docs', SwaggerUI.serve, SwaggerUI.setup(swaggerdocs));

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
  console.log('Swagger docs at http://localhost:3000/api/docs');
});

Workflow Examples

First Time Setup

# 1. Install swagme globally
npm install -g swagme

# 2. Navigate to your Express project
cd my-express-project

# 3. Run interactive setup
npx swagme

# 4. Follow the prompts to configure your project

Daily Development Workflow

# After making changes to routes or schemas, rebuild documentation
npx swagme build --scan

CI/CD Integration

# Auto-build documentation without prompts
npx swagme run -y --scan

Features

Auto-detect Express routes - Scans your route files automatically
Database schema support - Works with Mongoose, Prisma, and Drizzle
Multiple output formats - Generate JSON and/or YAML
Interactive CLI - User-friendly prompts for configuration
Auto mode - Skip prompts for CI/CD pipelines
Gitignore integration - Optionally add docs to .gitignore
Authorization support - Configure API authorization schemes


Troubleshooting

Express dependency not found

npm install express

Swagger UI Express not found

npm install swagger-ui-express

Support

Support (from Malawi or USA)

License

MIT License - See LICENSE file for details

Links