【发布时间】:2014-11-12 23:47:29
【问题描述】:
我正在尝试在“自包含”模块中引用 html 文档。该模块由两个文件组成:
app_root/node_module/my_module/main.js
app_root/node_module/my_module/header.html
main.js 包含:
module.exports.test = function() {
var doc = fs.readFileSync('./header.html');
console.log(doc);
}
当我在app_root/program.js 中运行我的程序时
require('my_module').test();
当我启动我的应用程序时,当前工作目录设置为app_root。当它尝试读取 ./header.html 时,它会因为路径不正确而中断。
如何在不知道正在运行什么的情况下找到已安装模块的目录?
【问题讨论】:
标签: javascript html node.js scope