Last Updated: February 25, 2016
· ihcsim
130921 tcl 103 s

A Simple Chat Server Using nodejs express and socket.io

This example uses nodejs, express 3.1.0 and socket.io 0.9.13. to build a simple chat server: 1 file, 10 statements. This node stuff is pretty slick!

var express = require('express');
var app = express();
var server = require('http').createServer(app).listen(7000);
var io = require('socket.io').listen(server);
io.sockets.on('connection', function(client){
    client.on('message', function(err, msg){
        client.broadcast.emit('message', msg);

You can find the full source at https://github.com/ihcsim/node-tutorial/blob/master/js/chat.js

Say Thanks