【发布时间】:2013-08-01 03:58:02
【问题描述】:
我正在尝试使用 node.js 读取本地文件。我的 NPM 模块试图执行一个子进程,然后打开一个文件来读取。阅读此内容时会引发错误
{ [Error: ENOENT, open 'E:\Project\SecIntegrator\Attack\manifest.json']
errno: 34,
code: 'ENOENT',
path: 'E:\\Project\\SecIntegrator\\Attack\\manifest.json' }
读取这个文件的实际路径是
E:\Project\SecIntegrator\node_modules\restScannerDriver\GarudRudra\Attack\manifest.json
我已使用 var configPath = path.join(path.dirname(fs.realpathSync(__filename)), '/'); 计算绝对路径,但仍然无法正常工作。
【问题讨论】:
-
你用的是哪种阅读方式?
-
file.readFile(fileName, 'utf8', function (err,data) {} -
不确定,但您的路径看起来像 Windows 路径,所以请看这里stackoverflow.com/questions/10015877/…
-
如果我从不同的命令提示符运行代码作为独立代码,它工作正常。当我将它集成为 NPM 模块时,它无法正确地走路径。