简体   繁体   中英

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 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.

你应该能够使用require.resolve('module_name')

也许你可以使用require.resolve(...)函数来获得你想要的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM