Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Node.js Stream readable.isPaused() Method
Next article icon

Node.js Stream readable.pause() Method

Last Updated : 12 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report
The readable.pause() method is an inbuilt application programming interface of Stream module which is used to stop the flowing mode from emitting 'data' events. If any data that becomes accessible will continue to exist in the internal buffer. Syntax:
readable.pause()
Parameters: This method does not accept any parameters. Return Value: If this method is used then the reading of data is paused at that time. Below examples illustrate the use of readable.pause() method in Node.js: Example 1: javascript
// Node.js program to demonstrate the      // readable.pause() method    // Including fs module const fs = require('fs');  // Constructing readable stream const readable = fs.createReadStream("input.txt"); readable.on('data', (chunk) => {   console.log(`${chunk}`); });  // Calling pause method readable.pause();  // Checking if paused or not readable.isPaused(); 
Output:
true
Example 2: javascript
// Node.js program to demonstrate the      // readable.pause() method    // Include fs module const fs = require('fs');  // Create readable stream const readable = fs.createReadStream("input.txt");  // Handling data event readable.on('data', (chunk) => {   console.log(`Received ${chunk.length} bytes of data.`);    // Calling pause method   readable.pause();    // After this any data will be displayed    // after 1 sec.   console.log('No further data will be displayed for 1 second.');    // Using setTimeout function   setTimeout(() => {     console.log('Now data starts flowing again.');     readable.resume();   }, 1000); });  // Displays that program  // is ended console.log("Program ends!!"); 
Output:
Program ends!!  Received 5 bytes of data.  No further data will be displayed for 1 second.  Now data starts flowing again.  
However, you can see while running, that after the execution of pause() method, no further data will be displayed for 1 second. Reference: https://nodejs.org/api/stream.html#stream_readable_pause.

Next Article
Node.js Stream readable.isPaused() Method
author
nidhi1352singh
Improve
Article Tags :
  • Web Technologies
  • Node.js
  • Node.js-Stream-module

Similar Reads

    Writable Streams Methods

    • Node.js Stream writable.cork() Method
      The writable.cork() method is an inbuilt application programming interface of Stream module which is used to write every data into the buffer memory. When we use stream.uncork() or stream.end() methods then the buffer data will be flushed.  Syntax: writable.cork() Parameters: This method does not ac
      2 min read

    • Node.js Stream writable.destroy() Method
      The writable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the created stream and you cannot call the write() method to write data again after you have already destroyed the created stream. Syntax: writable.destroy()Parameters: This method
      2 min read

    • Node.js Stream writable.end() Method
      The writable.end() method is an inbuilt application programming interface of Stream module so that no more data can be written to the Writable anymore. The arguments chunk and encoding are optional which will permit one final new chunk of data to be written instantly before closing the stream. Moreo
      3 min read

    • Node.js Stream writable.setDefaultEncoding() Method
      The writable.setDefaultEncoding() method is an inbuilt application programming interface of Stream module which is used to set the default encoding for a Writable stream. Syntax: writable.setDefaultEncoding( encoding ) Parameters: This method accepts single parameter encoding which holds the encodin
      2 min read

    • Node.js Stream writable.uncork() Method
      The writable.uncork() method is an inbuilt application programming interface of Stream module which is used to flush all the buffered data when stream.cork() method was called. Syntax: writable.uncork() Parameters: This method does not accept any parameters. Return Value: If this method is being cal
      2 min read

    • Node.js Stream writable._write() Method
      The writable._write() method is an inbuilt application programming interface of Stream module which is used to implement a writable stream. The writable._write() method is affixed with an underscore as it is inside the class that defines it. Moreover, the user program must not call it directly. This
      3 min read

    • Node.js Stream writable.write() Method
      The writable.write() method is an inbuilt application programming interface of Stream module which is used to write some data to the Writable stream. The callback function is called once the data has been completely handled. Syntax: writable.write( chunk, encoding, callback) Parameters: This method
      2 min read

    • Node.js Stream readable.read() Method
      The readable.read() method is an inbuilt application programming interface of Stream module which is used to read the data out of the internal buffer. It returns data as a buffer object if no encoding is being specified or if the stream is working in object mode. Syntax: readable.read( size ) Parame
      2 min read

    • Node.js Stream readable.destroy() Method
      The readable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the stream. Syntax: readable.destroy( error ) Parameters: This method accepts single parameter error which is optional and it emits an error while handling error event. Return Valu
      2 min read

    • Node.js Stream readable.pause() Method
      The readable.pause() method is an inbuilt application programming interface of Stream module which is used to stop the flowing mode from emitting 'data' events. If any data that becomes accessible will continue to exist in the internal buffer. Syntax: readable.pause() Parameters: This method does no
      2 min read

    • Node.js Stream readable.isPaused() Method
      The readable.isPaused() method is an inbuilt application programming interface of Stream module which is used to check the current operating state of the Readable streams. Syntax: readable.isPaused() Parameters: This method does not accept any parameters. Return Value: It returns true if the Readabl
      1 min read

    • Node.js Stream readable.resume() Method
      Node.js streams are powerful tools for handling data transfer efficiently, especially when dealing with large datasets or real-time data. The readable.resume() method is a part of the readable stream interface, playing a crucial role in managing the flow of data. This article will delve into what re
      4 min read

    Writable Streams Property

    • Node.js Stream writable.writableLength Property
      The writable.writableLength property is an inbuilt application of stream module which is used to check the number of bytes in the queue that is ready to be written.  Syntax: writable.writableLength Return Value: This property returns the number of bytes that is ready to write into the queue.  Below
      2 min read

    • Node.js Stream writable.writableObjectMode Property
      The writable.writableObjectMode property in Stream module is used to get the object mode value of the Writable stream. Syntax: writable.writableObjectMode Return Value: It returns true if the objectMode is set to true otherwise returns false. Below examples illustrate the use of writable.writableObj
      2 min read

    • Node.js Stream writable.writableFinished Property
      The writable.writableFinished property is set to true instantly before the emit of the 'finish' event. Syntax: writable.writableFinished Return Value: It returns true if 'finish' event is called before it else it returns false. Below examples illustrate the use of writable.writableFinished property
      2 min read

    • Node.js Stream writable.writableCorked Property
      The writable.writableCorked property is an inbuilt application programming interface of Stream module which is used to check the number of times you need to call the uncork() function so that you can fully uncork the stream. Syntax: writable.writableCorked Return Value: It returns an integer value t
      2 min read

    • Node.js Stream writable.destroyed Property
      The writable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the writable.destroy() method is being called or not. Syntax: writable.destroyed Return Value: This property returns true if writable.destroy() method is called before it else it r
      2 min read

    • Node.js Stream writable.writable Property
      The writable.writable property is an inbuilt application programming interface of Stream module which is used to check the writable.write() method is safe to call or not. Syntax: writable.writable Return Value: It returns true if it is safe to call writable.write() method otherwise returns false. Be
      2 min read

    • Node.js Stream writable.writableEnded Property
      The writable.writableEnded property is an inbuilt application programming interface of Stream module which is used to check the writable.end() method is being called or not. Syntax: writable.writableEnded Return Value: It returns true if writable.end() method is being called before otherwise returns
      3 min read

    • Node.js Stream writable.writableHighWaterMark Property
      The writable.writableHighWaterMark property is an inbuilt application programming interface of stream module which is used to check the highWaterMark value which was passed while creating the Writable. Syntax: writable.writableHighWaterMark Return Value: It returns the value of highwatermark if it i
      2 min read

    • Node.js Stream readable.destroyed Property
      The readable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the readable.destroy() function is being called or not. Syntax: readable.destroyed Return Value: It returns true if readable.destroy() method is being called otherwise returns fals
      2 min read

    Writable Streams Event

    • Node.js stream.Writable close Event
      The stream.Writable close Event is an inbuilt application programming interface of Stream module which is used to emit when the stream and any of its hidden resources (for example, a file descriptor) is being closed. This event implies that no further events will be emitted, plus no further computat
      2 min read

    • Node.js Writable Stream finish Event
      The 'finish' event in a Writable Stream is emitted after the Calling of writable.end() method when all the data is being flushed to the hidden system. Syntax: Event: 'finish' Return Value: If the writable.end() method is being called before then this event is emitted else its not emitted. Below exam
      2 min read

    • Node.js Writable Stream pipe Event
      The pipe event in a Writable Stream is emitted when the stream.pipe() method is being called on a readable stream by attaching this writable to its set of destinations.  Syntax: Event: 'pipe' Return Value: If the pipe() method is being called then this event is emitted else it is not emitted.  The b
      1 min read

    • Node.js Writable Stream unpipe Event
      The 'unpipe' event in a Writable Stream is emitted when the stream.unpipe() method is being called on a Readable stream by detaching this Writable from its set of destinations.  Syntax: Event: 'unpipe' Return Value: If the unpipe() method is being called then this event is emitted else it's not emit
      1 min read

    Readable Streams Methods

    • Node.js Stream readable.pipe() Method
      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
      2 min read

    • Node.js Stream readable.unpipe() Method
      The readable.unpipe() method in a Readable Stream is used to detach a Writable stream which was previously attached while using the stream.pipe() method. Syntax: readable.unpipe( destination ) Parameters: This method accepts single parameter destination which is the destination of writable stream to
      1 min read

    • Node.js Stream readable.unshift() Method
      The readable.unshift() method in a Readable Stream is utilized to push a chunk of data back into the internal buffer. However, when a stream is being fully consumed and it needs to be "un-consumed" then this method is helpful. Syntax: readable.unshift( chunk, encoding ) Parameters: This method accep
      2 min read

    • Node.js stream.Readable.from() Method
      The stream.Readable.from() method is an inbuilt application programming interface of the Stream module which is used to construct Readable Streams out of iterators. Syntax: stream.Readable.from( iterable, options ) Parameters: This method accept two parameters as mentioned above and described below:
      2 min read

    • Node.js Stream readable.setEncoding() Method
      The readable.setEncoding() method in a Readable Stream is used to set the encoding of the data read. Syntax: readable.setEncoding( encoding ) Parameters: This method accepts single parameter encoding which holds the encoding type. Return Value: It returns the data in the encoded form. Below examples
      1 min read

    Readable Streams Property

    • Node.js Stream readable.readableLength Property
      The readable.readableLength property in a readable Stream that is used to check the number of bytes in the queue which is ready to be read. Syntax: readable.readableLength Return Values: It returns the number of bytes in the queue which are ready to be read. Below examples illustrate the use of read
      1 min read

    • Node.js Stream readable.readableHighWaterMark Property
      The readable.readableHighWaterMark property in a readable stream that is used to check the value of highWaterMark used while constructing Readable streams. Syntax: readable.readableHighWaterMark Return Value: It returns the value of highWaterMark used while constructing Readable streams. Below examp
      1 min read

    • Node.js Stream readable.readableFlowing Property
      The readable.readableFlowing property in a readable stream that utilized to check if the streams are in flowing mode or not. Syntax: readable.readableFlowing Return Value: It returns true if stream is in flowing mode else it returns false. Below examples illustrate the use of readable.readableFlowin
      1 min read

    • Node.js Stream readable.readableEnded Property
      The readable.readableEnded property in a readable Stream is utilized to check if the end event is emitted or not. Syntax: readable.readableEnded Return Value: It returns true if end event is emitted else it returns false. Below examples illustrate the use of readable.readableEnded property in Node.j
      1 min read

    • Node.js Stream readable.readableObjectMode Property
      The readable.readableObjectMode property in a Readable Stream that is used to check the objectMode of the stream. Syntax: readable.readableObjectMode Return Value: It returns the Boolean value. Below examples illustrate the use of readable.readableObjectMode property in Node.js: Example 1: // Node.j
      2 min read

    • Node.js Stream readable.readable Property
      The readable.readable property is an inbuilt application programming interface of Stream module which is used to check if it is safe to call readable.read() method. Syntax: readable.readable Return Value: It returns true if readable.read() method is being called otherwise returns false. Below exampl
      1 min read

    Readable Streams Events

    • Node.js Readable Stream pause Event
      The 'pause' Event in a Readable Stream is emitted when stream.pause() is being called and readableFlowing property is not false. Syntax: Event: 'pause' Return Value: It is emitted if readable.pause() is being called else it is not emitted. Below examples illustrate the use of pause event in Node.js:
      1 min read

    • Node.js Readable Stream resume Event
      The 'resume' Event in a Readable Stream is emitted when stream.resume() is being called and readableFlowing property is not true. Syntax: Event: 'resume' Return Value: It is emitted if readable.resume() is being called else it is not emitted. Below examples illustrate the use of resume event in Node
      2 min read

    • Node.js Readable Stream error Event
      The 'error' event in Readable stream can be emitted at any time. It takes place when the hidden stream is not able to generate data due to some hidden internal failure or when the implementation of stream pushes a chunk of data which is not valid. Moreover, a single Error object is passed as an argu
      1 min read

    • Node.js Readable Stream readable Event
      The 'readable' Event in a Readable Stream is emitted when the data is available so that it can be read from the stream or it can be emitted by adding a listener for the 'readable' event which will cause data to be read into an internal buffer. Syntax: Event: 'readable' Below examples illustrate the
      1 min read

    • Node.js Readable Stream data Event
      The 'data' Event in a Readable Stream is emitted when readable.pipe() and readable.resume() method is called for switching the stream into the flowing mode or by adding a listener callback to the data event. This event can also be emitted by calling readable.read() method and returning the chunk of
      2 min read

    • Node.js Readable Stream close Event
      The 'close' Event in a Readable Stream is emitted when the stream and any of its hidden resources are being closed This event implies that no further events can be emitted, and no further computations can take place. Moreover, if a Readable stream is created with the emitClose option then it can alw
      1 min read

    • Node.js Readable Stream end Event
      The 'end' Event in a Readable Stream is emitted when there is no available data to be consumed from the readable stream. And the 'end' event won't be emitted if the data is not fully consumed. It can be done by switching the stream into the flowing mode, or by calling stream.read() method again and
      2 min read

    Transform Streams Methods

    • Node.js Stream transform.destroy() Method
      The transform.destroy() method in a Readable Stream is used to destroy the transform stream and also emits an 'error' event optionally. Moreover, the transform stream releases any internal resources after this call is made.  Syntax: transform.destroy( error ) Parameters: This method accepts single p
      2 min read

    • Node.js Stream.pipeline() Method
      The stream.pipeline() method is a module method that is used to the pipe by linking the streams passing on errors and accurately cleaning up and providing a callback function when the pipeline is done.  Syntax: stream.pipeline(...streams, callback) Parameters: This method accepts two parameters as m
      3 min read

    • Node.js stream.finished() Method
      The stream.finished() method is utilized to receive an alert if a stream is not writable or readable anymore or if it had experienced an error or a close event that is immature. Syntax:   stream.finished(stream, options, callback) Parameters: This method accepts three parameters as mentioned above a
      3 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences