Websockets/react - net::ERR_CONNECTION_REFUSED

Hi there,

I am coding along the following : https://www.youtube.com/watch?v=ZwFA3YMfkoc&t=234s

At the 1 hour 16 stage, i have come across an error when i try to enter the chat message:

GET http://localhost:5000/socket.io/?EIO=3&transport=polling&t=MvziWt_ net::ERR_CONNECTION_REFUSED
TypeError: Cannot read property 'room' of undefined
    at Socket.socket.on (C:\Users\Yaz\react projects\chat-app-3\server\index.js:38:16)
    at Socket.emit (events.js:198:13)
    at C:\Users\Yaz\react projects\chat-app-3\server\node_modules\socket.io\lib\socket.js:528:12
    at process._tickCallback (internal/process/next_tick.js:61:11)
[nodemon] app crashed - waiting for file changes before starting...

I can’t quite see what is happening and why it would throw an error (new to sockets). the error is either in the front-end (Chat.js) or server (index.js):

Completed repo is below:

I would appreciate your help to see why is there an error so i can understand sockets more.


I’m having the same issue and following the same video, did you ever figure it out?


I was facing a similar issue.
Turns out , it has got to do something with the port number 5000.
I changed my port to some random port (3030 for eg.) and everything worked as expected.

Hi there, I faced a similar issue
Just add this to your server
Const io=socketio(server,{cors:{
This worked for me

1 Like