Rotciv Ocnarb
Rotciv Ocnarb

Reputation: 23

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:

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 pushes and deploys?

Upvotes: 2

Views: 463

Answers (1)

Chris
Chris

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 pushes 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

Related Questions