Skip to content

finom/fresh-up

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

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

Example:

const freshUp = require('fresh-up');

// require.resolve returns absolute path to ./bar
freshUp(require.resolve('./bar'));

function foo() {
    const bar = require('./bar'); // returns another value only if ./bar is changed
    bar();
}

// foo can be called by any async function
setInterval(() => {
    foo();
}, 500);

About

require function wrapper which returns actual module value

Resources

License

Stars

Watchers

Forks

Packages

No packages published