How to download heroku running file? - node.js

Is there any possibility to download running app file?
Im using quick.db for my discord bot database and I need that running json database file with user data before restarting. When I will deploy a new build, then the old json database file from github will load and I will lose all new data in that database.
Thx for anything...

You can programmatically upload the json file to remote storage (S3, DropBox): you can do this at restart (if you can intercept the event) or at regular times (this might not work for you, it depends how often the db is updated).
You can read about some possible options on Heroku Files
The download option is not a good idea because you need to secure the download endpoint (I believe you don't want anybody be able to grab your data) and also because the Dyno restarts at least every 24hrs (if you don't deploy for a day the Dyno will restart without notice and giving the time to download your data).

Related

Remotely upload a file to Wordpress from nodejs instance

I’m running a node app on Heroku. It gathers a chunk of data and sticks it into a set of JSON files. I want to POST this data to my Wordpress server (right now it’s on siteground, but moving to WP Engine).
I thought the WordPress REST API would provide what I wanted but after reading the docs I’m not not so sure.
Does anyone have any advice on this? It’s not the kind of thing I’ve done before.
Naturally, I could download the generated files and manually upload them in the right place… but I want it to be automated!
Can anyone point me in the right direction?
Looked at WordPress REST API but don’t think that’s the answer.
An option would be to setup a cron job on your Wordpress site to download the already made JSON files. This would let you download the files via http if they're publicly available, or using an api-key, or SFTP even.
You could also go the opposite way and setup a cron job on the server running your node app and use SFTP to deliver the updated files onto your Wordpress site.
If you are really committed to wanting to use the wordpress rest api, I think the closest one that comes to my mind (not an expert in wordpress) would be that you'd upload the json files as media objects: https://developer.wordpress.org/rest-api/reference/media/.

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.

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