[英]Create a serverside file in Meteor
I was wondering how to write files in Meteor to the server. 我想知道如何将流星中的文件写入服务器。 I was looking at this NodeJS code, but it wasn't working when I tried it in the server javascript code.
我当时在看这个NodeJS代码,但是当我在服务器javascript代码中尝试它时,它不起作用。
var fs = require('fs');
fs.writeFile("/client/test", "Hey there!", function(err) {
if(err)
console.log(err);
else
console.log("The file was saved!");
});
It was saying that require wasn't defined. 有人说还没有定义需求。 Anyways, does anybody know how to write files to the server in Meteor?
无论如何,有人知道如何在Meteor中将文件写入服务器吗?
You need to use Npm.require
instead of just require
. 您需要使用
Npm.require
而不是require
。
var fs = Npm.require('fs');
This will work for any module that is part of node or meteor (such as fs
so its not a problem here). 这将适用于节点或流星的任何模块(例如
fs
因此在这里不是问题)。 However, for other npm modules you would have to use Meteor NPM or write your own smart package 但是,对于其他npm模块,您将必须使用Meteor NPM或编写自己的智能软件包
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.