Reading streams via Async/Await in node pre Node.js 10
by: Peter Shoukry

Node.js 10 introduced experimental support for asyncornously iterating over readable streams. If you are working with Node.js 10 then please read more about it [here]( If however you are using an earlier version handling streams with async/await can be a bit tricky. One of the nice solutions is to block execution via a promise that resolves on the completion of the stream read. A quick demo of the technique is as follows: ```javascript let recordsStream = myReadStream() /** block execution until we process the stream */ let records = await new Promise(function(resolve, reject) { let records = [] recordsStream.on(‘data’, function (record) { // Process one record from the stream records.push(record) }) .on(‘end’, function() { // Resolve the promise to continue execution when the // stream finishes. resolve(records) }) }) /** process all the records in the stream */ ```