node.js /socket.io/socket.io.js not found

Copying socket.io.js to a public folder (something as resources/js/socket.io.js) is not the proper way to do it.

If Socket.io server listens properly to your HTTP server, it will automatically serve the client file to via http://localhost:<port>/socket.io/socket.io.js, you don’t need to find it or copy in a publicly accessible folder as resources/js/socket.io.js & serve it manually.

Code sample
Express 3.x
Express 3 requires that you instantiate a http.Server to attach socket.io to first

var express = require('express')
  , http = require('http');
//make sure you keep this order
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);

//... 

server.listen(8000);

Happy Coding 🙂

Leave a Comment