VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-stream-readable-pipe-method/

⇱ Node.js Stream readable.pipe() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js Stream readable.pipe() Method

Last Updated : 12 Jul, 2025

The readable.pipe() method in a Readable Stream is used to attach a Writable stream to the readable stream so that it consequently switches into flowing mode and then pushes all the data that it has to the attached Writable. 

Syntax:

readable.pipe( destination, options )

Parameters: This method accepts two parameters as mentioned above and described below:

  • destination: This parameter holds the destination of writing data.
  • options: This parameter holds the pipe options.

Return Value: It returns the stream.Writable destination, allowing for a chain of pipes if it is a Duplex or a Transform stream.

readable.pipe in node helps to enable the data transfer between streams by connecting the readable and writable streams.

Explore this Node.js Streams Module Complete Reference for detailed insights, practical examples, and expert guidance on handling data streams efficiently, from reading and writing to transforming and piping, to enhance your Node.js applications.

The below examples illustrate the use of readable.pipe() method in Node.js: 

Example 1: This example demonstrates the use of readable.pipe method to transfer data from input.text to output.text.

Output:

Program Ended

So, after the piping method the file named "output.text" must contain the data that was in the file "input.text". 

Example 2: This example demonstrates using readable.pipe method to compress the input file data to input.text.gz

Output:

File Compressed.

Reference:https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options.

Comment

Explore