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

  • Home
  • SEARCH
  • 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 8412383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:39:28+00:00 2026-06-10T00:39:28+00:00

When scanning a directory tree with node.js, as we utilise asynchronous callbacks with a

  • 0

When scanning a directory tree with node.js, as we utilise asynchronous callbacks with a large directory it is easy to instantly queue up more than a 1000 fs operations at once which often causes the node.js process to crash or simply for the fs operations to fail with a “EM too many open files” error.

Has anyone figured out an elegant way of solving this?

  • 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-06-10T00:39:29+00:00Added an answer on June 10, 2026 at 12:39 am

    Update for the years:

    1. I coded a https://npmjs.com/package/safefs package based on this answer
    2. Isaac coded a https://npmjs.com/package/graceful-fs package
    3. Safefs now uses the graceful-fs package
    4. The same problem exists for processes, so I created the https://npmjs.com/package/safeps package which solves this issue among many others

    —

    Not sure if this is the best way to solve this issue, but what I’ve effectively done is wrapped all the asynchronous fs functions with a wrapper that checks whether or not the we have more than the allowed amount of files open (arbitrarily set to a reasonable 100). If there is more than that many files open at the time of the call, the call will idle and check again after a delay to see if there is now an opening. The code for this logic can be found here: https://github.com/balupton/bal-util/blob/master/src/lib/paths.coffee#L7-45

    In terms of implementing it, you just need to change require('fs').readFile or whatever call you are using to require('bal-util').readFile and install the bal-util dependency (npm install bal-util) which is simple enough.

    Hope this helps. If there is a more robust way of doing this, I’d love to know.

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

Sidebar

Related Questions

I was looking how to write a multi threaded C++ code for scanning directory
Does anyone know of a tool that generates a makefile by scanning a directory
when scanning a file for words and using the built-in hashset class from the
I am scanning 5000 csv files into a database. Regrettably the files have '',
Does C# provide an effective means of scanning the available COM ports? I would
Using C# (VS2008) and WIA - scanning to TIFF format; When I use the
i've dev code for wifi scanning in python, now i trying to modify my
I'm trying to do barcode scanning using Android emulator. Could anyone please tell me
Currently I have a powershell proccess that is scanning a SQL Server Table and
In Java there are methods to go about scanning the classpath/all classes/within a package

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.