Reputation: 37
I have this code to store the file on the server and after sending the file to the user, delete it.
var fileName=`invoice_${Date.now().toString()}.pdf`
await fs.writeFileSync(path.join(__dirname,'invoices',fileName), result.pdf, 'base64');
var filePath=path.join(__dirname,'invoices',fileName)
console.log(filePath)
res.download(filePath,"invoice.pdf",function(){
fs.unlinkSync(filePath)
});
here is my file structure:
Error in heroku log:
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/app/routes/invoices/invoice_1609956681064.pdf'
Upvotes: 1
Views: 498
Reputation: 37
I have sorted out my issue, initially, my invoice folder was empty and git did not push empty folders on the repository so I have added a dummy file in my invoice folder, and it worked.
Upvotes: 2