Warm tip: This article is reproduced from serverfault.com, please click

Save file change on heroku

发布于 2016-12-22 19:47:38

I hava a node.js app on heroku thath checks for emails and then if the email match certian cliteria it would reply.

Because heroku restarts the dyno every so often I made a file that saves the ids of the emails (a small array) I've already cheaked (so it doesn't reply twice to the same email), but silly me, heroku restarts that file too, so no changes I made will be save.

Is there a way to save the file changes the app makes to it? If you know of a better way of to do what I want to?

Questioner
Cosmeoes
Viewed
0
rdegges 2016-12-30 01:45:04

Heroku enforces this behavior (the local file deletion stuff) because it is a best practice. Writing files locally doesn't scale well, and can lead to some odd edge-case behaviors when you have multiple processes on the same VM all performing file I/O operations.

What you should use instead is either a database, a cache (like Redis), or even just write your file directly to a file storage service like Amazon S3.

I realize it sounds annoying that you have to do these extra things even for a simple use case like what you're doing here -- but Heroku's platform is geared around enforcing best practices to help people build scalable, reliable software.

If you're looking for a way to do stuff like this without the extra hassle, you might want to consider just purchasing a small VPS server from another company where you can have direct control over processes, disk, etc.