I have a Node JS API currently hosted on Heroku free tier and I am using Postgres Database and used Heroku's free Dyno. I recently added multer to store images but I guess Heroku doesn't allow that in its free tier, so I am hoping is there any way I can store the images on shared hosting? I have like 20GB of SSD space there. Can I route my images and store the path of the images on my database? I tried to search a lot on the internet but couldn't find anything about it.
CodePudding user response:
First of all great question.
You're correct Heroku's free tier doesn't save local files, because apps hosted on free tier sleep, that means that the server stops running after inactivity, after that happens the next time the app is visited it restarts the server from scratch, it refers to the latest git commit or version which doesn't include the images.
Anyways you're gonna need a storage service for your files or images.
I would recommend using cloudinary https://cloudinary.com/
Cloudinary offers you a free tier, no credit card needed and 25gb of storage for files. You can check out the docs there for uploading and managing your files or you could research tutorials. You could also use the package multer-storage-cloudinary
to make it a bit easier to upload files but you could always use the original approach seen on the docs.
I would suggest checking out AWS s3(simple storage service) as well https://aws.amazon.com/s3/ However, this will require your credit card info to signup there is a free tier which lasts for a year I think.
I hope this helped, have a good day!