Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js socket.io.js not found or io not defined

I'm trying to run a node.js application on my freebsd server, but I can't get the socket.io library to work with it. I've tried including:

    <script src="/socket.io/socket.io.js"></script>

Which gives a 404 error, and if i link directly to the file (i.e. where it is in my public_html folder) I get the io not defined error.

Thanks in advance

like image 632
Jack TC Avatar asked Dec 07 '22 14:12

Jack TC


1 Answers

Try creating another node.js application that has this single line in it and then run it with node.js

var io = require('socket.io').listen(8000);

Then in your browser visit http://127.0.0.1:8000 and you should get the friendly "Welcome to socket.io." greeting. If you are getting this then socket.io is running and will serve the socket.io.js file.

The only other thing that I can think of that might be happening is that you might not be linking to the alternate port in your client file. Unless you're running the socket.io server on express which is running on port 80. For now create a client file that has the script source for socket.io set to

<script src="http://127.0.0.1:8000/socket.io/socket.io.js"> </script>

This should connect to the socket.io server running on port 8000 and get the socket.io.js file.

like image 151
sonikarc Avatar answered Dec 30 '22 10:12

sonikarc