Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在加载过程中从模块本身内部获取 Node.js 模块的名称?
//mymodule.js console.log(GET_MODULE_FULL_PATH_NAME()) //prog.js require('/full/path/module') OR require('./module') OR require('module.js')
使用__filename. 这会让你得到你想要的。
__filename
http://nodejs.org/api/globals.html#globals_filename