In this post we'll be looking at a smallest possible chat application to get you started. with AngularJS boilerplate

Sander Sink has truly been a godsend to making realtime applicaions. What used to require writing complex code, ajax polling and other tricks of the trade is now a few lines of code. And it’s fast too - in fact we have a situation where client sends a POST request to python server, which in turn is passed to node server via redis pub/sub and that in turn send a message to the client with The interesting bit is that although the round-trip involves more components, it delivers the message back to client before the response is received. While pure HTTP implementation with network latency in the mix might win the race, it is still a valid contender.

I often find myself experimenting on some concept where I need a quick and simple boilerplate to get me going - setting it all up takes time after-all. There are great demos out there, but they often cover more ground than necessary, what I am mostly interested in is the bare minimum working backbone that I can build upon. So here is a stripped-down chat application in just 2 files, doesn’t even contain an http server!


var io = require('').listen(3000);

io.on('connection', function(socket){
  socket.on('message', function(msg){
    io.emit('message', msg);

console.log("Server up!");


Since Angular is not aware of socket receiving a message, we need to wrap the $scope update in an $apply function so that angular would pick it up.

<!doctype html>
<html ng-app="myApp">
    <script src=""></script>
    <script src=""></script>
  <body ng-controller="myAppCtrl">
    <textarea ng-model="messages" rows=15 cols=80></textarea><br/>
    <input ng-model="message"></input>
    <button ng-click="send()">Send</button>
      var app = angular.module("myApp", []);
      app.controller("myAppCtrl", function($scope) {
        var socket = io('http://localhost:3000');
        $scope.messages = '';
        $scope.send = function(){
          socket.emit('message', $scope.message);
          $scope.message = '';
        socket.on('message', function(message){
            $scope.messages += message + "\n";


npm install
node server.js