I want to put the content of a file in an array. But when I try to access the variable fileArray
it is empty after lineReader.on
. This the code:
var fileArray=[]
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('file-to-read')
});
lineReader.on('line', function (line) {
fileArray.push(line)
//console.log(fileArray)
});
// I want to get the array here but it is currently empty
console.log(fileArray)
Thanks