The require function is created anew for each module:

*function require(path){ return self.require(path); }*

Which ends up at

*Module.prototype.require = function(path){ return Module._load(path, 
this); }*
*
*
In order to begin injecting your own logic you can start at

*var Module =  require('module');*
*var util = require('util');*
*
*
*function MyModule(){ Module.apply(this, arguments) }*
*util.inherits(MyModule, Module);*
*MyModule.prototype.require = function(path){ /*custom logic*/ }*
*
*
*var mymodule = Object.getOwnPropertyNames(module).reduce(function(r,s){ 
r[s] = module[s]; return r; }, Object.create(MyModule.prototype));*
*
*
In order to make the new module class propagate through resulting requires 
you need to wrap Module._load because it instantiates a new Module and 
won't honor whatever your custom module is.

You can see an example of a full implementation of that here 
https://github.com/Benvie/Node.js-Ultra-REPL/blob/master/lib/ScopedModule.js

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to