Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140854

How to create an array entry for each line of a text file using node.js

$
0
0

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


Viewing all articles
Browse latest Browse all 140854

Latest Images

Trending Articles



Latest Images