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

TypeScript
51%
ZLIB

Portainer

Devops

38,707

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
93
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,326

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
87
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 5 days ago
TypeScript
100%
AGPL 3.0

RSSHub

Automation · Social Media

46,631

Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.

View details
94
Repo Health
82
Technical
71
Dependency
Built with
TypeScript 100%
Updated 5 days ago
TypeScript
91%
MIT

SerpBear

Analytics · Marketing

2,128

Self-hosted keyword rank tracker with Google Search Console integration, multi-provider SERP scraping, and a built-in REST API.

View details
48
Repo Health
67
Technical
68
Dependency
Built with
TypeScript 91%
Updated 5 months ago
PHP
58%
AGPL 3.0

Nextcloud Server

Collaboration · File Storage

37,265

Your own private cloud: self-hosted file sync, collaboration, and communication with no vendor lock-in.

View details
95
Repo Health
77
Technical
81
Dependency
Built with
PHP 58%
JavaScript 32%
Updated 5 days ago
TypeScript
50%
Other

SigNoz

Analytics · Monitoring

32,429

Self-host your entire observability stack — logs, metrics, traces, and LLM monitoring — in one OpenTelemetry-native platform, without the Datadog bill.

View details
92
Repo Health
83
Technical
64
Dependency
Built with
TypeScript 50%
Go 38%
Updated 6 days ago
TypeScript
95%
MIT

Skrun

AI Agents

210

An open, self-hostable, multi-model agent runtime that deploys any agent skill as an API via POST /run — an open-source alternative to Claude Managed Agents and Google's Gemini Enterprise Agent Platform.

View details
54
Repo Health
66
Technical
77
Dependency
Built with
TypeScript 95%
Updated 1 months ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
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