FS file system reading and writing issues


#1

Newbie to Node fs here.
I can’t seem to find an up-to-date example on reading and writing files from the app directories. I can make the reading and writing work from a pure node.js console, but not within meteor. Seems like this shouldn’t be so difficult.

READING: The only example I found that works with Meteor 1.1.0.2, has an ugly directory hack. (http://stackoverflow.com/questions/16762983/reading-files-from-a-directory-inside-a-meteor-app)

 var fs = Npm.require('fs');
 //Doesn't work
 fs.readFileSync('test.csv');
 //works
 fs.readFileSync('../../../../../test.csv');

WRITING: This example produces no errors, but it also doesn’t create a file. Can anyone else reproduce this?

var fs = Npm.require('fs');
fs.writeFile('./packages/helloworld.txt', 'Hello World!', function (err) {
  if (err) return console.log(err);
  console.log('Hello World > helloworld.txt');
});