O'Reilly logo

Node Cookbook Second Edition by David Mark Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making stream interfaces

The Consuming streams and Playing with pipes recipes show us how to initiate and interact with various stream interfaces, such as the fs module's read and write streams, the http module's response object's write stream, and third-party modules, such as JSONStream (refer to the There's More… section of Playing with pipes).

In this recipe, we're going to make our own basic read and write stream interfaces.

Getting ready

Let's create and open a file, which we'll name basic_streams.js.

How to do it…

Node's stream module contains some base constructors to create streams. So, let's require the stream module and instantiate a readable stream as well as a writable stream:

var stream = require('stream'); var writable = new stream.Writable(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required