Short answer
Check which kind it is. connect ETIMEDOUT means the connection was never set up: the host or port is wrong, a firewall drops the traffic, or a cloud database only accepts allowlisted IP addresses. Test the port from the same machine with nc -vz host port. read ETIMEDOUT means an open connection went silent, often an idle connection dropped by a load balancer or NAT. An AggregateError with one ETIMEDOUT per address means every address Node.js tried (IPv6 and IPv4) timed out; if the host works from elsewhere, a slow network or broken IPv6 is the usual cause, so raise the attempt timeout.
Why the connection timed out, and the fix
01
connect ETIMEDOUT: a firewall, allowlist or wrong port
“ETIMEDOUT (Operation timed out): A connect or send request failed because the connected party did not properly respond after a period of time.” Node.js, Errors: common system errors
Managed databases (Postgres, MySQL, Redis, MongoDB Atlas) and private servers usually drop traffic from addresses that are not allowlisted, and a cloud firewall or security group does the same. A wrong port on a firewalled host looks identical. Test the exact host and port from the machine that fails, then allow that machine’s outbound IP in the provider’s network settings.
nc -vz db.example.com 5432 # "succeeded" = reachable; a long wait then "timed out" = dropped on the way # Windows: Test-NetConnection db.example.com -Port 5432 curl -s https://api.ipify.org # the outbound IP to allowlist02
AggregateError: several ETIMEDOUT attempts
“The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the autoSelectFamily option.” Node.js, net: socket.connect() options
Node.js 20 and newer try each address of a hostname (IPv6 and IPv4) in turn and give each attempt 250 milliseconds by default. On a slow or high-latency network every attempt can time out, and the error lists them all. Give each attempt more time, or, when IPv6 is broken on that network, try IPv4 first with --dns-result-order=ipv4first.
// in code, before the first connection require('node:net').setDefaultAutoSelectFamilyAttemptTimeout(1000); // or from the command line node --network-family-autoselection-attempt-timeout=1000 server.js03
read ETIMEDOUT: an open connection went silent
The connection worked, then the other side stopped answering. Load balancers, NAT gateways and serverless platforms drop idle connections without telling either end, so the next request on a pooled connection times out. Keep idle timeouts in your client shorter than the server’s, and retry requests that are safe to repeat.
04
Set your own timeouts so it fails fast
“The timeout is the number of milliseconds before the request times out.” Axios, Request config: timeout
An ETIMEDOUT from the operating system can take a long time to arrive. Set a timeout in the client so a dead host fails quickly with a clear error: the timeout option on http.request, timeout in Axios, or AbortSignal.timeout() with fetch. With http.request, the timeout option only emits a timeout event, so add a handler that calls req.destroy().
const res = await fetch(url, { signal: AbortSignal.timeout(10_000) }); // Axios axios.get(url, { timeout: 10_000 }); // http.request const req = http.request(url, { timeout: 10_000 }); req.on('timeout', () => req.destroy(new Error('Request timed out')));
Checked against the vendor’s docs on : Node.js: Errors (common system errors); Node.js: net (autoSelectFamily); Node.js: http.request() timeout; Axios: Request config.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: ECONNREFUSED: connection refused · Node.js ECONNRESET (“socket hang up”) · Axios “Network Error” · “self-signed certificate in certificate chain”