0

 const path = require('path')
const fs = require('fs');

 const filePath1 = path.join
(
__dirname,
 "..",
 "public",
"exports",
"csv-"+ req.user.ecode + " history"  + ".csv"
)
  fs.writeFile(filePath1,csv,function(err){
            if(err){
              console.log('fs writeFile error:' + err)
              return res.status(500).json({ err })
            }else{
              setTimeout(function()
             {
             fs.unlinkSync(filePath1)
             },40000)
             res.download(filePath1, function(err){
                console.log(err);                     
              })
            }
          })

am getting the following output in my console with csv and error as follows.. Date :,Feb-14-2020 Strategy,Corporate Goal,Project Name,Weightage,Responsibility,Target Date Financial,EBIDTA@582%= 46.77cr INR,Project A,10,EM00875,Jul-25-2020 Financial,EBIDTA@582%= 46.77cr INR,Project C,90,EM00875,Feb-16-2020

Error: Request aborted
    at onaborted (E:\KRA_5\abc_5_final - Copy\node_modules\express\lib\response.js:1025:15)
    at Immediate._onImmediate (E:\KRA_5\abc_5_final - Copy\node_modules\express\lib\response.js:1067:9)
    at processImmediate (internal/timers.js:439:21) {
  code: 'ECONNABORTED'
}
hoangdv
  • 15,138
  • 4
  • 27
  • 48
  • Please refer https://stackoverflow.com/questions/50995471/why-is-express-res-download-method-causing-a-request-aborted-error Also do check request headers – Sakshi Nagpal Feb 17 '20 at 06:13

1 Answers1

0

Download your file using Express.js instead of Node.js. How to download a file using Express in Node.js

Hopefully the problem will be fixed. Let me know.

Besides, you can check the following links to have more clear idea that can be helpful related to your problem.

Rashed Rahat
  • 2,357
  • 2
  • 18
  • 38