You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
![]() |
5 years ago | |
---|---|---|
.. | ||
node_modules | 5 years ago | |
index.d.ts | 5 years ago | |
index.js | 5 years ago | |
license | 5 years ago | |
package.json | 5 years ago | |
readme.md | 5 years ago |
readme.md
clear-module 
Clear a module from the cache
Useful for testing purposes when you need to freshly import a module.
Install
$ npm install clear-module
Usage
// foo.js
let i = 0;
module.exports = () => ++i;
const clearModule = require('clear-module');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
clearModule('./foo');
require('./foo')();
//=> 1
API
clearModule(moduleId)
moduleId
Type: string
What you would use with require()
.
clearModule.all()
Clear all modules from the cache.
clearModule.match(regex)
Clear all matching modules from the cache.
regex
Type: RegExp
Regex to match against the module IDs.
Related
- 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