From the course: Advanced Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Readable streams

Readable streams - Node.js Tutorial

From the course: Advanced Node.js

Start my 1-month free trial

Readable streams

- [Instructor] In the last lesson we discovered why streams are important. In the next several lessons we're going to take a look at the various types of streams that you can use with nodejs. We're going to start with readable streams. Now, a readable stream reads data from a source and then feeds it into a pipeline bit by bit. For instance, we can create a readable stream that can read from a source array. I'm inside of chapter two, chapter two lesson one, inside of the start folder, and in your index.js file you'll find a sample array of strings. These are local mountain peaks here in the Sierra. So what we're gonna do is we're gonna create a particular type of stream that can read the data from the array and then pass it along chunk by chunk. So, let's see what that would look like. I'm gonna go ahead and create a new instance of our peak stream, and we're gonna use the new StreamFromArray class, and we'll pass it the peaks. Now streams implement the event emitter, which means they…

Contents