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

228
Vistas
Node.js getaddrinfo ENOTFOUND when there is no internet connection

Normally, everything works, but when there is no internet connection my app throws an error:

    events.js:160
      throw er; // Unhandled 'error' event
      ^

   Error: getaddrinfo ENOTFOUND

    /* my code - putting this to try...catch have no effect: */
    var http = require('http');
    // (...)
    var req = http.request(options, response => {
       /* ... */
    });
    req.write(data);
    req.end();

So what can I do when internet connection shuts down and I would like to prevent my app from stopping?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To prevent your app from stopping when external server's internet connection is down, you can catch getaddrinfo ENOTFOUND error and return error message to your end client. Please check this SO on how to catch getaddrinfo ENOTFOUND error.

In your case, the code would be:

var http = require('http');
// (...)
var req = http.request(options, response => {
   /* ... */
});
req.on('error', function (err) {
    // Check error type and console.log corresponding message.
});
req.write(data);
req.end();
about 4 years ago · Santiago Trujillo Denunciar
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