我很困惑,我需要为meteor.js fw 使用fs 包。
从流星版本 0.6> 我需要像这样使用 Npm.require:
var fs = Npm.require('fs');
但是当我这样做时会出现错误:npm is not defined
如何解决?我试过 mrt add npm 但是嗯...
顺便说一句:我有 /root/packages/npm
编辑 我的代码在客户端/服务器端文件夹中,所以我将它移动到服务器的块中
var fs;
if(Meteor.isServer) {
fs = Meteor.require('fs');
}
fs.writeFile(path + name,...
GETTING ERROR: Cannot call a method writeFile of undefined
已解决好吧,我通过将整个内容包装到Meteor.isServer {... 解决了这个错误,但如果有人能好奇地向我解释为什么它不像上面那样工作?