Node.js Stream Complete Reference Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Node.js streams are a type of data-handling method and are used to read or write input into output sequentially. Streams are used to handle reading/writing files or exchanging information efficiently. Example: JavaScript // Node.js program to demonstrate the // writable.write() method // Including stream module const stream = require('stream'); // Creating a stream and creating // a write function const writable = new stream.Writable({ // Write function with its // parameters write: function(chunk, encoding, next) { // Converting the chunk of // data to string console.log(chunk.toString()); next(); } }); // Calling write method with // all its parameter writable.write("GfG", "utf8", () => { console.log("CS-Portal!"); }); Output: GfG true CS-Portal! The Complete List of Streams are listed below: Writable Streams Writable Streams Methods Descriprioncork()Write every data into the buffer memory.destroy()Destroy the created stream and you cannot call the write() methodend()It is an inbuilt application programming interface of Stream modulesetDefaultEncoding()Set the default encoding for a Writable stream.uncork()Flush all the buffered data when stream.cork() method was called._write()It is affixed with an underscore as it is inside the class that defines it.write()Write some data to the Writable stream.read()Read the data out of the internal buffer.destroy()Destroy the stream.pause()Stop the flowing mode from emitting ‘data’ events.isPaused()Check the current operating state of the Readable streams.resume()Paused data that can be resumed again and data starts flowing again.Writable Streams Property DescriptionLengthcheck the number of bytes in the queue that is ready to be written.ObjectModeGet the object mode value of the Writable stream.FinishedThe writable.writableFinished property is set to true instantly before the emit of the ‘finish’ event.CorkedCheck the number of times you need to call the uncork() function so that you can fully uncork the stream.destroyedCheck the writable.destroy() method is being called or not.writableCheck the writable.write() method is safe to call or not.writableEndedCheck the writable.end() method is being called or not.HighWaterMarkCheck the highWaterMark value which was passed while creating the Writable.destroyedCheck the readable.destroy() function is being called or not.Writable Streams Event Description closeIts hidden resources (for example, a file descriptor) is being closed.finishThe ‘finish’ event in a Writable Stream is emitted after the Calling of writable.end() methodStream pipeWhen the stream.pipe() method is being called on a readable streamunpipeWhen stream.unpipe() method is being called on a Readable stream Readable Streams Readable Streams Methods Description pipe()Attach a Writable stream to the readable stream so that it consequentlyunpipe()Detach a Writable stream which was previously attached while using the stream.pipe() method.unshift()Readable Stream is utilized to push a chunk of data back into the internal buffer.Readable.from()construct Readable Streams out of iterators.setEncoding()Set the encoding of the data read.Readable Streams Property Description readableLengthCheck the number of bytes in the queue which is ready to be read.readableHighWaterMarkCheck the value of highWaterMark used while constructing Readable streams.readableFlowingCheck if the streams are in flowing mode or not.readableEndedCheck if the end event is emitted or not.readableObjectModeCheck the objectMode of the streamreadableCheck if it is safe to call readable.read() method.Readable Streams EventsDescription pauseWhen stream.pause() is being called and readableFlowing property is not false.resumeWhen stream.resume() is being called and readableFlowing property is not true.errorThe ‘error’ event in Readable stream can be emitted at any time.readableWhen the data is available so that it can be read from the streamdataWhen readable.pipe() and readable.resume() method is called for switching the streamcloseWhen the stream and any of its hidden resources are being closedendWhen there is no available data to be consumed from the readable stream. Transform Streams Transform Streams MethodsDescription destroy()Destroy the transform stream, and also emits an ‘error’ event optionally.pipeline()That is used to the pipe by linking.finished()It is utilized to receive an alert if a stream is not writable or readable anymore. Comment K kartik Follow Improve K kartik Follow Improve Article Tags : Web Technologies Node.js Node.js-Stream-module Explore Node.js Tutorial 3 min read Introduction & Installation NodeJS Introduction 3 min read Node.js Roadmap: A Complete Guide 6 min read How to Install Node.js on Linux 6 min read How to Install Node.js on Windows 5 min read How to Install NodeJS on MacOS 6 min read Node.js vs Browser - Top Differences That Every Developer Should Know 6 min read NodeJS REPL (READ, EVAL, PRINT, LOOP) 4 min read Explain V8 engine in Node.js 7 min read Node.js Web Application Architecture 3 min read NodeJS Event Loop 5 min read Node.js Modules , Buffer & StreamsNodeJS Modules 5 min read What are Buffers in Node.js ? 4 min read Node.js Streams 4 min read Node.js Asynchronous ProgrammingAsync Await in Node.js 3 min read Promises in NodeJS 7 min read How to Handle Errors in Node.js ? 4 min read Exception Handling in Node.js 3 min read Node.js NPMNodeJS NPM 6 min read Steps to Create and Publish NPM packages 7 min read Introduction to NPM scripts 2 min read Node.js package.json 4 min read What is package-lock.json ? 3 min read Node.js Deployments & CommunicationNode Debugging 2 min read How to Perform Testing in Node.js ? 2 min read Unit Testing of Node.js Application 5 min read NODE_ENV Variables and How to Use Them ? 2 min read Difference Between Development and Production in Node.js 3 min read Best Security Practices in Node.js 4 min read Deploying Node.js Applications 5 min read How to Build a Microservices Architecture with NodeJS 3 min read Node.js with WebAssembly 3 min read Resources & ToolsNode.js Web Server 6 min read Node Exercises, Practice Questions and Solutions 4 min read Node.js Projects 9 min read NodeJS Interview Questions and Answers 15+ min read Like