Reputation: 4206
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.
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?
Upvotes: 0
Views: 193
Reputation: 75945
You need to use Npm.require
instead of just 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). However, for other npm modules you would have to use Meteor NPM or write your own smart package
Upvotes: 1