How to modify/write a file into public folder after building


As I understand all files and directories in public/ gets moved to …/web.browser/app/ (relative to the main entry) after building.
I noticed that all the files there have only read permissions, even if they originally had 666 (read/write) in public/

How can I keep the permission of the files there? Is that not recommended?

My use-case is that I want to append to a log file and be able to reach it normally as localhost/log.txt
Is it more recommended to never use this and instead save the file somewhere else (like tmp) and then serve it by setting a route handler for it for example?

Using Meteor 1.6 and React 15.4

The public/ folder is intended to be used for read-only assets. Check the Meteor Guide for more information.

That’s only building for development. It’s not building for production.

It’s generally recommended to not use local file storage at all, because:

  • If you use a deployment service which is container or instance based (Meteor, AWS, etc), that storage is completely volatile. It will be re-created from the build image when a new instance is started, but anything you’ve changed in there will be lost.
  • If you use local storage, what will you do if you need to scale-out? Clients could connect to an instance which doesn’t have the changes.

The usual recommendation is to use a storage service, such as S3.

1 Like

Yes. And if you don’t want to bring 3rd party services into the mix needlessly (not everyone wants to build a Facebook-style empire of servers) you can use this solution which works just fine for my needs:

1 Like

Absolutely: nginx does a much better job of serving static assets than nodejs. However, even with a small application on a single Galaxy instance, you will lose changes to local files if you do an update.

If you’re running your own server, you can do whatever works for you. It’s just that there are pitfalls with local storage which I felt it important to highlight.

1 Like

Thanks @robfallows @rhywden for your replies!
Losing the log file doesn’t really matter for me as it’s just to log problems in the current build / docker image.
Another aspect I forgot to mention is that the file will be edited during runtime as we keep appending to the logs every X minutes. Would that be a problem? Must the file be non-changing?

I’ll try what you said and reply with the results! :smile:

If you’re using Docker and you want to keep changes to files regardless of what happens to the container, you should investigate Docker Volumes, which permit the decoupling of persistent storage outside of the container.

1 Like