问题
I am using the fs package for my meteor project to open a file on server startup. This works perfectly fine when testing locally, but when I deploy to the meteor server, I'm receiving this error.
WARNING Error: ENOENT, open '/server/filename.csv'
WARNING events.js:72
The code where the error is coming up:
Meteor.startup( function() {
var input = fs.createReadStream(process.env.PWD + 'server/filename.csv');
});
回答1:
Meteor isn't designed for reading and writing files with fs
. When you bundle your Meteor app/publish it in production mode the folder structure is nothing like what it is in development.
You can read static files by creating a directory in your project called private
and placing your text files in it.
You can then read them (on the server side) as @David Weldon suggests:
var text = Assets.getText("filename.csv");
Keep in mind its not recommended to read files using fs
incase the production mode directory structure changes between Meteor versions.
Its not recommended to write files in case you have a different server serving the request which may not have the previously written file.
来源:https://stackoverflow.com/questions/28533669/enoent-error-when-deployed-to-meteor-server