I am building an app using node.js and trying to download data as a csv file. I am using json2csv (https://www.npmjs.com/package/json2csv) for this purpose. However, the way I h
Use res.send if you use express.
You have to define a HTTP GET route which looks something like that:
app.get("/pathToYourDownload", function (req, res) {
json2csv({ data: myCars, fields: fields }, function(err, csv) {
res.setHeader('Content-disposition', 'attachment; filename=data.csv');
res.set('Content-Type', 'text/csv');
res.status(200).send(csv);
});
});