Skip to content

How to fix error: getaddrinfo enotfound?

  • by
  • 2 min read

There are now many different options for web developers to use when it comes to frameworks for web development. That said, as easy as they make the job, random bugs and glitches are still the order of the day for most developers.

In this article, we’re talking about the “error: getaddrinfo enotfound” in Node.js, its causes and what you can do to fix the problem.


What causes this error?

The error occurs because Webpack can’t find your local host address. There are several reasons why this might happen, including:

  • The Hosts file is missing or corrupt. 
  • The local network isn’t functioning properly.
  • A firewall is blocking your connection. 

Also read: How to fix Javascript error: ipython is not defined?


How to fix this?

Here are three fixes you can try out.

Add the localhost entry to the Hosts file

One quick and simple fix for the problem is ensuring your Hosts file contains the localhost entry that identifies local servers and hosts.ย 

Step 1: Open a terminal and run the following command.

sudo nano / etc/ hosts

Step 2: Add the following line to the file.

127.0.01 localhost

Close the file and restart your server. The error should be gone now. 


Check options for the HTTP request

If you’re requesting data from a remote host, check to ensure that your options for the request are typed properly. One important thing to note here is that you don’t need to mention the HTTP/HTTPS protocol in theย hostย field.ย 

A correct request would look something like this:

var options = { host: 'host.com', 
                path: 'path/after/host' };

Restart your server after making the change, and it should work just fine. Alternatively, if the remote service is running on a port other than the default, make sure to add the port option.ย 


Use the HTTPS library

If your remote host is protected with HTTPS, you must use the HTTPS library to parse the URL correctly. Here’s an example snippet demonstrating how.ย 

https = require('https');

// options
var options = { host: 'host.com', 
                path: 'path/after/host' };

// get
https.get(options, callback);

Also read: How to fix error: enoent: no such file or directory?

nv-author-image

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: [email protected].

>