• Uncategorized

About javascript : Can-I-configure-how-long-fsreadFileSync-should-wait-before-it-gives-up

Question Detail

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?

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.