question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Client socket.io.js not found 404

See original GitHub issue

Hi, I’m trying to use socket.io(0.9.6) with express (3.00b4) and node (0.8.1). On a localhost.

When I create the base epxress server the socket.io client is not found.

I’ve tried uninstalling everything and reinstalling it.

This is my app.js code

var socket = require('socket.io')
var express = require('express')
  , routes = require('./routes')
  , http = require('http');


var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('your secret here'));
  app.use(express.session());
  app.use(app.router);
  app.use(require('less-middleware')({ src: __dirname + '/public' }));
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});


var server = http.createServer(app);

var io = socket.listen(server)

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

33reactions
rauchgcommented, Jun 30, 2012
http.createServer(app).listen(app.get('port'), function(){})

That’s your server. Not:

var server = http.createServer(app);

You’re basically creating two http servers, the latter of which is not listening on any port. It’s a zombie.

Turn your code into this:

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

var io = socket.listen(server);
io.sockets.on('connection', function () {
  console.log('hello world im a hot socket');
});
1reaction
sathnindukcommented, Aug 22, 2021

Amazing!!! 🎉🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

GET/ socket io not found 404 - node.js - Stack Overflow
The problem is in your server code. You bind socket.io to http , but only app listens on the port (5000). You need...
Read more >
Error node js socket io socket io js not found - Edureka
Getting the error: /socket.io/socket.io.js 404 (Not Found) Uncaught ReferenceError: io is not defined. My code is:
Read more >
Socket.io 404 Not Found when using express server
io.js” file in my “views” folder, but I have no idea if it auto-generated, or if I found one online and threw it ......
Read more >
Node.js Socket.io Error when trying to connect client to server
src="/socket.io/socket.io.js". and client throws the Errors: Failed to load resource: the server responded with a status of 404 (Not Found).
Read more >
Client Initialization | Socket.IO
In case your front is not served from the same domain as your server, you have to pass the URL of your server....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found