This is my "app.js" file.
const { convertArrayToCSV } = require('convert-array-to-csv');
const converter = require('convert-array-to-csv');
const fs = require('fs')
const csv = require('csv-parser')
const randomWords = require('random-words')
const header = ['number', 'first', 'last', 'handle'];
const dataArrays = [
[1, 'Mark', 'Otto', '@mdo'],
[2, 'Jacob', 'Thornton', '@fat'],
[3, 'Larry', 'the Bird', '@twitter'],
];
const val = convertArrayToCSV(dataArrays, {
header,
separator: ','
});
console.log(val)
output:
number,first,last,handle
1,Mark,Otto,@mdo
2,Jacob,Thornton,@fat
3,Larry,the Bird,@twitter
I want to save this "Val" as a .csv file on my device. How can I do that? Please help. I am stuck here for the last 4 hours.
/home/newcsvfile.csv~/newcsvfile.csv