July 2017
Intermediate to advanced
656 pages
16h 1m
English
The pipe method attaches a data event listener to the source stream (the stream on which pipe is called), which writes incoming data to the destination stream (the stream that was passed into pipe).
When we string several streams together with the pipe method, we're essentially instructing Node to shuffle data through those streams.
Using pipe is safer than using data events and then writing to another stream directly, because it also handles backpressure for free. Backpressure has to be applied to source streams that process data faster than destination streams, so that the destination stream's memory doesn't grow out of control due to a data backlog.