Node JS Streams: Understanding data concatenation
Node JS Streams: Understanding data concatenation One of the first things you learn when you look at node's http module is this pattern for concatenating all of the data events coming from the request read stream: let body = ; request.on('data', chunk => { body.push(chunk); }).on('end', () => { body = Buffer.concat(body).toString(); }); However, if you look at a lot of streaming library implementations they seem to gloss over this entirely. Also, when I inspect the request.on('data',...) event it almost ever only emits once for a typical JSON payload with a few to a dozen properties. request.on('data',...) You can do things with the request stream like pipe it through some transforms in object mode and through to some other read streams. It looks like this concatenating pattern is never needed. Is this because the request stream in handling POST and PUT bodies pretty much only ever emits one data event which is because their payload is way...
