I have been playing with node.js (0.8.14), socket.io (0.9.11) and express (3.0.3) for the couple of days but kept running into an issue where the client socket.io.js file would not load. It just kept 404ing; and it was really pissing me off… I spent some time researching why it was not working; there were a lot of “answers” but none of them worked, shocking.
I honestly spent more time trying to find the answer to this issue then I did writing most of core PHP functionality of submitting and retrieving backend data between the web server and the push engine. I finally came across someone’s fix while tirelessly searching github issues for the correct answer. See the sample code after the jump.
var express = require('express')
,app = express();
app.configure(function(){
app.use(express.bodyParser());
app.use(express.static(__dirname + '/'));
});
var server = app.listen(8080);
var io = require('socket.io').listen(server);
Now, I can see WHY this works, but I don’t understand WHY it needs to work like this. I am sure there is a better way going about it, but I honestly could not find another answer that actually worked. So, since it works for me now, I am just going to roll with it so I can test aspects of my application… I am sure after more research and experience there will be a better solution that pops up.
Anyway, I know I may be late to this but it plagued me long enough that I had to post something about it.
Source: Sreekumar | Sreekumar GitHub | socket.io Issue 843 on GitHub