How to use "fs" in Meteor?


#1

How to use “fs” in Meteor?
How to declare?
Ex:

var fs = Npm.require('fs');
var path = Npm.require('path');
var basePath = path.resolve('.').split('.meteor')[0];

Meteor.methods({
    witeFile: function () {
        console.log(basePath);
        var temPath = basePath + 'cpanel/sever/gen';
        console.log(temPath);
        fs.writeFileSync(temPath + 'message.js', 'Hello Node.js', 'utf8');
    }
});

But don’t work.
Please help me.


#2

hey,

i just tested that code:

var fs = Npm.require('fs');
console.log(fs)

this works fine for me on the server


#3

How about on the client? (Need to read camera roll on iOS)


#4

Thanks, now work fine for me.


#5

you cant use nodejs code on the client
for that you need cordova plugins like:
https://github.com/driftyco/cordova-camera-roll


#6

Can I do it using Javascript? I saw some file reading functionality (Reader, etc) The security of this seems complex though.


#7

I think I’ll open a new thread on this.