decache
In node.js when you require()
a module, node stores a cached version of the
module, so that all subsequent calls to require()
do not have to reload
the module from the filesystem.
decache
( Delete Cache ) lets you delete modules from node.js require()
cache
this is useful when testing your modules/projects.
Why?
When testing our modules we often need to re-require the module being tested. This makes it easy.
What?
An easy way to delete a cached module.
How? (usage)
install
Install the module from npm:
npm install decache --save-dev
Use it in your code:
// require the decache module:var decache = ; // require a module that you wrote"var mymod = ; // use your module the way you need to:console; // 0 (the initial state for our counter is zero)console; // 1 // delete the cached module:; //mymod = ; // fresh startconsole; // 0 (back to initial state ... zero)
Modules other than .js
, like for example, .jsx
, are supported as well.
If you have any questions or need more examples, please create a GitHub issue: https://github.com/nelsonic/decache/issues
Thanks!