我正在使用node.js.
我想从该脚本调用的模块函数中访问脚本的文件名。例如,
exampleModule.js:
module.exports = function(){
console.log(__filename);
// more code which may also use the filename
};
example.js
var exampleModule = require("./exampleModule.js")
exampleModule();
这将记录“path / exampleModule.js”。我想知道如何使它记录“path / example.js”,而我宁愿不必传入__filename
作为参数。
提前致谢 :)
找到了:
module.parent.filename
朋友知道Google正确的事情。