You'll have to disable caching and it will work, this saved would print the
directory that required the module;
delete require.cache[__filename];
module.exports = function() {
var path = require('path');
console.log(path.dirname(module.parent.filename));
};
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