Using express.js you can force a file download by setting the appropriate http headers and content type.
This example forces a .csv file download.
| app.get('/csv', (req, res) => { | |
| let data = "name,age,status\nderek,30,online\nsarah,28,offline\nDan,36,online" | |
| let filename = 'cool.csv' | |
| res.setHeader('Content-disposition', `attachment; filename=${filename}`) | |
| res.set('Content-Type', 'text/csv') | |
| res.send(data) | |
| }) |