I'm very novice in node.js and don't understand the documentation about streams. Hoping to get some tips.
I'm reading a very large file line, and then for each line I'm calling an async network api.
Obviously the local file is read much faster than the async calls are completed:
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream(program.input)
});
lineReader.on('line', function (line) {
client.execute(query, [line], function(err, result) {
// needs to pressure the line reader here
var myJSON = JSON.stringify(result);
console.log("line=%s json=%s",myJSON);
});
});
What is the way to add back pressure in the "execute" method?