ENOENT Error when deployed to meteor server

亡梦爱人 提交于 2019-12-13 01:28:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!