reload-require
Node module to reload require'd modules
General idea
You require a module, then anywhere from your application you can trigger a "reload" to flush require
's cache such that next call to require(module)
will call a new version.
This library comes with a handy reload.require
(*) that keeps an object's property mapped to a module.
Install
npm install --save reload-require
Usage
var reload = module;
API
Use-case: an interface in your app allows to edit a JSON file that is require'd
// Trigger a reload; // Watch for module's reloadreload; // Assign a module to an object's property and watch it (*)reload; // Optional callback:reload; // Note that "reload" is an EventEmitter, two events may be triggeredreload;reload; // It provides helper for event name dedicated to reloadingreloadevent === "reload"reloadevent"./toto.js" === "reload:/absolute/path/to/toto.js"
(*) reload.require considered harmful
Modifying a variable is considered harmful by functional programmers. Modifying a variable from an unpredictable event, located in a totally different part of the application, is considered harmuful by anyone :)
TODO
- Tests
- Fix memory leak (see examples/memory-leak)