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

counterfact

v1.4.7

Published

Generate a TypeScript-based mock server from an OpenAPI spec in seconds — with stateful routes, hot reload, and REPL support.

Readme

Spin up a mock server instantly. No config, no fuss. Try it now:

npx counterfact@latest https://petstore3.swagger.io/api/v3/openapi.json mock-api

This command reads an OpenAPI spec (the Swagger Petstore), generates TypeScript code for a mock server in mock-api, and starts the server.

// ./mock-api/routes/store/order/{orderID}.ts
import type { HTTP_GET } from "../../../types/paths/store/order/{orderId}.types.js";
import type { HTTP_DELETE } from "../../../types/paths/store/order/{orderId}.types.js";

export const GET: HTTP_GET = ($) => {
  return $.response[200].random();
};

export const DELETE: HTTP_DELETE = ($) => {
  return $.response[200];
};

Want control? Edit the generated route files (e.g. ./mock-api/routes/store/order/{orderID}.ts) and define responses directly. A type-safe API from your spec speeds up prototyping.

// ./mock-api/routes/store/order/{orderID}.ts
import { Order } from "../../../types/components/schemas/Order.js";
import type { HTTP_GET } from "../../../types/paths/store/order/{orderId}.types.js";
import type { HTTP_DELETE } from "../../../types/paths/store/order/{orderId}.types.js";

export const GET: HTTP_GET = ($) => {
  const orders: Record<number, Order> = {
    1: {
      petId: 100,
      status: "placed",
    },
    2: {
      petId: 999,
      status: "approved",
    },
    3: {
      petId: 1234,
      status: "delivered",
    },
  };

  const order = orders[$.request.orderID];

  if (order === undefined) {
    return $.response[404];
  }

  return $.response[200].json(order);
};

export const DELETE: HTTP_DELETE = ($) => {
  return $.response[200];
};

You can also proxy some paths to the real API while mocking others — perfect when part of the backend isn’t finished or you need to simulate tricky scenarios. See Proxying for details.

Use npx counterfact --help to view CLI flags for customizing behavior (e.g. --port, --proxy, --watch).

Go further with stateful mocks: POST data, then GET it back. Tweak backend data live with a REPL. Update code without restarting the server or losing state.

We believe strongly in API-first development and the Dependency Inversion Principle. When frontend and backend implement the same API spec, they can be built and tested independently. Most of the time, it’s best to test the front end against the real API and full stack. But there's always some part of the backend that isn't finished yet, or a scenario that's cumbersome to reproduce. For this reason, Counterfact supports proxying to the real API for some paths and using mocks for others.

Counterfact was by built an engineer who spent decades writing frontend code and got tired of being slowed down by unfinished or unwieldy backend APIs. This is the fastest way to get unblocked, prototype ideas, and remember what it feels like to enjoy creating stuff.

Requires Node ≥ 17.0.0

Documentation | Changelog | Contributing

MIT License TypeScript Coverage Status