Inject middleware into Node.js require() calls before they hit the cache, file system, or native modules. Version 1.0.0 is the initial stable release. It allows intercepting and transforming modules at load time, useful for instrumentation, mocking, or polyfilling. Differentiates by operating at the require level rather than module-level hooks, providing a middleware pipeline similar to Express.
npm install require-middlewareVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a middleware function, wrapping require, and unwrapping.
Call unwrap() before wrap() again, or check if already wrapped.
Register all middleware via use() before calling wrap().
Access mod.exports to modify the module's exports.
Use path.relative or resolve manually if comparing paths.
Call unwrap() before wrapping again, or conditionally wrap.
Run npm install require-middleware and ensure import/require path is correct.
Use { use } from 'require-middleware'.No dependency data recorded yet.