Nock

HTTP request mocking and intercepting library for Node.js. Intercepts outgoing HTTP/HTTPS requests at the Node.js http/https module level and returns mocked responses without actual network calls. Used in unit/integration tests to mock external API calls. Works with any HTTP client library (axios, node-fetch, got, http.request) since it intercepts at the Node.js core level.

Evaluated Mar 07, 2026 (0d ago) v13.x / 14.x
Homepage ↗ Repo ↗ Developer Tools testing mocking http interceptor node jest mocha api-testing
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
98
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
80
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
85
Secret Handling
100

MIT licensed. Test-only library — never deployed to production. Intercepts at OS level — ensure test isolation with nock.cleanAll().

⚡ Reliability

Uptime/SLA
100
Version Stability
88
Breaking Changes
82
Error Recovery
88
AF Security Reliability

Best When

You're writing Node.js unit/integration tests and need to mock HTTP API calls for any HTTP client library without test-specific adapter code.

Avoid When

You're testing browser-side code — use msw instead. For integration tests hitting real APIs, nock may over-constrain test fidelity.

Use Cases

  • Mock external API calls in agent unit tests to test agent behavior with controlled responses without network access
  • Record real API responses (nock.recorder) and replay them in tests for reproducible integration testing
  • Test error handling in agent code by mocking specific HTTP error responses (500, 401, timeouts)
  • Test retry logic and backoff behavior in agent HTTP clients by simulating transient failures
  • Mock Stripe, OpenAI, GitHub, or other external APIs in CI pipelines without live API credentials

Not For

  • Browser testing — nock intercepts Node.js http module; use msw (Mock Service Worker) for browser or Playwright's route interception
  • Persistent test doubles across process restarts — nock interceptors exist only in-memory for current test process
  • GraphQL-specific mocking — nock works at HTTP level; use graphql-mocking libraries for schema-aware mocks

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no authentication required. MIT licensed.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT licensed. Zero cost.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Always call nock.cleanAll() in afterEach/afterAll — stale interceptors affect subsequent tests and cause hard-to-debug test pollution
  • Nock interceptors are consumed on first match by default — use .persist() for interceptors that handle multiple requests: nock('https://api.example.com').get('/data').reply(200, data).persist()
  • nock.disableNetConnect() is essential for preventing accidental real network calls in tests — call in global test setup; add allowUnmocked for specific hosts if needed
  • Request body matching: nock intercepts based on URL+method by default; add .matchHeader() or request body matchers for precise interception
  • Nock v13+ dropped Node.js < 12 support — ensure test environment compatibility
  • Nock intercepts http AND https but hostname must match exactly — 'https://api.example.com' does NOT match 'http://api.example.com'; specify correct protocol

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for Nock.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-07.

6470
Packages Evaluated
26150
Need Evaluation
173
Need Re-evaluation
Community Powered