Skip to content

Instantly share code, notes, and snippets.

@dbainbridge
Created April 19, 2012 20:48
Show Gist options
  • Star 66 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save dbainbridge/2424055 to your computer and use it in GitHub Desktop.
Save dbainbridge/2424055 to your computer and use it in GitHub Desktop.
How to use socket.io with Express 3
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http');
var app = express();
var server = app.listen(3000);
var io = require('socket.io').listen(server);
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
console.log("Express server listening on port 3000");
@itsjustcon
Copy link

Worked like a charm. Thanks!

@mohsen1
Copy link

mohsen1 commented Apr 20, 2013

Thank you, it was helpful. It's number one result for "using express 3 and socket.io".

@justaurelia
Copy link

Thanks !!!!

@fesja
Copy link

fesja commented Sep 1, 2013

thanks!

@satbirdd
Copy link

satbirdd commented Oct 4, 2013

the 7th line"http = require('http');", ti's neccesary? i did't see you use http

@dfkuro
Copy link

dfkuro commented Dec 10, 2013

Thanks, it works.

@thomasbrueggemann
Copy link

Perfect, thank you!

@fmoris
Copy link

fmoris commented Dec 27, 2013

Thanks!

@drjova
Copy link

drjova commented Mar 12, 2014

Thanks!

@DrDyne
Copy link

DrDyne commented Mar 16, 2014

Thanks a lot !

@pomerus
Copy link

pomerus commented Apr 13, 2014

Thank you !

@quinvit
Copy link

quinvit commented May 2, 2014

Thank you !

@vishakashoka
Copy link

You Rock! Thank you

@asccigcc
Copy link

Thank you!

@heanfig
Copy link

heanfig commented Aug 18, 2014

Excelent, Thank You :)

@scottglenblanch
Copy link

Thanks a ton!

@mackeyguenther
Copy link

👍

@titechnologies
Copy link

Good one... Thanks alot!!!

@mikes16
Copy link

mikes16 commented Mar 11, 2015

Niceeee!! Thank you!! ;)

@bsautron
Copy link

Excellent

@peheje
Copy link

peheje commented Jan 18, 2016

Works like a charm. Stackoverflow posts failed to help me, but this works like a charm.

@jpna
Copy link

jpna commented Jan 10, 2017

Very helpful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment