var server=require('http').createServer(handler); var io = require('socket.io').listen(server); var fs=require('fs'); server.listen(80); function handler(req,res){ fs.readFile(__dirname+'/helloworld.html', function(err, data){ if(err){ res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.on('msg', function (data,fn) { console.log('received message from client:'+data); fn('The server has been successfully received your message:'+data); }); });