If you mess with the require() cache, it's very possible to create a
situation where you cause infinite loops by require() cycles
re-reading the same files repeatedly and synchronously, and these are
difficult to debug.
It's much better to just export a function, and have your consumer
call that function, rather than re-run your module on every load.
module.exports = function(arg) {
// do stuff
}
// the consumer
var blarg = require('blahrg');
var myBlarg = blarg(__filename);
On Wed, Nov 21, 2012 at 10:50 PM, dhruvbird <[email protected]> wrote:
> Looks you want separate behaviour for every module require()ing you. Why not
> force every caller to instantiate an object of your custom class type,
> passing in a directory location? This has the added side effect of allowing
> a single module to instantiate multiple objects with potentially different
> arguments (something you might need later - it at least smells like it).
>
>
> On Saturday, November 10, 2012 9:02:50 AM UTC-5, boden wrote:
>>
>> hi all,
>> trying to find the proper way to determine the path of the module
>> requiring my module given the following requirements:
>>
>> * must be strict mode complaint
>> * cannot depend on node arguments (i.e. process.argv)
>> * must work when being required from different modules in the same
>> execution (i.e. my module is already cached)
>>
>> i ended up patching Module._load() to capture the request and then
>> wrapping it in a closure like shown here:
>> https://github.com/bodenr/expose/blob/master/index.js
>>
>> however this doesn't feel right -- i must be missing something.
>>
>> thx in advanced
>
> --
> 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
--
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