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

counterfact

v2.16.1

Published

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

Readme

MIT License Coverage Status Swagger 2.0 OpenAPI 3.0–3.2 Ask DeepWiki

Turn an OpenAPI document into an editable, stateful local API.

Counterfact generates TypeScript handlers and request/response types for supported OpenAPI operations, then starts a local server. Begin with schema-derived sample responses; add shared state, failures, latency, middleware, or selective proxying as your workflow needs them. Route and context files hot-reload while their in-memory state stays available.

Counterfact checks contract shape while giving you a path to shape the behavior. Start with schema-derived responses, then turn them into deterministic, stateful scenarios by editing the generated typed handlers and adding shared context. Model the workflow your client needs, not the real backend's internal complexity. You can explore in seconds and keep the behavior you author as a repeatable local or CI fixture.

Run a live API in 60 seconds

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

This generates editable files in api/, starts the server at http://localhost:3100, serves Swagger UI at http://localhost:3100/counterfact/swagger/, and opens the live REPL. Exit with .exit, Ctrl+D, or Ctrl+C twice.

Requires Node.js 22 or newer. For a repeatable project or CI workflow, install Counterfact as a dev dependency and commit the lockfile:

npm install --save-dev counterfact
npx counterfact ./openapi.yaml api

Start with the workflow you need

| When you need to… | You can… | Start here | | -------------------------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | | Build ahead of your backend | Create a record, read it later, and shape the failure paths | Build a stateful flow | | Make failures repeatable | Reset, fail, recover, and tear down the same way every run | Automate a deterministic test | | Give a coding agent a reliable sandbox | Leave a resettable context and an HTTP test for review | Give an agent a verifiable task | | Bring endpoints online gradually | Keep one client base URL while paths move from local to upstream | Run the checked hybrid path | | Keep the contract in the loop | Regenerate types and catch drift in your normal type check | See a contract change reach a client |

The first-10-minutes guide includes the shared setup, reset and isolation rules, CI lifecycle, and the boundary between contract checks and behavior realism.

Prefer a complete artifact to copy? The CI-checked first-10-minutes example contains a minimal OpenAPI contract, resettable context, typed handlers, real-HTTP test, lockfile, and type-check configuration.

Confidence you can build on

| Where Counterfact helps | What you get | What remains yours | | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | | Generated TypeScript types | Supported status codes, media types, declared headers, and request/response shapes when your project runs a type check | The business rules that make the API truly yours | | Request validation | Required query, header, and cookie parameters plus supported JSON/form bodies; detected mismatches return 400 | Authentication, authorization, path-parameter schemas, and business rules | | Response checks | Required response headers and their schema types, with advisory response-type-error details when something is off | Response-body enforcement and production correctness | | Your handlers, context, and scenarios | The state, rules, failures, reset behavior, and deterministic fixtures your workflow needs | Targeted real-backend and end-to-end coverage for the real service |

Counterfact gives you a fast, contract-shaped world to build against. Keep targeted real-backend and end-to-end coverage for the parts only the real service can prove. See how to make the workflow yours for the practical checklist.

Project lifecycle

  • Commit your OpenAPI document, editable routes/, scenarios, and usually the generated types/ so collaborators share a working contract snapshot.
  • Regeneration overwrites generated types and may append scaffolding for newly added operations; it preserves existing handler bodies unless you explicitly use a destructive option such as --prune.
  • In-memory context survives hot reload. A new process creates fresh context, and its constructor or startup scenario defines the initial state.
  • Counterfact executes TypeScript route files, but it does not run a TypeScript type-check step for you. Include generated files in your project and run your normal type check in CI.
  • Use a user-defined reset() in test setup, and use separate server instances and ports for parallel workers.

Documentation

  • Getting started – Generated files, state, REPL, proxying, and spec changes
  • Usage – Feature map
  • Patterns – Reusable development and testing workflows
  • Reference$ API, CLI flags, and architecture
  • FAQ – State, types, validation, and regeneration
  • How it compares – json-server, WireMock, Prism, Microcks, and MSW
  • Example repository – A larger Petstore implementation

Changelog · Contributing · Security