Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io.js not found

For some reason my node server cannot serve the route /socket.io/socket.io.js, I always get a 404 error.
I tried compiling different node versions (current is 0.6.13 which also runs on server, where it actually works).
From the app.js I get info: socket.io started and no error when trying to call the socket.io.js.

I try it from localhost and port 8000 and I use the express framework

This is the code from app.js:

var express = require('express')   , app = require('express').createServer()   , io = require('socket.io').listen(app, { log: true });  app.listen(8000);  app.configure(function() {     app.use(express.static(__dirname + '/public'));     app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); });  io.sockets.on('connection', function (socket) {    // all other stuff here 
like image 952
dan-lee Avatar asked Apr 17 '12 12:04

dan-lee


People also ask

Does Socket.IO require node JS?

It requires almost no basic prior knowledge of Node.JS or Socket.IO, so it's ideal for users of all knowledge levels.

How do I run a Socket.IO in node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .

What is Socket.IO Socket.IO JS?

Socket.io is a JavaScript library that enables real-time, bi-directional and event driven communication between the client and server.


1 Answers

Please check your Express version. Express recently is updated to 3.0alpha which API was changed. If 3.0 you can change your code to something likes this:

var express = require('express')   , http = require('http');  var app = express(); var server = http.createServer(app); var io = require('socket.io').listen(server);  ...  server.listen(8000); 

Same issue with connect: https://github.com/senchalabs/connect/issues/500#issuecomment-4620773

like image 97
nguyenkha Avatar answered Oct 01 '22 07:10

nguyenkha