I have created a script (block 1) and it fails to import anythign into my array. if i take the code and execute it line by line (block 2) in command line node it works fine
Block 1:
var fs = require('fs');
var readline = require('readline');
var filename = process.argv[2];//filename
var content = [];
console.log(filename);
readline.createInterface({
input: fs.createReadStream(filename),
terminal: false
}).on('line', function (line) {
content.push(line);
});
console.log(content.length);
Block 2: (each line entered sequentially)
fs = require('fs');
readline = require('readline');
filename = "filename.txt";
content = [];
readline.createInterface({
input: fs.createReadStream(filename),
terminal: false
}).on('line', function (line) {
content.push(line);
});
content;
the console.log(filename)
in Block 1 prints out the correct name, but the console.log(content.length)
prints "0", where as in the node REPL content has upwards of 1700 entries.
I am using node v6.9.4 in a linux environment, and executing both blocks on the same computer. am I missing something obvious here?
thanks