How to exclude from delete folder during heroku deploy? - node.js

I deployed app on heroku which can save files with database record. Problem is, when i deploy again some changes, folder with files is new without files which were there before deploy (rows in database stay of course). How can resolve this? I want to folder "files" in root app folder stay this same during all future deploys on Heroku.
App - nodejs + express + react + postgresl

This is not possible, Heroku provides an ephemeral file system which is wiped out after each deployment.
You need to persist data in a database (MongoDB Atlas, Heroku Postgres addon) or use an external file storage (AWS S3, Dropbox).
Check out Files on Heroku to see some options and examples.

Related

storing csv files on a dedicated server

I'm having trouble storing csv files on a heroku server. I have a javascript application running express and a few other node packages and wondering what I should do in order to maintain those csv files. Heroku will always wipe new data and revert to the last deployed code (https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted), so any new files added while the app is running will be erased. Wondering if I should look for another dedicated service to deploy the project on or store the data in a database.

how to save uploaded file on elastic beanstalk?

I use a elastic-beanstalk service on AWS by using Node.js.
I use a multer for file upload and uploaded file is saved on webserver.
But when I publish a new version of project file, the files that saved on my webserver are gone.
I want to maintain the file on webserver.
just overwrite not rewrite.
so how can I solve this issue?
Thanks for your time!
When working with Elastic Beanstalk (or any auto-scaling environment), ideally you don't want to store anything on the server itself. If a user is uploading a file, save it somewhere off the server.
In AWS, this typically means storing it in S3 - this means that the file doesn't get lost when the project is updated or the server gets terminated.

Uploaded Image Disappeard When Heroku Server Restart

I am using node.js to upload files to my Heroku server. Everything works fine, but when the Heroku server restarts or goes down all the uploaded files disappears, the URL hits returns 'Not Found'.
Experienced this months ago. You need to host the images somewhere else as Heroku does not support storing files in them. Ended up using Cloudinary to store files, and then later on getting a VPS server.
Media files and other user content that is uploaded by users should not be stored on Heroku. Heroku was built to run the application code and it only cares about the files of your application that are in your repository.
Heroku discards your previous environment on every deploy, and launches a new one based on your code repository.
So only application code should stay there, other things should be delegated to other services, in this case for file storage you should use something like S3 or similar.
Heroku has something called Ephemeral filesystem.
From the documentation:
Each dyno gets its own ephemeral filesystem, with a fresh copy of the
most recently deployed code. During the dyno’s lifetime its running
processes can use the filesystem as a temporary scratchpad, but no
files that are written are visible to processes in any other dyno and
any files written will be discarded the moment the dyno is stopped or
restarted.

Save image file to IBM Bluemix Node.js application

I have a Node.js application on IBM Bluemix.
I need to let the user upload a image. In my localhost, the image is save into the folder, no problems...
But when I do the same in production, the file isn't save to the server corresponding folder...
Someone can help?
Assuming this is a Cloud Foundry app ... the file system is ephemeral, you need to save the images somewhere external to the app for them to be persisted through app restarts.
There is a sample app that shows how to do this using Cloudant - https://github.com/IBM-Bluemix/nodejs-cloudant
You will need to specify the directory using __dirname , but every time you redeploy your application you will lose the files. Stoping and Restarting should be ok.

heroku retain files/folders while re-deploying new version of nodejs application to heroku

My folder structure for images looks like below
./public/img/**
under img folder I have following folders - categoryImages, languageImages, socialShareImages and userImages.
Now I want to retain the userImages as this contains images uploaded by user, But every time I deploy a new version of my app to heroku with "git push heroku master" it overwrites userImages folder.
I tried without userImages folder in my git repository but even this doesnt help. Looks like everytime you upload a new version of app every folder and file is rewritten. Now question is how can I retain this userImages folder?
Regards,
Chidan
Heroku has a ephemeral filesystem and as far as I know, (and as much as I wish it weren't) I don't think you can get any files to persist.
However, heroku offers a free Postgres database per app, and anything in your database will persist. You'll have to use the node.js pg package to access Postgres.
Edit: I believe it's also possible to use S3 (which might work better for something like images). You'll have to look that up though.

Resources