我正在使用node.js。
我想从该脚本调用的模块函数中访问脚本的文件名。例如,
exampleModule.js:
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p>This is a paragraph.</p>
<p>Specifying the font-size in em allows all major browsers to resize the text.
Unfortunately, there is still a problem with older versions of IE. When resizing the text, it becomes larger/smaller than it should.</p>
example.js
module.exports = function(){
console.log(__filename);
// more code which may also use the filename
};
这将记录&#34; 路径 /exampleModule.js"。我想知道如何使它成为日志&#34; 路径 /example.js"并且我不必传递var exampleModule = require("./exampleModule.js")
exampleModule();
作为参数
提前致谢:)
答案 0 :(得分:0)
找到它:
module.parent.filename
朋友知道谷歌的正确选择。