So it's really quite simple but I can't seem to get it to work. I'm trying to pull in a csv file , turn the rows to objects, then push to objects to an array then do stuff with the array. Everytime I try to run it, it wont await the filestream or let me read the modified reports array.
const csv = require('csv-parser');
const fs = require('fs');
const reports = [];
async function readTable(){
fs.createReadStream('pull.csv')
.pipe(csv())
.on('data', (row) => {
//console.log(row);
reports.push(row)
})
.on('end', () => {
console.log('got all the csv data')
return
});
}
async function getData(){
await readTable()
console.log(reports)
}
readTable();