Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:14:58+00:00 2026-05-28T11:14:58+00:00

In a node program I’m reading from a file stream with fs.createReadStream . But

  • 0

In a node program I’m reading from a file stream with fs.createReadStream. But when I pause the stream the program exits. I thought the program would keep running since the file is still opened, just not being read.

Currently to get it to not exit I’m setting an interval that does nothing.

setInterval(function() {}, 10000000);

When I’m ready to let the program exit, I clear it. But is there a better way?

Example Code where node will exit:

var fs = require('fs');

var rs = fs.createReadStream('file.js');
rs.pause();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:14:59+00:00Added an answer on May 28, 2026 at 11:14 am

    Node will exit when there is no more queued work. Calling pause on a ReadableStream simply pauses the data event. At that point, there are no more events being emitted and no outstanding work requests, so Node will exit. The setInterval works since it counts as queued work.

    Generally this is not a problem since you will probably be doing something after you pause that stream. Once you resume the stream, there will be a bunch of queued I/O and your code will execute before Node exits.

    Let me give you an example. Here is a script that exits without printing anything:

    var fs = require('fs');
    
    var rs = fs.createReadStream('file.js');
    rs.pause();
    
    rs.on('data', function (data) {
      console.log(data); // never gets executed
    });
    

    The stream is paused, there is no outstanding work, and my callback never runs.

    However, this script does actually print output:

    var fs = require('fs');
    
    var rs = fs.createReadStream('file.js');
    rs.pause();
    
    rs.on('data', function (data) {
      console.log(data); // prints stuff
    });
    
    rs.resume(); // queues I/O
    

    In conclusion, as long as you are eventually calling resume later, you should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this program to remove a node from tree, but it still exists!
In a program to simulate logic gates I switched from using arrays node N[1000];
I've got a chat program which pushes JSON data from Apache/PHP to Node.js, via
I'm trying to make the node-mongodb-native driver from git, but when i try and
Possible Duplicate: A simple program to CRUD node and node values of xml file
I am building a file synchronization program (not unlike Dropbox) using node.js on both
I have a simple Node.js program running on my machine and I want to
I want the following following node.js program to read a file and print out
I've got a little program that needs to grab favicons from sites using node.js.
When a user clicks a 'Add Node' button above a tree and the program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.