require-again is a lightweight Node.js utility that clears the require cache for a given module path, allowing you to re-require it with fresh state. This is particularly useful in unit tests where you need to test code that behaves differently based on environment variables or other runtime conditions (e.g., NODE_ENV). The package is version 2.0.0, last updated with support for Node.js 4-6. Unlike other cache-busting tools (like decache or rerand), require-again re-adds the module back to the cache after re-requiring, so subsequent normal requires return the cached version. It has zero dependencies and a minimal API.
npm install require-againNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates using requireAgain to re-require a module with a changed environment variable, showing that the cache is bypassed and the module gets a fresh evaluation.
If you need persistent cache clearance, use decache or manually delete the entry from require.cache before requiring.
Test with your Node version or consider using a more modern alternative like decache or jest.resetModules().
Always use the same resolved path (e.g., via path.resolve) when requiring and calling requireAgain.
Run 'npm install require-again'
Use 'const requireAgain = require('require-again');'No dependency data recorded yet.