I have the next piece of code. It's a function that has to return an array based on a txt file. The problem is when I print piece by piece the array, it prints well. But when I print the array out of the Interface, the array is empty.
const fs = require('fs');
const readline = require('readline');
function read_file(filename) {
const filePath = './uploads/' + filename;
var data = []
data = readline.createInterface({
input: fs.createReadStream(filePath),
terminal: false
}).on('line', function (
data.push(line);
console.log(data); // Here the array is filling well
});
console.log(data); // Buy here is empty again
}