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?