Reputation: 23
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:
database.json
,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?
Upvotes: 2
Views: 463
Reputation: 136918
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.
Upvotes: 2