[英]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? 在Node.js中,有没有办法确定从哪个文件系统加载模块?
I do NOT mean, what directory context Node.js is executing in--which you can determine with process.cwd()
. 我不是说,Node.js正在执行什么目录上下文 - 您可以使用
process.cwd()
来确定。 I want to know something specific about whatever module is in memory. 我想知道关于内存中任何模块的具体内容。
For instance, in Python I can do the following... 例如,在Python中我可以执行以下操作...
>>> 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. 这显示了
os
模块来自文件系统的位置。 Is there anyway to do something similar in Node.js? 无论如何在Node.js中做类似的事情?
你应该能够使用require.resolve('module_name')
也许你可以使用require.resolve(...)函数来获得你想要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.