Determining Paths for Loaded Modules in Node.js
In Node.js, is there any way to determine where on the filesystem a module was loaded from?
I do NOT mean, what directory context Node.js is executing in--which you can determine with process.cwd()
. I want to know something specific about whatever module is in memory.
For instance, in Python I can do the following...
>>> import os
>>> os.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/os.pyc'
Which shows me where on the filesystem the os
module is from. Is there anyway 开发者_Python百科to do something similar in Node.js?
NOTE: I was trying to ask this question when I asked my previous question, but I phrased it poorly and ended up getting an answer to a different question.
You should be able to use require.resolve('module_name')
Maybe you could use the require.resolve(...) function to get what you are looking for.
精彩评论