I wrote the following code:
var csv = require('csv-parser')
var fs = require('fs')
var devices = []
fs.createReadStream('devices.csv')
.pipe(csv())
.on('data', function (data) {
devices.push(data)
});
console.log(devices)
The line devices.push(data) insert each line in csv file into the global array 'devices'. Unfortunatelty, when I reach the last line in my code (outside the callback), I see that devices is again empty array. Why does it happen, and how can I make it work as I want?