I'm trying to read a file line by line using this:
function makeList() {
let lines = [];
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('titles.txt')
});
lineReader.on('line', function(line) {
//console.log(typeof line)
lines.push(line);
//console.log(lines)
});
return lines;
}
When enabling the comments I can see that the lines are read and are strings.
But when calling the function I always get an empty list:
async function run() {
var p = makeList();
console.log(p);
for (line of lines) {
console.log("Elaborando: " + line)
for (let i = 1; i <= 18; i++) {
if (!processString(line)) {
fs.mkdirSync(processString(line));
}
await sleep(5000);
//getImage(line, i, line);
}
}
}
run()
printing p
to console gives an empty list.
I'm not familiar with JavaScript, what am I doing wrong?