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 7174587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:05:17+00:00 2026-05-28T16:05:17+00:00

I have a file called a.txt which I can open and read using fs.readFile.

  • 0

I have a file called a.txt which I can open and read using fs.readFile. However, I can’t seem to read it with createReadStream:

var fs = require('fs');

var stream = fs.createReadStream('a.txt');
stream.on('data', function() { console.log('data present'); });

This never prints anything, what am I missing?

  • 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-28T16:05:18+00:00Added an answer on May 28, 2026 at 4:05 pm

    Had this exact situation happen to me. What’s happening when you run this code in the REPL is that the control flow is going back to node’s event loop in between each line you type. When that happens node is taking the opportunity to do any pending IO. But because you haven’t attached a listener, the ‘data’ events sail merrily off into oblivion.

    You can verify this by pasting the code above into a javascript file and running it as a script. It works fine then because the listener gets attached before control returns to the event loop.

    The version of this problem we encountered was when opening a stream and trying to work with it in a callback. Opening the stream in the enclosing function and referring to it from the callback didn’t work – node had already pumped all the data out before our event listener was attached.

    You can solve this one of two ways: either call pause on the stream as soon as you open it or be sure to attach your listeners before going through any callbacks.

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

Sidebar

Related Questions

I have a file called 34.php?session=2534464a39a2c97cb7113689726a4e52 in my /var/www/html folder but I can't view
I have a file, called genes.txt , which I'd like to become a data.frame.
I have a file called installer.txt which will contain a line by line of
Say I have a file called hello.txt which contains Hello World!. If I wanted
I have a file called File1.txt which resides in the following folder D:\Dev\File1(v1).txt (v1)
Let's say I have a file called test.txt within the package com.test.io within my
I'm creating a Shell Script, and I have a file like this called expressions.txt
I have a filelist.txt file and I created a file called clear.php to clear
I have a file called webpart.cs which is called by one of my masterpages
Ok, I have a text file containing an encrypted string of text called textToDecrypt.txt

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.