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

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

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 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!