I am parsing a huge csv (1.2GB) using csvparser and trying to obtain certain column data from the parsed csv. I am trying to push the data to the array after processing, but only getting empty array as output. How can I fix this code?
var parse = require('csv-parse');
var output = []
var parser = parse({
delimiter: '\t',
columns: true
}, function(err, csvLine) {
for (var l = 0; l < csvLine.length; l++) {
output.push(csvLine[l].id)
}
});
console.log(output)
fs.createReadStream('file.csv', {
encoding: 'utf8'
}).pipe(parser);
The output at console.log(output) is always an empty array. Please help me solve this.
I tried to understand the post here - Save csv-parse output to a variable. But I was not able to understand and fix the code.
console.log(output)inside thefunction(err, csvLine){}right after theforloop