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

create-mock-service

v3.1.0

Published

CLI tool to generate mock API service projects with OpenAPI/Swagger UI support

Downloads

487

Readme

create-mock-service

CLI to scaffold a fully-typed mock API service with Postman-style request matching, Zod validation, auto OpenAPI, and typed frontend client generation.

Quick Start

npx create-mock-service my-api
cd my-api
bun install
bun run dev

Open http://localhost:8787/docs — Swagger UI with interactive docs.

What You Get

my-api/
  mock.config.ts          ← Server config (base path, security, groups, OpenAPI metadata)
  routes.config.ts        ← Declarative endpoint manifest
  src/
    contracts.ts          ← Shared Zod schemas (ErrorRes, MessageRes)
    types.ts              ← TypeScript type definitions
    data/                 ← Handler files (one per method)
      hello/
        GET.ts
        POST.ts
        {name}/
          GET.ts
    lib/                  ← Core engine (router, matcher, store)
    scripts/              ← Build, scaffold, dump, client generation
    generated/            ← Auto-generated routes + OpenAPI spec + FE client
  .docs/                  ← Full documentation + tutorials

Features

| Feature | Description | |---|---| | File-based routing | src/data/users/GET.tsGET /api/users | | Postman-style matching | Declare examples, server auto-picks the best match by body, headers, or query params | | Zod validation | Request body validation with auto-400, typed responses | | Auto OpenAPI 3.0.3 | Zod schemas → accurate OpenAPI spec (enum, format, required) | | Swagger UI | Interactive docs at /docs with try-it-out | | Typed client gen | bun run generate:client → fully typed fetch functions for your frontend | | Shared contracts | Define ErrorRes once, reuse across all handlers | | Scaffold + dump | Sync config ↔ filesystem, or regenerate config from files | | Security | Bearer, API Key, OAuth2 — per-route or global | | Hot reload | Dev server watches files and rebuilds OpenAPI |

Example Handler

// src/data/hello/POST.ts
import { z } from 'zod';
import { ErrorRes } from '../../contracts.js';
import type { MockExample } from '../../types.js';

const Req = z.object({
  name: z.string().min(1),
  message: z.string().min(1),
});

const HelloCreated = z.object({
  id: z.string(),
  message: z.string(),
});

export const schema = {
  request: Req,
  responses: {
    201: HelloCreated,
    400: ErrorRes,
  },
};

export const examples = [
  {
    name: 'Create success',
    match: {
      body: Req.parse({ name: 'Alice', message: 'Hello' }),
    },
    response: {
      status: 201,
      body: HelloCreated.parse({ id: 'abc', message: 'Hello' }),
    },
  },
  {
    name: 'Missing name',
    match: {
      body: { message: 'Hello' },
    },
    response: {
      status: 400,
      body: ErrorRes.parse({ error: 'Name is required' }),
    },
  },
] satisfies MockExample[];

export default {
  status: 201,
  body: { id: 'abc', message: 'Hello created!' },
};

How matching works

POST /api/hello  { name: "Alice", message: "Hello" }
  → auto-matches "Create success" example → returns 201

POST /api/hello  { message: "Hello" }
  → auto-matches "Missing name" example → returns 400

POST /api/hello  {}
  → no example matches → returns the default export

Control matching explicitly with headers:

curl -H "X-Mock-Response-Name: Missing name" \
     -d '{"message":"Hello"}' \
     http://localhost:8787/api/hello

See .docs/tutorial/05-matching.md for the full matching algorithm.

Matching & Override Headers

| Header | Purpose | |---|---| | X-Mock-Response-Name | Select example by name | | X-Mock-Response-Code | Filter examples by status code | | X-Mock-Match-Request-Body | Require exact body match (true) | | X-Mock-Match-Request-Headers | Comma-separated header keys to match | | X-Mock-Scenario | Legacy scenario selection | | X-Mock-Delay | Artificial response delay (ms) |

Project Scripts

| Command | Description | |---|---| | bun run dev | Dev server + hot reload + auto OpenAPI rebuild | | bun run build | Build routes + lint | | bun run build:routes | Regenerate route manifest & OpenAPI spec | | bun run scaffold | Sync routes.config.ts → filesystem | | bun run dump:routes | Scan files → update routes.config.ts | | bun run create:endpoint | Interactive new handler generator | | bun run generate:client | Generate typed FE client from Zod schemas | | bun run lint | TypeScript type check |

Requirements

  • Node.js 18+
  • Bun (recommended) or npm

Documentation

After generating a project, see:

  • .docs/tutorial/ — Step-by-step hands-on guides (English)
  • README.md (in generated project) — Project overview

License

MIT