I am making a server with express to store some files,the site was deployed to heroku.And I found that the file saved on the server will disappear in a few hours.How can I fix that????
Using Packages: express express-fileupload
simple code:
main.js
app.post('/fileupload',(req,res)=>{
if (!req.files) {
return res.status(400).send("No files were uploaded.");
}
const file = req.files.myFile;
const path = __dirname + "/files/" + file.name;
file.mv(path, (err) => {
if (err) {
return res.status(500).send(err);
}
return res.send({ status: "success", path: path });
});
})
terminal command(how i publish the server)
$ cd myproject
$ git add .
$ git commit -m "make it better"
$ git push heroku master
I know that I can use tools like S3,but the storage is limited,any free ways like installing npm packages or editing Heroku settings can solve this?
As far as I know, Heroku does not have persistent storage, meaning if your dynos (server) restart, or go to sleep, then all files are gone. You should save your files somewhere else and retrieve them from the heroku server, for example S3