Piping Patterns: Forking Streams
Learn how to fork streams using piping patterns.
We'll cover the following
We can perform a fork of a stream by piping a single Readable
stream into multiple Writable
streams. This is useful when we want to send the same data to different destinations; for example, two different sockets or two different files. It can also be used when we want to perform different transformations on the same data, or when we want to split the data based on some criteria. If you’re familiar with the Unix command tee
this is exactly the same concept applied to Node.js streams.
The illustration given below gives us a graphical representation of this pattern.
Get hands-on with 1400+ tech skills courses.