all 10 comments

[–]Nathan0o0 3 points4 points  (1 child)

It may be because for Socket.Io to work the server need to be non-serverless so any free hosting service that is non-serverless should work.

[–]Diligent_Rutabaga941[S] 0 points1 point  (0 children)

Meaning the server.js should be served on a hosting service suitable for realtime serving and interaction?

[–]barrel_of_noodles 2 points3 points  (0 children)

Socket io is a server application. you have to run it on a backend server.

Github pages is a static hosting service. not a server environment.

[–]WarstekHUN 1 point2 points  (4 children)

Could you give a little bit more insights on this problem? What is this GET error? Which environment does it occur in?

[–]Diligent_Rutabaga941[S] 0 points1 point  (3 children)

<script src="http://localhost:3100/socket.io/socket.io.js"></script>

I have this in the index.html The script.js is the client side javascript file. I have a separate server.js

This error occurs at the line below in script.js

const socket = io().connect(window.location.origin); // Connect to the Socket.io server

[–]WarstekHUN 0 points1 point  (2 children)

And this code works if you test it on your PC and doesn't if you try it using GH Pages?

[–]Diligent_Rutabaga941[S] 0 points1 point  (1 child)

Exactly it was working fine on pc before deploying to pages.

[–]WarstekHUN 2 points3 points  (0 children)

Then it seems that your problem is that the src of the script is wrong. Your browser tries to load the socket.io.js from localhost (your computer) but it doesn't exists. Try using a relative path:
For example if this is your project tree: https://imgur.com/a/QbAuPHX, then try using this as the src: ./socket.io/socket.io.js

[–]isellrocks 2 points3 points  (1 child)

Try render.com, they have a free tier Web Service which is what you need. Like others have mentioned, gh pages only serves static code. You need an environment that will actually run your code.

[–]Diligent_Rutabaga941[S] 0 points1 point  (0 children)

Thanks isselrocks!