Registry /
http-networking / node-request-interceptor
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.
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ESM-only since v0.41.0? The package is primarily ESM, but CJS require is still supported via default export. Use ESM for best compatibility.
import { RequestInterceptor } from 'node-request-interceptor'
In CJS, use require('node-request-interceptor/presets/default') directly, not with .default property.
import withDefaultInterceptors from 'node-request-interceptor/presets/default'
This is a named export, not default. The path is case-sensitive.
import { interceptXMLHttpRequest } from 'node-request-interceptor/interceptors/XMLHttpRequest'
Creates an interceptor with default presets, adds a middleware to mock a specific request, then restores after use.
import { RequestInterceptor } from 'node-request-interceptor';
import withDefaultInterceptors from 'node-request-interceptor/presets/default';
const interceptor = new RequestInterceptor(withDefaultInterceptors);
interceptor.use((req) => {
if (req.url.href === 'https://api.example.com/data') {
return {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'mocked' }),
};
}
// return undefined to bypass
});
// Now any request to that URL will be intercepted
fetch('https://api.example.com/data').then(res => res.json()).then(console.log);
// Later, restore original modules
interceptor.restore();
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.