Error getaddrinfo enotfound localhost

ng serve error: getaddrinfo ENOTFOUND localhost I was getting this error: when running ng serve . After web lookup, the proposed answer to this problem is to run this command instead: Unfortunately, the instructions came without explanation. This works and the Angular project compiled successfully. I am not sure why. Can someone explain why […]

Содержание

  1. ng serve error: getaddrinfo ENOTFOUND localhost
  2. 6 Answers 6
  3. solution for Ubuntu users
  4. to edit hosts file
  5. entry example inside hosts
  6. Related
  7. Hot Network Questions
  8. Subscribe to RSS
  9. test: Error: getaddrinfo ENOTFOUND localhost #44003
  10. Comments
  11. Version
  12. Platform
  13. Subsystem
  14. What steps will reproduce the bug?
  15. How often does it reproduce? Is there a required condition?
  16. What is the expected behavior?
  17. What do you see instead?
  18. Additional information
  19. Error: GetAddrInfo ENOTFOUND localhost
  20. NodeJS Postgres error getaddrinfo ENOTFOUND
  21. 8 Answers 8
  22. XCUITest/WebDriverAgentRunner — getaddrinfo ENOTFOUND localhost localhost:8100 #7273
  23. Comments
  24. The problem
  25. Environment
  26. Details
  27. Link to Appium logs
  28. Code To Reproduce Issue [ Good To Have ]

ng serve error: getaddrinfo ENOTFOUND localhost

I was getting this error:

when running ng serve . After web lookup, the proposed answer to this problem is to run this command instead:

Unfortunately, the instructions came without explanation.

This works and the Angular project compiled successfully. I am not sure why. Can someone explain why this works and what has happened in the background? Thanks

6 Answers 6

Hi I was having the same issue, my configuration is virtual host was not for localhost. At the same time this issue comes when there is conflict between your global Angular CLI version with local Angular CLI version. I tried with ng serve —port 4200 —host 127.0.0.1 that works for me.

solution for Ubuntu users

—host option does not work until there is an explicit entry in hosts file for your Operating system. I solved it adding a host entry inside hosts’ file under

/etc/hosts` on ubuntu OS.

to edit hosts file

entry example inside hosts

The issue for me was the host entry:

Since I was on MAC I cmd+space bar type terminal then

add the localhost entry ^ + O to save and ^ + x to exit

and then my problem was resolved

For those of you who work with docker, I had this issue because my docker was stuck, reset the docker application and everything was working again.

In my case, it was a corrupted ‘hosts’ file. A nightly update on my MAC OS caused it. This error made no sense at first and all conditions were misleading:

  1. I ran ‘ng serve’ all day without error until suddenly vscode started throwing that error late in the day!
  2. I haven’t updated the hosts file in a year.
  3. cat /etc/hosts —> 127.0.0.1 localhost (NO ERROR!)
  4. ls -rtl /etc —> hosts file modified in the morning!
  5. vi /etc/hosts —> bunch of ASCII characters that were not visible using cat command were now visible and corrupted the file!
  6. I deleted the unwanted characters and it solved the issue.

For the person who use windows.
I have the same problem in angular.

  1. Go to C:WindowsSystem32driversetchosts.txt .
  2. Add localhost to 127.0.0.1 line
    ex :

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

test: Error: getaddrinfo ENOTFOUND localhost #44003

Version

Platform

Subsystem

What steps will reproduce the bug?

Currently the failures are visible in the current build log,

How often does it reproduce? Is there a required condition?

What is the expected behavior?

What do you see instead?

Additional information

and resolv.conf doesn’t exist. All other test cases that use localhost are passing, as expected.

The text was updated successfully, but these errors were encountered:

curious what you see when doing strace . On Ubuntu I see the following:

I get this error sometimes on my pc, but not always.

ENOTFOUND is a synthetic error that node fabricates when it doesn’t get an answer back from getaddrinfo(3), it’s not a real operating system-level error. Reasons include running out of file descriptors in libc (not visible to node), not getting back a response from the DNS server, etc. It’s basically a catch-all.

In this case, there is no DNS server and it works with other tests.

strace shows nothing. This is only a problem since about 18.2.0 and not before and not in any other released line. And I only see it in a VM build environment and not in a chroot (at least it disappeared there) which is very strange.

I will try to bisect the issue.

You mean v18.1.0 works? There are no changes between the two that seem like likely culprits. I’m interested to see what bisect turns up.

So, the bisect ended up on 70b516e which is #43054 . Looking at the pull request, it kind of makes sense this is the one as the tests in question are explicitly skipped on some platforms.

The test is reproducible every time on openSUSE:Tumbleweed build VM. I can’t reproduce it outside of it on a workstation, but in the VM with no networking connections and only a hosts file to resolve localhost to ipv6 and ipv4, it reproduces every time.

I will try to look more closely what is actually failing here.

This was introduced in 18.4.0. I mistyped earlier the versions. 18.2.0 still passed

Is there no network interface at all, no loopback ?

So, I’ve learned something about debugging node over last few days 🙂 But I did find the problem.

The problem is that family is set to a string, which causes hints to be set to 32 which means AI_ADDRCONFIG and then address resolution fails.

On a network connected device, this passes.

Why? We can look at the manpage for getaddrinfo

If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses are returned in the list pointed to by res only if the local system has at least one IPv4 address configured, and IPv6 addresses are returned only if the local system has at least one IPv6 address configured. The loopback address is not considered for this case as valid as a configured address. This flag is useful on, for example, IPv4-only systems, to ensure that getaddrinfo() does not return IPv6 socket addresses that would always fail in connect(2) or bind(2).

This is why these tests fail every time when you have a loopback interface as the only network interface active. They will pass if you have other network interfaces active.

Источник

Error: GetAddrInfo ENOTFOUND localhost

I am dropping this here as a reminder for my future self and for anyone that might encounter this weird error.

At work we are using nodejs and serverless framework to build a backend application.

To test it we just run it locally with

Exit fullscreen mode

Today, a colleague who was working remotely asked me if I could run the app locally because he was getting this error:

The info we found googling were mostly related to Webpack or Angular, which we are not using but had in common some problems in the configuration of etc/hosts.

Confronting that configuration on my workstation and his laptop at home, I had:

where his contained info about OpenVN Client SSL but nothing about localhost. Probably when he configured the VPN to work remotely he overwrote the previous content, he added to his file this one line:

Exit fullscreen mode

and everything started to work.

    To edit the file: go to home directory ( cd

) and open vim sudo vi /etc/hosts then press I and start editing the file.

  • To save and exit vim: press ESC then :wq or :q! if you just want to exit without saving. More cheatsheets here

Источник

NodeJS Postgres error getaddrinfo ENOTFOUND

I use pg://user:pass@localhost:port/table for connecting to my AWS database. When I use localhost, the app works fine, but when I try to connect the AWS server it falls apart.

Even a simple connection code gives me this error. The database name is people and it’s running on port 8080 but in this error it’s showing 5432 even if I declare the correct port number in the conString.

Error: getaddrinfo ENOTFOUND people people:5432 at errnoException (dns.js:26:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

This is my code so far:

8 Answers 8

If you’re sure your connection string is already well-formed like the one gnerkus described, the last thing you need to check is your password. If it’s contain non alphanumeric characters, maybe that’s the one who cause the issue. It seems either the Node.js or the way javascript work itself causing this (I’m not really sure since pg-admin can connect using my initial password just fine).

My password was contain ‘+’ and ‘/’ (acquired by creating a long json filled with gibberish and then hash it resulting base64 string) and I sure does receiving the same error like yours. Once I get rid of it (from my connection string and updating my database’s password), it’s working fine.

Oh, and . ‘=’ is accepted though. Because it seems the problem is with url decoding process at the database side. When I sent ‘+’ , I think it replaced by ‘ ‘ which will cause incorrect password. And the ‘/’ was causing malformed url which is the root cause of our error (which says not found). Take a look at this example.

I’m sure you’ll realize that there are extra ‘/’ which will cause wrong url break down. So, protocol:// user:pass@host / database changed into protocol:// [malformed user:pass@host] / [malformed database name] / [some gibberish] because of that extra ‘/’ .

If your colleague who access it using JSF can edit their connection string, I suggest to update the password to one which accepted by both. If they can’t, then you need to create another user/role with same access right but different password that can be used from Node.js.

EDIT: Or better yet, according to discussion here, try encode the password part of your connection string. They say it works. I didn’t bother to try it since I already change my password. Since you still has this issue, you might want to try it first before doing one of my two suggestions above.

Источник

XCUITest/WebDriverAgentRunner — getaddrinfo ENOTFOUND localhost localhost:8100 #7273

The problem

I am facing some proxyRequest Error:

ProxyRequestError: Could not proxy command to remote server. Original error: Error: getaddrinfo ENOTFOUND localhost localhost:8100

I got this issue while automating my app on iOS 10. I have setup all the dependencies and WebDriverAgent successfully.

It just happens that WebDriverAgentRunner launches on my device (iPhone 6) and after that this error appears.

Environment

  • Appium version — 1.6.0
  • Last Appium version that did not exhibit the issue (if applicable): NA
  • Desktop OS/version used to run Appium: MAC OS X 10.11 El Capitan
  • Node.js version (unless using Appium.app|exe):
  • Mobile platform/version under test: iOS 10.0.2
  • Real device or emulator/simulator: Real device
  • Appium CLI or Appium.app|exe: CLI

Details

Versions:
Node — v6.9.1
npm — 3.10.8
appium — 1.6.0

Starting appium server
appium -p 4725 —session-override

Server Caps:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(«platformName», «iOS»);
capabilities.setCapability(«platformVersion», «10.0.2»);
capabilities.setCapability(«deviceName», «iPhone»);
capabilities.setCapability(«newCommandTimeout», 100000);
capabilities.setCapability(«unicodeKeyboard», true);
capabilities.setCapability(«automationName», «XCUITest»);
capabilities.setCapability(«sendKeyStrategy», «setValue»);
capabilities.setCapability(«showXcodeLog», true);
capabilities.setCapability(«udid», pro.getProperty(«udid»));
capabilities.setCapability(«app», «/Users/magic/Desktop/Appium/myApp.ipa»);
wd = new IOSDriver(new URL(«http://0.0.0.0:4725/wd/hub»), capabilities);

Link to Appium logs

Code To Reproduce Issue [ Good To Have ]

The text was updated successfully, but these errors were encountered:

Источник

You will encounter various kinds of errors while developing Node.js
applications, but most can be avoided or easily mitigated with the right coding
practices. However, most of the information to fix these problems are currently
scattered across various GitHub issues and forum posts which could lead to
spending more time than necessary when seeking solutions.

Therefore, we’ve compiled this list of 15 common Node.js errors along with one
or more strategies to follow to fix each one. While this is not a comprehensive
list of all the errors you can encounter when developing Node.js applications,
it should help you understand why some of these common errors occur and feasible
solutions to avoid future recurrence.

🔭 Want to centralize and monitor your Node.js error logs?

Head over to Logtail and start ingesting your logs in 5 minutes.

1. ECONNRESET

ECONNRESET is a common exception that occurs when the TCP connection to
another server is closed abruptly, usually before a response is received. It can
be emitted when you attempt a request through a TCP connection that has already
been closed or when the connection is closed before a response is received
(perhaps in case of a timeout). This exception will usually
look like the following depending on your version of Node.js:

Output

Error: socket hang up
    at connResetException (node:internal/errors:691:14)
    at Socket.socketOnEnd (node:_http_client:466:23)
    at Socket.emit (node:events:532:35)
    at endReadableNT (node:internal/streams/readable:1346:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ECONNRESET'
}

If this exception occurs when making a request to another server, you should
catch it and decide how to handle it. For example, you can retry the request
immediately, or queue it for later. You can also investigate your timeout
settings if you’d like to wait longer for the request to be
completed.

On the other hand, if it is caused by a client deliberately closing an
unfulfilled request to your server, then you don’t need to do anything except
end the connection (res.end()), and stop any operations performed in
generating a response. You can detect if a client socket was destroyed through
the following:

app.get("/", (req, res) => {
  // listen for the 'close' event on the request
  req.on("close", () => {
    console.log("closed connection");
  });

  console.log(res.socket.destroyed); // true if socket is closed
});

2. ENOTFOUND

The ENOTFOUND exception occurs in Node.js when a connection cannot be
established to some host due to a DNS error. This usually occurs due to an
incorrect host value, or when localhost is not mapped correctly to
127.0.0.1. It can also occur when a domain goes down or no longer exists.
Here’s an example of how the error often appears in the Node.js console:

Output

Error: getaddrinfo ENOTFOUND http://localhost
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'http://localhost'
}

If you get this error in your Node.js application or while running a script, you
can try the following strategies to fix it:

Check the domain name

First, ensure that you didn’t make a typo while entering the domain name. You
can also use a tool like DNS Checker to confirm that
the domain is resolving successfully in your location or region.

Check the host value

If you’re using http.request() or https.request() methods from the standard
library, ensure that the host value in the options object contains only the
domain name or IP address of the server. It shouldn’t contain the protocol,
port, or request path (use the protocol, port, and path properties for
those values respectively).

// don't do this
const options = {
  host: 'http://example.com/path/to/resource',
};

// do this instead
const options = {
  host: 'example.com',
  path: '/path/to/resource',
};

http.request(options, (res) => {});

Check your localhost mapping

If you’re trying to connect to localhost, and the ENOTFOUND error is thrown,
it may mean that the localhost is missing in your hosts file. On Linux and
macOS, ensure that your /etc/hosts file contains the following entry:

You may need to flush your DNS cache afterward:

sudo killall -HUP mDNSResponder # macOS

On Linux, clearing the DNS cache depends on the distribution and caching service
in use. Therefore, do investigate the appropriate command to run on your system.

3. ETIMEDOUT

The ETIMEDOUT error is thrown by the Node.js runtime when a connection or HTTP
request is not closed properly after some time. You might encounter this error
from time to time if you configured a timeout on your
outgoing HTTP requests. The general solution to this issue is to catch the error
and repeat the request, preferably using an
exponential backoff
strategy so that a waiting period is added between subsequent retries until the
request eventually succeeds, or the maximum amount of retries is reached. If you
encounter this error frequently, try to investigate your request timeout
settings and choose a more appropriate value for the endpoint
if possible.

4. ECONNREFUSED

The ECONNREFUSED error is produced when a request is made to an endpoint but a
connection could not be established because the specified address wasn’t
reachable. This is usually caused by an inactive target service. For example,
the error below resulted from attempting to connect to http://localhost:8000
when no program is listening at that endpoint.

Error: connect ECONNREFUSED 127.0.0.1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (node:_http_client:442:9)
    at Socket.emit (node:events:526:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8000
}

The fix for this problem is to ensure that the target service is active and
accepting connections at the specified endpoint.

5. ERRADDRINUSE

This error is commonly encountered when starting or restarting a web server. It
indicates that the server is attempting to listen for connections at a port that
is already occupied by some other application.

Error: listen EADDRINUSE: address already in use :::3001
    at Server.setupListenHandle [as _listen2] (node:net:1330:16)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1465:7)
    at Function.listen (/home/ayo/dev/demo/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/ayo/dev/demo/main.js:16:18)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 3001
}

The easiest fix for this error would be to configure your application to listen
on a different port (preferably by updating an environmental variable). However,
if you need that specific port that is in use, you can find out the process ID
of the application using it through the command below:

Output

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    2902  ayo   19u  IPv6 781904      0t0  TCP *:3001 (LISTEN)

Afterward, kill the process by passing the PID value to the kill command:

After running the command above, the application will be forcefully closed
freeing up the desired port for your intended use.

6. EADDRNOTAVAIL

This error is similar to EADDRINUSE because it results from trying to run a
Node.js server at a specific port. It usually indicates a configuration issue
with your IP address, such as when you try to bind your server to a static IP:

const express = require('express');
const app = express();

const server = app.listen(3000, '192.168.0.101', function () {
  console.log('server listening at port 3000......');
});

Output

Error: listen EADDRNOTAVAIL: address not available 192.168.0.101:3000
    at Server.setupListenHandle [as _listen2] (node:net:1313:21)
    at listenInCluster (node:net:1378:12)
    at doListen (node:net:1516:7)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRNOTAVAIL',
  errno: -99,
  syscall: 'listen',
  address: '192.168.0.101',
  port: 3000
}

To resolve this issue, ensure that you have the right IP address (it may
sometimes change), or you can bind to any or all IPs by using 0.0.0.0 as shown
below:

var server = app.listen(3000, '0.0.0.0', function () {
  console.log('server listening at port 3000......');
});

7. ECONNABORTED

The ECONNABORTED exception is thrown when an active network connection is
aborted by the server before reading from the request body or writing to the
response body has completed. The example below demonstrates how this problem can
occur in a Node.js program:

const express = require('express');
const app = express();
const path = require('path');

app.get('/', function (req, res, next) {
  res.sendFile(path.join(__dirname, 'new.txt'), null, (err) => {
    console.log(err);
  });
  res.end();
});

const server = app.listen(3000, () => {
  console.log('server listening at port 3001......');
});

Output

Error: Request aborted
    at onaborted (/home/ayo/dev/demo/node_modules/express/lib/response.js:1030:15)
    at Immediate._onImmediate (/home/ayo/dev/demo/node_modules/express/lib/response.js:1072:9)
    at processImmediate (node:internal/timers:466:21) {
  code: 'ECONNABORTED'
}

The problem here is that res.end() was called prematurely before
res.sendFile() has had a chance to complete due to the asynchronous nature of
the method. The solution here is to move res.end() into sendFile()‘s
callback function:

app.get('/', function (req, res, next) {
  res.sendFile(path.join(__dirname, 'new.txt'), null, (err) => {
    console.log(err);
    res.end();
  });
});

8. EHOSTUNREACH

An EHOSTUNREACH exception indicates that a TCP connection failed because the
underlying protocol software found no route to the network or host. It can also
be triggered when traffic is blocked by a firewall or in response to information
received by intermediate gateways or switching nodes. If you encounter this
error, you may need to check your operating system’s routing tables or firewall
setup to fix the problem.

9. EAI_AGAIN

Node.js throws an EAI_AGAIN error when a temporary failure in domain name
resolution occurs. A DNS lookup timeout that usually indicates a problem with
your network connection or your proxy settings. You can get this error when
trying to install an npm package:

Output

npm ERR! code EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/nestjs failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org

If you’ve determined that your internet connection is working correctly, then
you should investigate your DNS resolver settings (/etc/resolv.conf) or your
/etc/hosts file to ensure it is set up correctly.

10. ENOENT

This error is a straightforward one. It means «Error No Entity» and is raised
when a specified path (file or directory) does not exist in the filesystem. It
is most commonly encountered when performing an operation with the fs module
or running a script that expects a specific directory structure.

fs.open('non-existent-file.txt', (err, fd) => {
  if (err) {
    console.log(err);
  }
});

Output

[Error: ENOENT: no such file or directory, open 'non-existent-file.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'non-existent-file.txt'
}

To fix this error, you either need to create the expected directory structure or
change the path so that the script looks in the correct directory.

11. EISDIR

If you encounter this error, the operation that raised it expected a file
argument but was provided with a directory.

// config is actually a directory
fs.readFile('config', (err, data) => {
  if (err) throw err;
  console.log(data);
});

Output

[Error: EISDIR: illegal operation on a directory, read] {
  errno: -21,
  code: 'EISDIR',
  syscall: 'read'
}

Fixing this error involves correcting the provided path so that it leads to a
file instead.

12. ENOTDIR

This error is the inverse of EISDIR. It means a file argument was supplied
where a directory was expected. To avoid this error, ensure that the provided
path leads to a directory and not a file.

fs.opendir('/etc/passwd', (err, _dir) => {
  if (err) throw err;
});

Output

[Error: ENOTDIR: not a directory, opendir '/etc/passwd'] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'opendir',
  path: '/etc/passwd'
}

13. EACCES

The EACCES error is often encountered when trying to access a file in a way
that is forbidden by its access permissions. You may also encounter this error
when you’re trying to install a global NPM package (depending on how you
installed Node.js and npm), or when you try to run a server on a port lower
than 1024.

fs.readFile('/etc/sudoers', (err, data) => {
  if (err) throw err;
  console.log(data);
});

Output

[Error: EACCES: permission denied, open '/etc/sudoers'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/etc/sudoers'
}

Essentially, this error indicates that the user executing the script does not
have the required permission to access a resource. A quick fix is to prefix the
script execution command with sudo so that it is executed as root, but this is
a bad idea
for security reasons.

The correct fix for this error is to give the user executing the script the
required permissions to access the resource through the chown command on Linux
in the case of a file or directory.

sudo chown -R $(whoami) /path/to/directory

If you encounter an EACCES error when trying to listen on a port lower than
1024, you can use a higher port and set up port forwarding through iptables.
The following command forwards HTTP traffic going to port 80 to port 8080
(assuming your application is listening on port 8080):

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

If you encounter EACCES errors when trying to install a global npm package,
it usually means that you installed the Node.js and npm versions found in your
system’s repositories. The recommended course of action is to uninstall those
versions and reinstall them through a Node environment manager like
NVM or Volta.

14. EEXIST

The EEXIST error is another filesystem error that is encountered whenever a
file or directory exists, but the attempted operation requires it not to exist.
For example, you will see this error when you attempt to create a directory that
already exists as shown below:

const fs = require('fs');

fs.mkdirSync('temp', (err) => {
  if (err) throw err;
});

Output

Error: EEXIST: file already exists, mkdir 'temp'
    at Object.mkdirSync (node:fs:1349:3)
    at Object.<anonymous> (/home/ayo/dev/demo/main.js:3:4)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -17,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: 'temp'
}

The solution here is to check if the path exists through fs.existsSync()
before attempting to create it:

const fs = require('fs');

if (!fs.existsSync('temp')) {
  fs.mkdirSync('temp', (err) => {
    if (err) throw err;
  });
}

15. EPERM

The EPERM error may be encountered in various scenarios, usually when
installing an npm package. It indicates that the operation being carried out
could not be completed due to permission issues. This error often indicates that
a write was attempted to a file that is in a read-only state although you may
sometimes encounter an EACCES error instead.

Here are some possible fixes you can try if you run into this problem:

  1. Close all instances of your editor before rerunning the command (maybe some
    files were locked by the editor).
  2. Clean the npm cache with npm cache clean --force.
  3. Close or disable your Anti-virus software if have one.
  4. If you have a development server running, stop it before executing the
    installation command once again.
  5. Use the --force option as in npm install --force.
  6. Remove your node_modules folder with rm -rf node_modules and install them
    once again with npm install.

Conclusion

In this article, we covered 15 of the most common Node.js errors you are likely
to encounter when developing applications or utilizing Node.js-based tools, and
we discussed possible solutions to each one. This by no means an exhaustive list
so ensure to check out the
Node.js errors documentation or the
errno(3) man page for a
more comprehensive listing.

Thanks for reading, and happy coding!

Check Uptime, Ping, Ports, SSL and more.

Get Slack, SMS and phone incident alerts.

Easy on-call duty scheduling.

Create free status page on your domain.

Got an article suggestion?
Let us know

Share on Twitter

Share on Facebook

Share via e-mail

Next article

How to Configure Nginx as a Reverse Proxy for Node.js Applications

Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Cover image for Error: GetAddrInfo ENOTFOUND localhost

Davide de Paolis

I am dropping this here as a reminder for my future self and for anyone that might encounter this weird error.

At work we are using nodejs and serverless framework to build a backend application.

To test it we just run it locally with

sls offline start --port 3001

Enter fullscreen mode

Exit fullscreen mode

Today, a colleague who was working remotely asked me if I could run the app locally because he was getting this error:
Error GetAddrInfo ENOTFOUND localhost

The info we found googling were mostly related to Webpack or Angular, which we are not using but had in common some problems in the configuration of etc/hosts.

Confronting that configuration on my workstation and his laptop at home, I had:

where his contained info about OpenVN Client SSL but nothing about localhost. Probably when he configured the VPN to work remotely he overwrote the previous content, he added to his file this one line:

127.0.0.1 localhost

Enter fullscreen mode

Exit fullscreen mode

and everything started to work.

Additional tip:

  • To edit the file: go to home directory (

    cd ~

    ) and open vim

    sudo vi /etc/hosts

    then press I and start editing the file.

exiting vim

  • To save and exit vim: press ESC then

    :wq

    or

    :q!

    if you just want to exit without saving.
    More cheatsheets here

Hey 😍

Want to help the DEV Community feel more like a community?

Head over to the Welcome Thread and greet some new community members!

It only takes a minute of your time, and goes a long way!

Понравилась статья? Поделить с друзьями:
  • Error get class hints
  • Error get alias что это
  • Error get alias тильда
  • Error get alias перевод
  • Error get alias tilda ошибка