Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js createWriteStream doesn't create new file on Heroku

I have following code that works fine on my localhost running node.js 0.12.0. The code creates a new file, and copy data from readable, but it doesn't create new file on Heroku.

var output = fs.createWriteStream('public/images/test/testfile.png');
readable.pipe(output);

I thought it has something to do with the permission, but whenever I change the permission on the folder using heroku run bash and then chmod -R 777 images/ Heroku resets it back to its original permission which is drwx------.

So may be the problem is something else?

Please note that it fails silently, no exception, nothing in the log.

like image 489
ZoM Avatar asked Oct 18 '25 13:10

ZoM


1 Answers

In Heroku a dyno's local file storage is not persistent (besides the git repo files obviously), so if you write a local file and the dyno restarts the file will be gone, and if you start another dyno it won't be able to "see" the file.

heroku run bash starts a new "one-off" dyno (can read about it here: https://devcenter.heroku.com/articles/one-off-dynos), so the file will not be accessible that way.

If you want your data to persist, better use some database or persistent storage addon.

like image 177
florpor Avatar answered Oct 21 '25 03:10

florpor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!