MSW (Mock Service Worker)

Seamless REST and GraphQL API mocking for browser and Node.js

Library
npm
v3.0.3
18,307 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 80
Maintenance 88
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 88
Code Quality 90
Innovation 92
Learning Curve 80

MSW (Mock Service Worker) intercepts outgoing requests at the network level rather than patching fetch/XMLHttpRequest in your application code. In the browser it uses the Service Worker API to intercept requests before they leave the page; in Node.js it patches the underlying request-dispatching layer. Either way, your application code and tests remain unaware that responses are mocked — they see the same requests and responses they would in production.

Handlers are defined with an Express-like routing syntax (http.get('/users/:id', resolver), graphql.query(...)), supporting path parameters, wildcards, and regular expressions, with resolvers able to return custom status codes, headers, cookies, delays, or streaming responses. The same handler definitions work across unit tests, integration tests, Storybook, and live browser development, so mocks are written once and reused everywhere.

What You Get

  • setupWorker() for browser-based interception via a generated Service Worker script, and setupServer() for Node.js test environments
  • Express-like http.get/post/put/... and graphql.query/mutation handler syntax with path params, wildcards, and regex matching
  • A CLI (msw init) to scaffold the Service Worker file into your public/static directory
  • Composable resolvers supporting custom status codes, headers, cookies, response delays, and streaming bodies
  • Life-cycle events and request/response logging for debugging which handlers matched a given request

Common Use Cases

  • Mocking backend REST/GraphQL APIs in unit and integration tests without patching fetch or spinning up a real server
  • Running Storybook stories or local development against mocked API responses before the real backend endpoint exists
  • Simulating error states, slow networks, or edge-case API responses that are hard to reproduce against a real backend
  • Sharing one set of mock handlers between tests, Storybook, and browser-based manual QA to avoid mock drift

Under The Hood

Architecture - MSW’s src/core module holds the runtime-agnostic pieces (handler matching, resolver execution, life-cycle events), while src/browser implements Service-Worker-based interception (generating and registering mockServiceWorker.js) and src/node implements interception by patching Node’s request-dispatch internals via an interceptors library — both runtimes funnel matched requests through the same core resolver pipeline so handler code is 100% shared. Tech Stack - Written in TypeScript (97% of the codebase) with a dual CJS/ESM build produced by tsup, tests run under Vitest, and the package ships separate browser, node, native, and iife entry points via conditional exports in package.json for each target environment. Code Quality - The test/ directory mirrors src/ with dedicated suites per interception target plus a large integration-test surface, and knip.json/commitlint.config.js indicate enforced unused-export detection and commit-message conventions; the project has 181 contributors and consistent release cadence. API Design - The Express-like http.get(path, resolver) syntax gives JS/TS developers a near-zero learning curve, graphql.query/mutation mirrors the same pattern for GraphQL, and life-cycle events (server.events.on('request:start', ...)) provide debuggability without extra tooling.

Used by 57 apps in this directory

Ruby
62%
BSD 3

Spree Commerce

CRM · Ecommerce · Marketing

15,774

Open-source headless eCommerce platform with a REST API, TypeScript SDK, and Next.js storefront for B2B, cross-border, and marketplace commerce — no vendor lock-in, no platform fees.

View details
91
Repo Health
84
Technical
75
Dependency
Built with
Ruby 62%
TypeScript 37%
Updated 6 days ago
TypeScript
47%
Other

Stirling PDF

Digital Signiture · Productivity

94,824

The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.

View details
92
Repo Health
86
Technical
68
Dependency
Built with
TypeScript 47%
Java 44%
Updated 5 days ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 6 days ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 5 days ago
Go
75%
AGPL 3.0

Teleport

Authentication · Security

21,016

Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.

View details
94
Repo Health
81
Technical
68
Dependency
Built with
Go 75%
TypeScript 16%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,119

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 6 days ago
Go
94%
MIT

Traefik

Automation · Devops · Security

65,344

A cloud-native reverse proxy and load balancer that auto-configures itself from Docker, Kubernetes, and other orchestrators — zero manual routing required.

View details
93
Repo Health
85
Technical
64
Dependency
Built with
Go 94%
Updated 6 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 6 days ago
TypeScript
99%
MIT

Umami

Analytics

39,609

Privacy-first web analytics that respects your users — self-hosted, cookieless, and GDPR compliant out of the box.

View details
95
Repo Health
83
Technical
67
Dependency
Built with
TypeScript 99%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers