Skip to content

Instantly share code, notes, and snippets.

/app.js Secret

Created January 16, 2018 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7f5ad3b51e867edd1450a0fb1e656c26 to your computer and use it in GitHub Desktop.
Save anonymous/7f5ad3b51e867edd1450a0fb1e656c26 to your computer and use it in GitHub Desktop.
Socket.IO 2 Express
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on("increment", (counter) => {
console.log("increment");
io.sockets.emit('COUNTER_INCREMENT', counter + 1)
})
socket.on("decrement", (counter) => {
console.log("decrement");
io.sockets.emit('COUNTER_DECREMENT', counter - 1)
})
});
http.listen(5000, function(){
console.log('listening on *:5000');
});
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment