const fs = require('fs')
const readline = require('readline')
const stream = require('stream')
const rl = readline.createInterface({
input: fs.createReadStream('logs_out.txt')
})
var items = new Set()
// ASYNC FUNCTION READING LINE BY LINE
rl.on('line', function(line) {
let log = JSON.parse(line)
// ADDING ITEMS TO A SET TO GET UNIQUE ITEMS COUNT
items.add(log.resource)
})
// PRINTING OUT THE SIZE OF THE SET
console.log(items.size)
Now the issue is, when I do this I always get undefined or 0 for the size of the set because the console.log(items.size)
is executed even before all the line
functions are executed.
How to fix this.
Thank You.