Meteor: "ReferenceError: fs is not defined"

lehtu picture lehtu · Apr 24, 2015 · Viewed 9.2k times · Source

Losing my mind with this one..

Getting "fs is not defined" on meteor when trying to read a file:

var data = fs.readFileSync(filepathHidden);

I have this package: cfs:filesystem 0.1.2 on Meteor 1.1.0.2

Funny thing here is that if I write in meteor shell fs it prints object and it seems to have lot of functions etc stuff. But the thing here is that after writing fs in meteor shell my code starts to work!? And if I close meteor server and then start it again my server code keeps nagging until I run fs in meteor shell...

Can someone please explain what happens in this case? And how to achieve same thing in my code..

Answer

David Weldon picture David Weldon · Apr 24, 2015

You just need to load it in via npm. In meteor that looks like:

var fs = Npm.require('fs');
var data = fs.readFileSync(filepathHidden);