Node.js Stream Complete Reference Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes 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. Create Quiz Comment K kartik Follow 2 Improve K kartik Follow 2 Improve Article Tags : Web Technologies Node.js Node.js-Stream-module Explore Introduction & Installation NodeJS Introduction3 min readNode.js Roadmap: A Complete Guide6 min readHow to Install Node.js on Linux6 min readHow to Install Node.js on Windows5 min readHow to Install NodeJS on MacOS6 min readNode.js vs Browser - Top Differences That Every Developer Should Know6 min readNodeJS REPL (READ, EVAL, PRINT, LOOP)4 min readExplain V8 engine in Node.js7 min readNode.js Web Application Architecture3 min readNodeJS Event Loop5 min readNode.js Modules , Buffer & StreamsNodeJS Modules5 min readWhat are Buffers in Node.js ?4 min readNode.js Streams4 min readNode.js Asynchronous ProgrammingAsync Await in Node.js3 min readPromises in NodeJS7 min readHow to Handle Errors in Node.js ?4 min readException Handling in Node.js3 min readNode.js NPMNodeJS NPM6 min readSteps to Create and Publish NPM packages7 min readIntroduction to NPM scripts2 min readNode.js package.json4 min readWhat is package-lock.json ?3 min readNode.js Deployments & CommunicationNode Debugging2 min readHow to Perform Testing in Node.js ?2 min readUnit Testing of Node.js Application5 min readNODE_ENV Variables and How to Use Them ?2 min readDifference Between Development and Production in Node.js3 min readBest Security Practices in Node.js4 min readDeploying Node.js Applications5 min readHow to Build a Microservices Architecture with NodeJS3 min readNode.js with WebAssembly3 min readResources & ToolsNode.js Web Server6 min readNode Exercises, Practice Questions and Solutions4 min readNode.js Projects9 min readNodeJS Interview Questions and Answers15+ min read Like