MSW (Mock Service Worker)

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

Library
npm
v2.15.0
18,227 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 72
Maintenance 80
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

TypeScript
76%
AGPL 3.0

Abby

Developer Tools · Product Management

166

Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.

View details
31
Repo Health
70
Technical
64
Dependency
Built with
TypeScript 76%
MDX 18%
Updated 1 years ago
TypeScript
82%
Other

AFFiNE

Collaboration · Note Taking · Productivity

73,040

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 82%
Rust 11%
Updated 5 days ago
Python
99%
MIT

Agent Lightning

AI Development

18,515

A Microsoft-built training framework that optimizes AI agents with reinforcement learning, automatic prompt optimization, or supervised fine-tuning — with near-zero code changes to your existing agent, in any framework.

View details
85
Repo Health
68
Technical
69
Dependency
Built with
Python 99%
Updated 4 days ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 4 days ago
TypeScript
68%
Apache 2.0

Appsmith

Automation · Developer Tools · No Code Platforms

40,959

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript 68%
Java 21%
Updated 6 days ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 4 days ago
TypeScript
100%
MIT

Botpress

AI Assistants · AI Development · Customer Support

14,924

The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 100%
Updated 1 weeks ago
Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
Java
72%
Other

ByteChef

AI Agents · Automation

1,003

Unified open-source platform for AI agent orchestration and workflow automation with 180+ connectors, MCP support, and durable execution.

View details
85
Repo Health
82
Technical
67
Dependency
Built with
Java 72%
TypeScript 28%
Updated 5 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