Building stream pipelines
The Node.js core stream
module provides a pipeline()
method. Similar to how we can use the Node.js core stream pipe()
method to pipe one stream to another, we can also use the pipeline()
method to chain multiple streams together.
Unlike the pipe()
method, the pipeline()
method also forwards errors, making it easier to handle errors in the stream flow.
This recipe builds upon many of the stream concepts covered by the other recipes in this chapter. We'll create a stream pipeline using the pipeline()
method.
Getting ready
- First, create a directory to work in named
stream-pipelines
:$ mkdir stream-pipelines $ cd stream-pipelines
- Create a file named
pipeline.js
:$ touch pipeline.js
- We'll also need some sample data to transform. Create a file named
file.txt
:$ touch file.txt
- Add some dummy text data to the
file.txt
file:Node.js is a JavaScript runtime built on Google Chrome's V8 JavaScript engine. Node.js is a JavaScript...