{"library":"node-request-interceptor","title":"node-request-interceptor","description":"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.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install node-request-interceptor"],"cli":null},"imports":["import { RequestInterceptor } from 'node-request-interceptor'","import withDefaultInterceptors from 'node-request-interceptor/presets/default'","import { interceptXMLHttpRequest } from 'node-request-interceptor/interceptors/XMLHttpRequest'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { RequestInterceptor } from 'node-request-interceptor';\nimport withDefaultInterceptors from 'node-request-interceptor/presets/default';\n\nconst interceptor = new RequestInterceptor(withDefaultInterceptors);\n\ninterceptor.use((req) => {\n  if (req.url.href === 'https://api.example.com/data') {\n    return {\n      status: 200,\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({ message: 'mocked' }),\n    };\n  }\n  // return undefined to bypass\n});\n\n// Now any request to that URL will be intercepted\nfetch('https://api.example.com/data').then(res => res.json()).then(console.log);\n\n// Later, restore original modules\ninterceptor.restore();\n","lang":"typescript","description":"Creates an interceptor with default presets, adds a middleware to mock a specific request, then restores after use.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}