Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.
The decache npm package is designed to delete modules from the cache in Node.js. This is particularly useful during development when you want to ensure that the latest version of a module is reloaded without having to restart the Node.js process.
Module cache deletion
This feature allows you to remove a specific module from the Node.js require cache. After decaching, the next time you require the module, Node.js will reload it from the filesystem, ensuring you have the latest version without restarting your application.
const decache = require('decache');
decache('./myModule');
let myModule = require('./myModule'); // This will reload the module from file
clear-require is similar to decache in that it clears modules from the require cache. It provides a simple API to clear a specific module or all modules at once. Unlike decache, clear-require also supports clearing modules by a regex pattern.
require-reload offers functionality to reload a module by requiring it again without needing to clear the cache manually. It is a bit more direct in usage compared to decache, as it wraps the require function to automatically decache the module.
import-fresh is designed to import a module by bypassing the cache. It's similar to decache but is more focused on ES6 module syntax compatibility. It's useful for cases where you want to ensure a fresh state of the module on each import.
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 628,521 weekly downloads. As such, decache popularity was classified as popular.
We found that decache demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.