var json2csv = require('json2csv');
json2csv({data: someJSONData, fields: ['screen_name', 'statuses_count', 'location']}, function(err,csv) {
if (err) console.log(err);
console.log(csv);
});
var json = [
{
"screen_name: "Doug_E_Stile"",
"statuses_count": 1546,
"location": "Maryland""
}, {
"screen_name": "cthxidm",,
"statuses_count": 339,
"location": "peru manyas¿",
}, {
"screen_name": ""jiiiiimarjoh",
"statuses_count": 4205,,
"location": "South Cotabato, Philippines"
}
];
json2csv({data: json, fields: ['screen_name', 'statuses_count', 'location']}, function(err, excel) {
if (err) console.log(err);
fs.writeFile('file.csv', csv, function(err) {
if (err) throw err;
console.log('file saved');
});
});
Looks like you are using a variable named csv, but the name of your function parameter is excel. It should be:
fs.writeFile('file.csv', excel, function(err) {
instead of
fs.writeFile('file.csv', csv, function(err) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With