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

mockaton

v13.11.2

Published

HTTP Mock Server

Readme

NPM Version Test codecov

Docs ↗ | Changelog ↗ | Skills

Mockaton is an HTTP mock server for simulating APIs. With it, you can test API errors, edge cases, and difficult to reproduce states in general.

Demo (Docker)

This will spin up Mockaton with the sample directory included in this repo mounted on the container.

git clone https://github.com/ericfortis/mockaton.git --depth 1
cd mockaton
make docker

Test it:

curl localhost:2020/api/user

Installation (more options ↗)

Mockaton has no dependencies.

npm install -g mockaton

Basic Usage

mockaton --port 2020 my-mocks-dir/

Mockaton will serve the files on the given directory. It's a file-system based router, so filenames can have dynamic parameters. Also, filenames can have comments, which are anything within parentheses, this way each route can have different mock file variants. Similarly, each route can have different response status code variants.

| Route | Filename | Description | | -----| -----| ---| | /api/company/123 | api/company/[id].GET.200.ts | [id] is a dynamic parameter. .ts, and .js are sent as JSON by default | | /media/avatar.png | media/avatar.png | Statics assets don't need the above extension | | /api/login | api/login(invalid attempt).POST.401.ts | Anything within parenthesis is a comment, they are ignored when routing | | /api/login | api/login(default).GET.200.ts | (default) is a special comment; otherwise, the first mock variant in alphabetical order wins | | /api/login | api/login(locked out user).POST.423.json | .json is allowed too |

Docs

How to scrape your backend APIs?

Mockaton has a Browser Extension that lets you download in bulk all your API responses following Mockaton's filename convention.

Skills

npx skills add ericfortis/mockaton

How to create mocks?

Write it to your mocks directory. .ts files are served as JSON by default.

mkdir -p my-mocks-dir/api
echo "export default { name: 'John' }" > my-mocks-dir/api/user.GET.200.ts

Example A: JSON

For JSON responses, use TypeScript (or JS), and export default an Object, Array, or String.

  • Route: /api/company/123
  • Filename: api/company/[id].GET.200.ts
interface Company {
  name: string
}

export default {
  name: 'Acme, Inc.'
} satisfies Company

Example B: Non-JSON

  • Route: /api/company/123
  • Filename: api/company/[id].GET.200.xml
<company>
 <name>Acme, Inc.</name>
</company>

Example C: Function Mocks

With a function mock you can do pretty much anything you could do with a normal backend handler. For example, you can handle complex logic, URL parsing, saving to a database, etc.

  • Route: /api/company/abc/user/999
  • Filename: api/company/[companyId]/user/[userId].GET.200.ts
import { IncomingMessage, OutgoingMessage } from 'node:http'
import { parseSegments } from 'mockaton'

export default async function (req: IncomingMessage, response: OutgoingMessage) {
  const { companyId, userId } = parseSegments(req.url, import.meta.filename)
  const foo = await getFoo()
  return JSON.stringify({
    foo,
    companyId,
    userId,
    name: 'Acme, Inc.'
  })
}