-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
35 lines (32 loc) · 783 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
let converter = require('json-2-csv');
let documents = [
{
Make: 'Nissan',
Model: 'Murano',
Year: '2013',
Specifications: {
Mileage: '7106',
Trim: 'S AWD'
}
},
{
Make: 'BMW',
Model: 'X5',
Year: '2014',
Specifications: {
Mileage: '3287',
Trim: 'M'
}
}
];
let json2csvCallback = function (err, csv) {
if (err) throw err;
console.log(csv);
fs.writeFileSync("./converted/" + form.filename + Date.now() + ".csv", csv, 'binary', (err) => {
if (err) {
console.log("writeFileSync :", err);
}
console.log( filename+" file is saved!");
});
};
converter.json2csv(documents, json2csvCallback);