I am having difficulty creating an array entry out of each line of a text file in node.js
My array is called "temp." I am able to console.log each line in the following code:
var temp = [];
const readline = require('readline');
const fs = require('fs');
let rl = readline.createInterface({
input: fs.createReadStream('./lib/Sphinx.txt')
});
let line_no = 0;
rl.on('line', function(line) {
line_no++;
console.log(line); //this successfully prints out every line
temp.push(line); //this would ideally create a new array entry for each line
});
However, when I run this code:
console.log(temp.size)
//returns empty
Help is appreciated. Thanks, Nakul