var express = require('express'); //import statement var app = express(); var server = app.listen(process.env.PORT); //listen on port 3000 app.use(express.static('public')); //the files that a visitor gets to see are the ones in 'public' folder console.log("My socket server is running."); var socket = require('socket.io'); //import statement var io = socket(server); //create an instance of a socket, and pass it our server io.sockets.on('connection', newConnection); //new connection event function newConnection(socket){ console.log('new connection: ' + socket.id); console.log(socket.id); socket.on('mouse', mouseMsg); //upon receiving the message named 'mouse', trigger function mouseMsg function mouseMsg(data){ socket.broadcast.emit('mouse', data); // io.sockets.emit('mouse', data); //this way would also include client that sent the message console.log(data); } }