node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »


fresh-up npm version

Refreshes NodeJS module when its file is modified

As you know NodeJS caches values returned by require function. When you call require('foo') twice or more it returns the same object. fresh-up watches and clears the cache (via delete require.cache[modulePath]) when the file of the module is modified. The only argument is an absolute path to the module.

npm install --save fresh-up


const freshUp = require('fresh-up');
// require.resolve returns absolute path to ./bar 
function foo() {
    const bar = require('./bar'); // returns another value only if ./bar is changed 
// foo can be called by any async function 
setInterval(() => {
}, 500);