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

api-doc-ks

v0.0.4

Published

Framework-agnostic API documentation UI with password protection

Readme

api-document

Framework-agnostic API documentation UI with optional password protection.

  • Works with Express, Fastify, Koa, Hono, or plain Node.js middleware style
  • Reads endpoint schema from JSON files in your app
  • Optional auth: if secret is not set, password page is bypassed

Install

npm i api-doc-ks

or

bun add api-doc-ks

Quick Start (Express)

import express from 'express';
import path from 'path';
import { createApiDoc } from 'api-doc-ks';

const app = express();

const apiDoc = createApiDoc({
  secret: process.env.API_DOCUMENT_SECRET,
  title: 'My App API',
  version: '1.0.0',
  schemaDir: path.resolve('./src/api-document'),
  basePath: '/api-doc',
});

app.use(express.urlencoded({ extended: false }));
app.use(express.json());

app.use(apiDoc);

app.listen(3000, () => {
  console.log('http://localhost:3000/api-doc');
});

API

initApiDocument(options)

createApiDoc(options)

Create middleware handler and initialize config in one step.

interface ApiDocumentConfig {
  secret?: string;
  title?: string;
  version?: string;
  schemaDir?: string;
  loadSchema?: () => Promise<{ endpoints?: unknown[]; errors?: Array<{ schemaPath: string; message: string }> }>;
  basePath?: string;
}

Options:

  • secret optional password
  • title document title shown in UI
  • version document version shown in UI
  • schemaDir path to schema directory in your app
    • default: src/api-document
  • loadSchema custom loader function (if provided, schemaDir is ignored)
  • basePath default mount path
    • default: /api-document
createApiDoc(options?: ApiDocumentConfig): Handler;

Auth Behavior

  • If secret is set:
    • GET /<basePath> requires login
    • GET /<basePath>/data returns 401 when not authenticated
  • If secret is not set or empty:
    • auth is disabled
    • password page is not shown
    • all api-doc routes are directly accessible

Routes

For basePath = /api-doc:

  • GET /api-doc UI page
  • POST /api-doc/login login endpoint
  • POST /api-doc/logout logout endpoint
  • GET /api-doc/script.js frontend script
  • GET /api-doc/data schema JSON payload

Schema Directory

By default, library scans this directory in your app:

src/api-document

It reads all .json files recursively.

Example structure:

src/api-document
├── auth
│   └── login.json
└── users
    ├── get-users.json
    └── create-user.json

Schema JSON Example

{
  "name": "Get Users",
  "method": "GET",
  "path": "/api/users",
  "description": "Get user list",
  "request": {
    "headers": { "Authorization": "Bearer <token>" },
    "query": { "page": 1, "limit": 20 }
  },
  "response": {
    "status": "200",
    "data": [{ "id": "usr_01", "name": "John Doe" }]
  },
  "responseError": [
    { "code": "401", "message": "Unauthorized" }
  ]
}

TypeScript

Types are included in the package.

import { createApiDoc } from 'api-doc-ks';
import type { SchemaLoaderOptions, ApiDocumentData } from 'api-document/schema';

Backward Compatibility

  • createApiDocumentHandler is still exported as an alias of createApiDoc.

Notes

  • createApiDoc(...) returns a handler with its own captured config.
  • Ensure your app can read the schema directory path you configure.