Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Can I configure how long fs.readFileSync should wait before it gives up?

I'm using fs.readFileSync almost exactly as this answer suggests.

var fileContents;
try {
  fileContents = fs.readFileSync('foo.bar');
} catch (err) {
  // Here you get the error when the file was not found,
  // but you also get any other error
}

However, while I'm playing around getting my code to work and handle missing files, and as I haven't got jest.mock('fs', ...) working yet, I was wondering if there was a way of configuring fs or NodeJs, or the WSL1 I'm using to take less time before throwing ENOENT errors?

As an example, time type foo.bar takes 0m0.000s but the rough equivalent (bear in mind my actual code is a little different to above, i.e. it dynamically determines what my actual foo.bar is) takes 39 seconds.

When I run my code above, it looks like NodeJs is waiting on the file system, perhaps polling for ~5-10 seconds, and then it bails and throws an error with ENOENT? I don't know how it works under the covers.

Can I configure how long it takes/waits for the file system to respond? Or is it just reporting the system error?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!