/errors/dns/getaddrinfo-enotfound
Error: getaddrinfo ENOTFOUND (DNS lookup failed)
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- DNS
- exit code
- 1
- versions
- Node.js 18+
- os
- any
getaddrinfo ENOTFOUND <host> means the operating system's resolver could not turn the host name into an IP address. The request never left the machine. Check the spelling, make sure you pass a host name and not a whole URL, and test DNS from the same environment.
Reproduce the error
.invalid is a reserved top-level domain that never resolves (RFC 2606):
node -e 'require("dns").lookup("nonexistent.invalid", (err) => console.log(err.code, "-", err.message))'Output
ENOTFOUND - getaddrinfo ENOTFOUND nonexistent.invalid
A URL instead of a host name
A frequent cause in code is passing a URL where only a host is expected:
node -e '
const http = require("http");
http.get({ host: "https://example.com/api" }).on("error", (e) => console.log(e.code, "-", e.message));'Output
ENOTFOUND - getaddrinfo ENOTFOUND https://example.com/api
Use http.get("https://example.com/api") or new URL(...) instead of putting the URL in host.
Check DNS from the same environment
nslookup api.example.com
dig +short api.example.com
getent hosts api.example.com # what the system resolver (and Node.js) sees on LinuxENOTFOUND vs EAI_AGAIN
| Code | Meaning | Usual cause |
|---|---|---|
| ENOTFOUND | the name does not exist (NXDOMAIN) | typo, wrong domain, private zone not visible |
| EAI_AGAIN | temporary resolver failure | no network, DNS server unreachable, timeout |
Sources
Related pages
errors · jsonSyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSONJSON.parse fails with Unexpected token '<' when the response is an HTML page, usually an error or login page, not JSON. Check the status and content type first.glossary · httpWhat does idempotent mean in HTTP?An HTTP method is idempotent if repeating the same request has the same effect on the server as sending it once: GET, PUT and DELETE are, POST is not.codes · httpHTTP status codes: 1xx to 5xx with meaning and common causesHTTP status codes explained: 200 and 204, the redirects 301 to 308, client errors 400 to 429 and server errors 500 to 504, each with its most common cause.