I notice that DEV ENV on meteor, public folder is under /public.
So I use something like:
fs.writeFile(process.env.PWD + “/public/” + file)
To save files.
On production, I notice that public folder is under /programs/web.browser/app.
So, when I save files on production, it goes to /public but when I try to retrieve them, it tries in /programs and dont find it.
What am I doing wrong? How can I upload to correct folder on DEV or change public folder on PROD?
What are you trying to write?
The “public” folder is not meant to be used for writing files during runtime
Hum… I just created a folder inside called Contents and I’m saving user files there. Where should them be saved so? I understood tha public is where I can save files visible to all users. No?
“public” is the wrong folder to use.
If you are writing this in your own server, you need to setup your server so that files in a particular folder will be available for users with the correct permissions.
It can also be done on a 3rd party storage like AWS S3.
Thanks again for your answer. In fact, there is just one server with one small aplication in meteor. I will not use AWS or other S3. If I want to use the same server to save couple of files from application, which approach should I use for folders?
It depends on the web server you are using.
Here is an example way of accessing static files from an nginx server: Serving Static Content | NGINX Documentation
And without nginx? Just using Meteor? Is there a way to save files and retrieve them?
You can use Meteor to serve static content through the Webapp package
As of version Meteor 2.x, the webapp package is using connect: connect - npm
You will need this middleware to serve static files: serve-static - npm
You can write file but not in the public folder as @rjdavid said.
You can create 2 meteor settings files, one for dev and other for prod. In meteor settings, you can set property, for example
USER_DIRECTORY: "/home/somewhere/data", make sure meteor process has write permission.
After that, you can write/read files from those directories without any problem.