尝试在服务器启动时导入JSON文件.
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
var fs = Npm.require('fs');
Videos = fs.readFileSync("public/toc_vd_en.json", "utf8");
});
}
Run Code Online (Sandbox Code Playgroud)
得到一个 Error: ENOENT, no such file or directory 'public/toc_vd_en.json'
文件结构:
我相信我正在给出正确的相对路径.导致此错误的原因是什么?
伙伴,试试这个:
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
var base = process.env.PWD;
var fs = Npm.require('fs');
Videos = fs.readFileSync(base + "/public/toc_vd_en.json", "utf8");
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |