Novapex
Novapex

Reputation: 37

how to solve path error on heroku, no such file or directory open

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:

enter image description here

Error in heroku log:

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/app/routes/invoices/invoice_1609956681064.pdf'

Upvotes: 1

Views: 498

Answers (1)

Novapex
Novapex

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

Related Questions