Registry / testing / flush-cache

flush-cache

JSON →
library1.0.1jsnpmunverified

Flush the Node.js internal require cache, ensuring modules are re-evaluated fresh on subsequent require() calls. Current version 1.0.1, last updated 2017, no active development or known releases since. Key differentiator: simple, single-function library that clears the entire module cache recursively, useful for writing isolated tests in Mocha or AVA. Minimal alternative to more feature-rich cache-busting tools or manual cache management.

npm install flush-cache
INSTALL
IMPORT
SIG · FLUSH-CACHE
F
flush-cache
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flushCache
const flushCache = require('flush-cache')
import flushCache from 'flush-cache'
Package is CommonJS-only (no ESM entry). Use require() in Node.js environments.
flushCache (default import in ESM via createRequire)
import { createRequire } from 'module'; const require = createRequire(import.meta.url); const flushCache = require('flush-cache');
import flush from 'flush-cache'
For Node.js ESM modules, use createRequire to import CommonJS packages.
flushCache (TypeScript)
import flushCache = require('flush-cache');
import flushCache from 'flush-cache'
TypeScript with esModuleInterop: false. Use import = require() syntax for CommonJS modules.

Shows how to use flush-cache to clear the require cache before each Mocha test, ensuring fresh module imports.

const flush = require('flush-cache'); // Clears all cached modules so subsequent require() calls re-evaluate flush(); // Example: with Mocha beforeEach(() => { flush(); const freshModule = require('./myModule'); });
Debug
Known issues
breakingflush-cache clears the entire module cache, which may break modules that expect their dependencies to be singletons (e.g., database connections, config singletons).
fix
Avoid flushing cache in production code; only use in test setup. Manually preserve specific modules if needed by re-requiring them after flush.
affects: >=0.0.0
deprecatedPackage is unmaintained since 2017 and has no activity. No ES module support, no TypeScript declarations.
fix
Consider using modern alternatives like 'jest.isolateModules()' for testing, or manually manage cache with 'delete require.cache[modulePath]'.
affects: >=0.0.0
gotchaflush-cache ignores certain internal modules (e.g., 'deasync') to prevent crashes, but the list may be outdated. Some modules may still break.
fix
Check if the ignored list covers your dependencies. If a module breaks, consider an alternative or manual cache clearing.
affects: 1.0.1
Errors
Common errors & fixes
Cannot find module 'flush-cache'
Package installed as devDependency but required in production code or not installed at all.
fix
Ensure npm install --save-dev flush-cache is run. Use in test scripts only, not in production entry points.
TypeError: flush is not a function
Default import in ESM environment where package uses require().
fix
Use const flush = require('flush-cache') instead of import flush from 'flush-cache'.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
flush-cache — npm install flush-cache · libregistry