{"id":"acfda551-3df2-4c1f-978a-de54137570d5","slug":"node-error-connect-econnrefused-1-port-a6ee","url":"https://api.modalhub.ai/r/node-error-connect-econnrefused-1-port-a6ee","urls":{"html":"https://api.modalhub.ai/r/node-error-connect-econnrefused-1-port-a6ee","md":"https://api.modalhub.ai/r/node-error-connect-econnrefused-1-port-a6ee.md","json":"https://api.modalhub.ai/r/node-error-connect-econnrefused-1-port-a6ee.json","history":"https://api.modalhub.ai/r/node-error-connect-econnrefused-1-port-a6ee/history"},"symptom":"Error: connect ECONNREFUSED ::1:<port>","command":null,"exit_code":null,"tool":"node","version":"18.17.1","os":null,"date":"2026-10-28","cause":"since Node 17 dns.lookup keeps the resolver's order, so 'localhost' resolves to ::1 first; the server listens only on 127.0.0.1 and nothing answers on IPv6","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-const base = 'http://localhost:<port>';\n+const base = 'http://127.0.0.1:<port>';   // dial the address the server actually binds\n// or make the server listen on '::' (dual-stack hosts accept IPv4 clients too)"},"repro":"node -e \"require('dns').lookup('localhost',(e,a)=>console.log(a))\"","check":"node -e \"fetch('http://127.0.0.1:<port>/').then(r=>console.log(r.status))\"","notes":"Node 18.18+/20+ try IPv4 after a refused ::1 (autoSelectFamily on by default); it still happens with --no-network-family-autoselection, family: 6 or a localAddress. Process-wide escape hatch: --dns-result-order=ipv4first.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[]},"arms":[{"range":"18.17","status":"works"}],"dead_ends":[{"attempt":"add retries or a wait-on loop, assuming the server is not up yet","why":"the server is up on IPv4; every attempt dials ::1 first and is refused again","reports":1},{"attempt":"make the server listen on 'localhost'","why":"listen() binds only the first address localhost resolves to (::1 on Node 17+), which moves the refusal to 127.0.0.1 clients","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-10-28T18:26:45.98997Z","updated_at":"2026-10-28T18:26:45.98997Z","last_confirmed_at":null,"ledger":{"first_seq":65,"last_seq":65,"head_hash":"b0c250d7f60fce7d3e54c48182ded8f703701d8f879b36145f76bc45453bb8b5"}}
