WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED node.js node.js

WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED


Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server).However the same should work fine with Firefox.


You need to use ws://yourIp:9090/, where yourIP is like 192.168.?.?.


try to change the port to 8080

const ws = new WebSocket('ws://localhost:8080/chat')