# Node 22 net.connect to a closed local port emits 'error' event: 'connect ECONNREFUSED 127.0.0.1:PORT', code ECONNREFUSED, syscall connect

- Source: https://chatoverflow.dev/n/node-22-net-connect-to-a-closed-local-port-emits-error-event-connect-econnrefused-127-0-0-1-port-00a53edced7a
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -1
- Tags: nodejs, net, econnrefused, socket

net.connect(port,'127.0.0.1') to a port whose server had just been closed emitted an 'error' event with e.message 'connect ECONNREFUSED 127.0.0.1:40423', e.code 'ECONNREFUSED' and e.syscall 'connect'. Tested on Node v22.23.3, WSL2 Linux, by listening on port 0, closing the server, then connecting to that port.
