Using the Stream Module to Stream Data

An important module in Node.js is the Stream module. Data streams are memory structures that are readable, writable, or both. Streams are used all over in Node.js, when accessing files, when reading data from HTTP requests, and in several other areas. This section covers using the Stream module to create streams as well as to read and write data from them.

The purpose of streams is to provide a common mechanism to transfer data from one location to another. They also expose events such as data when data is available to be read, error when an error occurs, and so forth so that you can register listeners to handle the data when it becomes available in a stream or is ready to be written to.

Streams are commonly used for HTTP data and files. You can open a file as a readable stream or access the data from an HTTP request as a readable stream and read bytes out as needed. In addition, you can create your own custom streams. The following sections describe the processes of creating and using Readable, Writable, Duplex, and Transform streams.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.243.4