How to let users download a file with data stored in an array (CSV/Node.js)? -
how allow users download array has stored list of objects csv without using express or additional libraries?
this have tried not sure stick infront of res.setheader - , want try prompt user if want download it.
var filename = 'music' + new date() + '.csv'; res.setheader('content-disposition', 'attachment; filename=' + filename);
you can use http package bundled nodejs
var http = require('http'); var options = { host: 'localhost', port: 80, path: '/download', method: 'post' }; var req = http.request(options, function(res) { res.setheader('content-type', 'text/csv'); res.setheader('content-disposition', 'attachment;filename=' + filename); }); req.on('error', function(e) { console.log('problem request: ' + e.message); }); // write data request body req.write('data\n'); req.end();
Comments
Post a Comment