Created
June 16, 2013 20:55
-
-
Save cybrown/5793410 to your computer and use it in GitHub Desktop.
Node.js + express + socket.io base project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function () { | |
var app = require('express')(); | |
var server = require('http').createServer(app); | |
var io = require('socket.io').listen(server); | |
server.listen(3000); | |
app.use(express.static(__dirname + '/public')); | |
app.use(express.bodyParser()); | |
app.use(express.cookieParser('cookieparsersecret')); | |
app.use(express.cookieSession({secret: 'cookiesessionsecret'})); | |
app.use(express.methodOverride()); | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); | |
socket.on('my other event', function (data) { | |
console.log(data); | |
}); | |
}); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect(''); | |
socket.on('news', function (data) { | |
console.log(data); | |
socket.emit('my other event', { my: 'data' }); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment