1.0.1 • Public • Published


Load and reload your Node.js modules whenever you wish, bypassing the require cache, and without having to restart your application.

Download via npm:
> npm install --save active-require

Basic usage for loading and reloading:

(Note: do not assign module variables you plan to reload using const, as attempts to reassign these values at a later time will produce an error)

//load the ActiveRequire module itself
const _require = require('active-require')
//load your target module using ActiveRequire
var myModule = _require('my-module')
//later, after having made changes to the module's files and/or dependencies, reload the module
myModule = _require('my-module')
//myModule will now contain your updated module's content

Or, use ActiveRequire's helper methods:

Load a single module and assign it to a namespace:
_require.set('myModule', 'my-module')
//now returns the loaded module from the 'my-module' package
Or, load multiple modules at once:
//use keys to define each namespace and the each key's
//value to define the module to load for that namespace
  myModule : 'my-module',
  request : 'request',
  mongo : 'mongodb',
  _ : 'underscore'
// myModule, request, mongo, and _ are now all defined
// in the global scope and assigned their respective modules
Later, reload one of the modules:
//updated module content will be loaded and assigned to myModule namespace
//now returns updated module
Or, reload multiple modules:
_require.reset('myModule', 'mongo', '_')
let targetModules = ['myModule', 'mongo', '_']
//each module will be reloaded and the reloaded
//value will be assigned to the appropriate namespace



Load or reload a target module, using the same approach and format as the traditional require() method.

Argument Description Type Required Default
module The target module you wish to load (should match usual require() target module format). String Yes n/a

_require.set(namespace, [module], [context])

Load a module and assign it to a specific namespace in the provided context's scope (default scope is global).

Argument Description Type Required Default
namespace If String:
Defines the namespace to which the loaded module should be assigned.

If Object:
A set of key:value pairs, where each key defines the namespace to be used and each value defines the module to be loaded and assigned to the requisite namespace.
String/Object Yes n/a
module The module to be loaded and assigned to the namespace provided by the namespace argument. String No null
context The context within which the module should be loaded and assigned. Object No global


Reload the modules assigned to each provided namespace (will only work for modules and namespaces previously loaded using the _require.set() method).

Argument Description Type Required Default
namespaces Either a single module namespace, multiple independent module namespaces, or an array of module namespaces that have been loaded using the _require.set() method previously, and that you would now like to have be reloaded and re-assigned to the namespace(s) provided. String/Array Yes n/a


Starts an repl session, allowing for modules to be loaded and reloaded via the command-line (using the _require.set() and _require.reset() methods) for any Node.js application being run in a terminal environment.

Returns an object map containing information on the current namespaces defined via the _require.set() and _require.reset() methods and the module sources/values assigned to those namespaces.

**For any additional questions and/or comments, please contact: **


npm i active-require

DownloadsWeekly Downloads






Last publish


  • mcullenlewis