mjkaufer
mjkaufer

Reputation: 4206

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.

    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

Answers (1)

Tarang
Tarang

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

Related Questions