Server
var express = require('express'); var app = express(); var logger = require('morgan'); var server = require('http').Server(app); var io = require('socket.io')(server); app.use(express.static('public')); app.use(logger('dev')); server.listen(14000); app.get('/', function (req, res) { res.sendFile(__dirname + '/public/index.html'); }); io.on('connection', function (socket) { console.log("Connected : " + socket.client.id); });
Client
$(document).ready(function () { var socket = io.connect('http://localhost:14000'); });
References
https://socket.io/docs/#Using-with-Express