简体   繁体   中英

How to mantain files in Heroku that are not in git repo after a deploy

This is the scenario: my Node.js app creates a file on the server that stores all user data (nothing sensitive) in a file called database.json .

I currently have two environments:

  • my local machine, with a database.json ,
  • and my production environment on Heroku, with its own database.json

Every time I push a new version of my app, from my machine to production, I would not like to replace the production database.json file with the one I have in my machine. For that, I used the .gitignore to ignore this file, so this file is not on GitHub, because it is created within the app execution

But every time I push a new version to Heroku, instead of keeping the old database.json file, Heroku erases it. It looks like Heroku completely overwrites all the app folder with the one downloaded from Git instead of "merging" with what is already there.

How can I set up a file on Heroku that I can use to save user data that is not affected by git push es and deploys?

How can I set up a file on Heroku that I can use to save user data that is not affected by git push es and deploys?

You can't.

Furthermore, this isn't just about deploys: your file will be lost at other times too.

Your file isn't being overwritten by Git ; Heroku's filesystem is ephemeral . Any changes made to it will be lost any time the dyno restarts. This happens frequently (at least once per day) whether you deploy or not.

You will need to change how you're persisting data. I suggest using a real client-server database , but you could also save your file in third-party object storage using something like Amazon S3 or Azure Blob Storage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM