Low-level HTTP/HTTPS/XHR request interception library for Node.js, currently at v0.6.3 (stable). It monkey-patches native modules like http, https, fetch, and XMLHttpRequest to intercept all outgoing requests, allowing custom logic to be applied before responses are sent. Unlike high-level mocking libraries (e.g., nock, sinon), it provides no request matching or routing—just raw interception. It is designed as a building block for tools like MSW. Releases are frequent, with active maintenance and breaking changes in v0.41.0 affecting CJS exports. Ships TypeScript types and supports ESM and CJS.
npm install node-request-interceptorVerified import paths — ran on the pinned version, not inferred.
Creates an interceptor with default presets, adds a middleware to mock a specific request, then restores after use.
For CJS, use `const preset = require('node-request-interceptor/presets/node');` instead of `const { default: preset } = require(...)`.Update your middleware to handle the new `RequestController` argument if needed.
Use `afterEach(() => interceptor.restore())` in tests, or scope the interceptor to a specific lifecycle.
Only use XMLHttpRequest interceptor if you are in a jsdom environment. For Node.js HTTP/HTTPS, use the default presets.
Use `import withDefaultInterceptors from 'node-request-interceptor/presets/default'` instead of manually importing individual interceptors.
Use `import withDefaultInterceptors from 'node-request-interceptor/presets/default';`
Correct: `const interceptor = new RequestInterceptor(withDefaultInterceptors);`
Remove the XMLHttpRequest interceptor or ensure jsdom is loaded before using it.
No dependency data recorded yet.