
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
import-fresh
Advanced tools
The import-fresh npm package is used to import a module afresh, bypassing the cache that Node.js uses for require calls. This is particularly useful when you need to ensure that you're getting a fresh version of the module, for instance, when you're testing or when you want to reload configuration files that may have changed.
Bypass require cache
This feature allows you to bypass the require cache and freshly import a module. It's useful when you want to reload a module to reflect any changes made to it since it was first imported.
const importFresh = require('import-fresh');
const freshConfig = importFresh('./config');
Proxyquire is a package that allows you to override dependencies during testing. It provides a way to stub out modules similar to import-fresh, but with an emphasis on mocking for testing purposes.
Decache is a package that lets you delete modules from the require cache. It is similar to import-fresh in that it allows for modules to be re-required as if they were never cached, but it does not provide a direct method to re-import a module.
Clear-require is a package that clears a module from the require cache. It is similar to import-fresh, but instead of re-importing the module, it simply clears it from the cache, requiring an additional call to 'require' to reload the module.
Import a module while bypassing the cache
Useful for testing purposes when you need to freshly import a module.
For ESM, you can use this snippet:
const importFresh = moduleName => import(`${moduleName}?${Date.now()}`);
const {default: foo} = await importFresh('foo');
This snippet causes a memory leak, so only use it for short-lived tests.
npm install import-fresh
// foo.js
let i = 0;
module.exports = () => ++i;
const importFresh = require('import-fresh');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
importFresh('./foo')();
//=> 1
importFresh('./foo')();
//=> 1
FAQs
Import a module while bypassing the cache
The npm package import-fresh receives a total of 45,429,589 weekly downloads. As such, import-fresh popularity was classified as popular.
We found that import-fresh demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.