I am trying to store data from a csv file in an array using createReadStream in node.js but for some reason the array stays empty and no data is stored in it. When i console log the values where i'am trying to push the data it logs it just fine. I've tried both csv-parser and csv-parse for this but none of them seem to work.
const fs = require("fs");
const csv = require('csv-parser');
function parseCSV () {
let finaldata = []
fs.createReadStream('data.csv')
.pipe(csv())
.on('data', function (row){
finaldata.push({Userid: row[0], Timestamp: row[1]})
}).on('end', function(){
console.log(finaldata)
})
}
parseCSV()