This was marked as a duplicate question because there is possibly an async issue with it, but I've tried adding a promise to it and it didn't help. If it is an ansync problem, can someone explain it to me?
I'm working on a project where I need to analyze and manipulate data in a txt file using. I'm using Readline to loop through each line of the txt file and I'm able to manipulate the data like I want to. My issue is that I can't return the data, I can only console.log() it. If I return it I get a message that the return contains 'invalid characters'. Is there a way to get around this? Thanks!
const rl = readline.createInterface({
  input: fs.createReadStream(input_file_path)
})
let arrofData = [];
rl.on('line', (line) => {
  line = JSON.parse(line);
  arrofData.push(line.user, line.action, line.timestamp);
})    
rl.on('close', () => {
  let bots = [];
   for (let i = 0; i < arrofData.length; i++) {
   let counter = i;
   let dataToCheck = [];
   while (dataToCheck.length < 20) {
     dataToCheck.push(arrofData[counter]);
     counter++;
   }
   if (!dataToCheck.length - 1) {
     return bots;
   }
   let time = dataToCheck[dataToCheck.length - 1][2] - dataToCheck[0][2];
  if (time <= 480) {
    let filterForSameUser = dataToCheck.filter((username) => username[0] !== dataToCheck[0][0]);
    if (filterForSameUser.length === 0) {
      if (!bots.includes(dataToCheck[0][0])) {
        bots.push(dataToCheck[0][0]);
      }
    }
  }
}
console.log(bots);
return bots;
})
