evented-require

Require modules and receive events.
Usage
var EventedRequire = require('evented-require');
var basedir = process.cwd();
var loader = new EventedRequire(basedir);
var foo = loader.require('./foo');
var expect = loader.require('expect');
loader.on('before', function(moduleName) {
});
loader.on('success', function(moduleName, result) {
});
loader.on('failure', function(moduleName, error) {
});
loader.requireAll([
'./foo.js',
'./bar.js'
]);
API
new EventedRequire(basedir)
Constructs a new EventEmitter instance. Requires made using this instance will be relative to the basedir given.
instance.require(moduleName)
Instance method for requiring modules relative to the basedir of the instance. Emits events for before, success, and/or failure depending on the outcome of the require. Returns the result of the require if successful.
instance.requireAll(moduleNames)
Instance method for requiring an array of modules in order. Removes duplicates in the array before requiring them. Emits the same events as instance.require for each module. Doesn't return anything.
event: instance.on('before', function(moduleName) {})
Emits the before event before a module is required. Provides the module name to the callback.
event: instance.on('success', function(moduleName, module) {})
Emits the success event after a module is required successfully. Provides the module name and the result of the require to the callback.
event: instance.on('failure', function(moduleName, error) {})
Emits the failure event after a module fails to load. Provides the module name and the error to the callback.
License
MIT