I am having difficulty with using fs.creadReadStream
to process my csv file asynchronously:
async function processData(row) {
// perform some asynchronous function
await someAsynchronousFunction();
}
fs.createReadStream('/file')
.pipe(parse({
delimiter: ',',
columns: true
})).on('data', async (row) => {
await processData(row);
}).on('end', () => {
console.log('done processing!')
})
I want to perform some asynchronous function after reading each record one by one before the createReadStream
reaches on('end')
.
However, the on('end')
gets hit before all of my data finishes processing. Does anyone know what I might be doing wrong?
Thanks in advance!