node.js - Redirect after download file - Nodejs -


i'm trying redirect page after downloading file. code:

app.get('/log', function(req,res){      return res.download('file.txt', function(err){             if(!err){                 return res.render('index.html');             }         }); }) 

but every time error: error: can't set headers after sent.

there way redirect/render after downloading? (at server-side, please).

you can't in way think headers sent download response.

you can accomplish manipulating response send required headers file download , send location header along with. requester should understand location header , redirect accordingly.

for eg.

const filedata = /* read file */; res.set({   'content-type': 'text/plain',   'location': '/' }); res.end(filedata); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -