Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
decache
Advanced tools
Readme
decache
Delete a module from node.js' require.cache
so you can freshly require
it again.
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.
When testing our modules we often need to re-require the module being tested. This makes it easy.
An easy way to delete a cached module.
Install the module from npm:
npm install decache --save-dev
// require the decache module:
const decache = require('decache');
// require a module that you wrote"
let mymod = require('./mymodule.js');
// use your module the way you need to:
console.log(mymod.count()); // 0 (the initial state for our counter is zero)
console.log(mymod.incrementRunCount()); // 1
// delete the cached module:
decache('./mymodule.js');
//
mymod = require('./mymodule.js'); // fresh start
console.log(mymod.count()); // 0 (back to initial state ... zero)
Modules other than .js
, like for example, .jsx
, are supported as well.
Note that native modules with the .node
extension are ignored from decaching because
they behave unexpectedly when decached.
If you have any questions or need more examples, please create a GitHub issue: https://github.com/dwyl/decache/issues
Thanks!
FAQs
decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.
The npm package decache receives a total of 881,898 weekly downloads. As such, decache popularity was classified as popular.
We found that decache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.