Clear a module from the cache
Useful for testing purposes when you need to freshly import a module.
$ npm install --save clear-module
// foo.js
let i = 0;
module.exports = () => ++i;
const clearModule = require('clear-module');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
clearModule('./foo');
require('./foo')();
//=> 1
Type: string
What you would use with require()
.
Clear all modules from the cache.
Clear all matching modules from the cache.
Type: RegExp
Regex to match against the module IDs.
- import-fresh - Import a module while bypassing the cache
- import-from - Import a module from a given path
- import-cwd - Import a module from the current working directory
- import-lazy - Import a module lazily
MIT © Sindre Sorhus