Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello Socket!');
var server = require('http').createServer(app).listen(3000, function() {
console.log(`Listening on port 3000 with http`);
const socketio = require('')
const io = socketio(server)
io.on('connection', (socket) => {
console.log('Client connected');
// echo received chat message
socket.on('chat', function(msg){
console.log('Recv chat:', msg)
io.emit('chat', msg);
socket.on('disconnect', () => {
console.log('Client disconnected');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment