I am using fs.createReadStream
to read CSV data and it is exhibiting some weird behaviour. I'm very confused as to why this is happening.
I have the following code:
const result = []
fs.createReadStream("path")
.pipe(csv()) //csv parser
.on("data", data => result.push(data))
.on("close", () => console.log(results)) // Showing results correctly here, 5000 rows
console.log(results) // Showing an empty array here []
I don't understand why the results array is going back to empty after the data was added correctly on close.