Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda