nock is a Node library for mocking HTTP in tests: you write interceptors that say which request to expect and what to reply, or you let Nock Back record real calls to JSON fixture files and replay them [1][2]. Stubsmith also records real calls and replays them, but the SDK masks every body value inside your process before the capture is sent, a person approves each new request shape, and the whole team replays the same reviewed bundle.
The practical difference is what ends up in your fixtures. nock’s recorder stores request bodies, response bodies and response headers as the API returned them, and an afterRecord function you write can change a recording before it is saved [3][11]. Stubsmith is built for the case where the traffic worth recording contains real customer data.
At a glance
| nock | Stubsmith | |
|---|---|---|
| Runtime | Node; current release requires Node 22.20.0 or later [4] | Python, and Node 22.12 or later |
| Intercepts | Node http/https and native fetch through @mswjs/interceptors, with basic undici support since v15 [5][6][16] |
Node http, https and global fetch; Python requests and httpx |
| Mocks from | Interceptors you write, or Nock Back fixtures recorded to a directory you choose [2] | Recorded traffic only |
| Recorded data | Request and response bodies and response headers as returned; request headers off by default [3][7] | Body values masked in your process before sending; sent only for fields you approve |
| A request with no match | A 501 response with ERR_NOCK_NO_MATCH (v15) [8]; unmocked hosts reach the network unless you call disableNetConnect() [9] |
Throws StubNotFound; never reaches the network |
| Where fixtures live | JSON files in your repository [2] | A bundle file you commit, pulled from Stubsmith |
| License and price | MIT, free [10] | SDKs MIT; hosted service with a free plan |
Recording with each
Nock Back records into a fixture directory. Its default mode, dryrun, uses recorded fixtures and lets other calls through without recording them; record adds new recordings; lockdown replays and blocks all real HTTP [2].
Stubsmith records wherever the SDK is installed, for example a staging environment:
import stubsmith from 'stubsmith';
stubsmith.install(); // key read from STUBSMITH_API_KEY
New request shapes wait in Review until someone approves them, and no bodies are stored before that. Then:
npx stubsmith pull --out .stubsmith/bundle.json
import { beforeEach, afterEach, expect, test } from 'vitest';
import { replay, StubNotFound } from 'stubsmith';
let ctx;
beforeEach(() => { ctx = replay(); });
afterEach(() => { ctx.restore(); });
test('an unrecorded call never reaches the network', async () => {
await expect(fetch('https://api.example.com/nope')).rejects.toBeInstanceOf(StubNotFound);
});
Sensitive data
nock does not record request headers by default, and it never records user-agent; its README gives matching stability as the reason [7]. Request and response bodies and response headers are recorded as returned [3]. The way to change a recording before it is saved is your own afterRecord function [11]. nock’s README, checked on the date below, describes no built-in redaction.
Stubsmith masks during capture. A body value without a keep rule becomes "<masked>", 0 or false before the capture leaves your process, and by default no field has a keep rule. Two kinds of value are sent as written: a path segment the SDK does not recognise as an ID, and the values of six transport headers a stub needs to replay. Names are sent as they are: JSON keys, form field names, query-parameter names and header names. So are the method, domain, status and duration of each call. The Security page lists all of it.
Choose nock when
- Everything should stay local: fixtures in your repository, no account, no service [2].
- You want to write a mock before the upstream API exists or is reachable [12].
- You need exact failure cases:
ECONNREFUSED, a specific status, a delay, a different reply on the second call [13][14]. - You want to assert how many times each call was made [15].
Choose Stubsmith when
- The traffic you want to record contains personal data, and real body values must not leave your process unless you approve a field.
- The team should replay one reviewed set of stubs instead of fixtures each developer recorded.
- Your services are in Python as well as Node.
What Stubsmith does not do
- Let you write a mock by hand, or for an API you have never called.
- Simulate socket errors or delays, or return a different reply than the one recorded.
- Assert call counts.
- Work without an account: the SDKs are open source, recording goes through the hosted service. Replaying a committed bundle needs no account or key.
Sources
Facts about nock are from nock's own repository (README, source, release notes and the v15 migration guide; latest release v15.0.6), last checked 2026-11-19. Where the README and the v15 migration guide disagree, this page follows the migration guide. Corrections are welcome at legal@stubsmith.dev.
- README
- Nock Back
- Recorder source
package.jsonengines- v14.0.0 release, native
fetch - v14.0.0-beta.8 release,
@mswjs/interceptors - Request header recording
- Migrating to v15
- Real HTTP requests
- License
- Nock Back options
- Specifying replies
- Replying with errors
- About interceptors
- Optional requests and expectations
- v15.0.0-beta.1 release