I am planning on allowing users to download a json file that is stored in MySQL Database. Since I am using Express.js, I would like to utilize the download method to initialize a download for the end user.
Something like
const { Item } = require('models');
app.get('/download', (req,res) => {
Item.find().then(result => {
res.download(result.file)
}
)}
);
However, looking at the documentation for download and it requires a filepath for the file to download. I do not want to write this file to my server and am only looking to send the file to download for the user.
If all else fails, I will consider just using fs to write the file to the server then delete it once the download is complete as shown here.
Is there a way to directly read the file in the database and send it to client?