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
Written by Ivan Sim
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ivanhcsim
Authors
ihcsim
751.3K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#