Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!