Camilo
Camilo

Reputation: 2853

fs.writeFile() doesn't work on Meteor 0.6.5.1

I was using Meteor 0.6.4.1 and used Npm.require('fs') and fs.writeFile()to save files. Here is the code I used to test it: Gist for save files. I updated Meteor to 0.6.5.1 and got this error:

(STDERR) app/server/save_file.js:18
(STDERR)         throw (new Meteor.Error(500, 'Failed to save file. ' + err));
(STDERR)                ^
(STDERR) Error: Failed to save file. Error: ENOENT, open 'public/carlos.png' [500]
(STDERR)     at Meteor.methods.saveFile (app/server/save_file.js:18:16)
(STDERR)     at fs.writeFile (fs.js:746:21)
(STDERR)     at Object.oncomplete (fs.js:297:15)

I know that node version changed from 0.8.18 to 0.8.24 on Meteor 0.6.5. It's a bug on the 0.8.24 node version or the Meteor 0.6.5 version? It's there any way to solve it or I must stay with 0.6.4.1 Meteor version?

Upvotes: 3

Views: 1176

Answers (1)

saimeunt
saimeunt

Reputation: 22696

In Meteor 0.6.5, they changed the current working directory in the server context, it used to be the Meteor root directory but it is now MyProject/.meteor/local/build/programs/server.

So if you want to access something in the public folder from the server side app, you could try this path : ../../../../../public/.

Warning : writing files to public might cause the server to restart and lead to undefined behaviour.

Upvotes: 4

Related Questions