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

256
Vistas
HTTPS module error handling when disconnecting from internet in Node.js

How can I handle or catch this code or https module in node.js? I'm trying to catch this, because if someone will just disconnect from the internet, it will end up in this error. I tried many things, but it didn't work. The website's body is just v2.2

Here's the code:

const version = "v2.2";

function checkforupdates() {
    try {
        https.get("https://tomkoid.tk/phyc/latestversion.txt",(res) => {
            let updatebody = "";
        
            res.on("data", (chunk) => {
                updatebody += chunk;
            });

            res.on("end", () => {
                if(updatebody.toString()!=version) {
                    console.log("\033[0;33m[Updates] Update " + updatebody.toString() + " found. Download it on GitHub!\033[0m");
                } else {
                    console.log("\033[0;32m[Updates] No update found.\033[0m");
                }
            });
        });
    } catch(err) {
        console.log("error")
    }
}

and here's the error:

node:events:368
      throw er; // Unhandled 'error' event
      ^
    
Error: getaddrinfo EAI_AGAIN tomkoid.tk
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:72:26)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (node:_http_client:442:9)
    at TLSSocket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -3001,
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: 'tomkoid.tk'
}

Node.js v17.3.1
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I just "fixed" it by trying axios library, works better.

about 4 years ago · Juan Pablo Isaza 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