Other then the obvious speed implications, there shouldn't be any other downsides to removing the cache? Although not the best case scenario, I believe its the only way to know the file that is requiring the module, as module.parent.filename will update to be the latest file.
On Sunday, November 18, 2012 9:49:18 PM UTC-5, Isaac Schlueter wrote: > > You can look at module.parent.filename, but that's just the first > module to require() you, not necessarily the most recent, due to > caching. > > Deleting yourself out of the cache is likely pretty stupid. Don't do > that. > > But what you're probably more interested in is require.main.filename > or process.cwd() anyway. > > > On Sun, Nov 18, 2012 at 11:34 AM, Jason Brumwell > <[email protected] <javascript:>> wrote: > > 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]<javascript:> > > To unsubscribe from this group, send email to > > [email protected] <javascript:> > > 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
