Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read and write files to the server with Meteor?

I'm working on a NoDB CMS in Meteor, but I'm new to both Meteor and JavaScript frameworks.

How do I go about reading and writing files to the server?

like image 225
Bob Rockefeller Avatar asked Jun 17 '13 23:06

Bob Rockefeller


1 Answers

Within the Node fs module you have a writeFile function.

getUser = Meteor.users.findOne({_id : Meteor.userId()});
userObject = JSON.stringify(getUser);
var path = process.env["PWD"] + "/public/";
fs.writeFile(process.env["PWD"] + "/public/"+Meteor.userId()+'.txt', userObject, 
        function (err) {
            if (err) throw err;
              console.log('Done!');
        }
    );

The above snippet would create a file with all the information of the user. You could access the properties of the result of your query with something like getUser._id to prepare your data parameter (String or Buffer) to print pretty.

All this of course is server side.

like image 58
Diego Avatar answered Nov 10 '22 08:11

Diego