
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
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 54,036,659 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.