First of all, I've found similar questions but nothing quite matching my use case:
I have a file such as:
line1prop1 line1prop2 line1prop3
line2prop1 line2prop2 line2prop3
line3prop1 line3prop2 line3prop3
...
I want to read the file line by line, execute a function for each line BUT wait for the function to finish before moving to the next line
This is because for each line I have to extract the properties and make a request to Elasticsearch, to see if I have a matching document or not, but my cluster gets flooded with requests because I currently read everything asynchronously.
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('file.in')
});
lineReader.on('line', function (line) {
//EXECUTE FUNCTION HERE AND WAIT FOR IT TO FINISH
});
Any help is greatly appreciated!