Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda