title: How to develop a large chat application with Socket.io and Node.js
body: <p>I've been working with Socket.io over the past few months, developing a fairly complex chat application with chat rooms, kicking/banning/moderators/friends/etc. </p>
  
  <p>Over the course of development, I've rewritten the app several times and I'm still fighting with my code.</p>
  
  <p>I really like JavaScript, but I find it really hard to maintain the application as it grows. I've read through huge amounts of "tutorials" on how to write chat applications, but they all cover just the most basic aspects. Same goes for all example apps on GitHub, and even most chat applications I found on the web (most of them are just simple IM without any user management).</p>
  
  <p>Some use cases just seem too ridiculous to me, for example kicking a user from a room.</p>
  
  <ul>
  <li>moderator clicks on a kick button -> emit event to the server</li>
  <li>the server pairs the username with a socket (or just broadcast to all users and filter on the client side) -> emit to him kicked event</li>
  <li>the user emits a logout event to the server and is also displayed a message that he was kicked (logout is just my implementation of punishment)</li>
  <li>the user is removed from the chat room's user list -> emit current list of users to all users in the room</li>
  </ul>
  
  <p>This doesn't seem too complex, but when I add all the callbacks that happen on the client side to manage the UI (since I use AngularJS, I use events to communicate between controllers), and also ton of callbacks on the server side, since everything is non-blocking, I find this really hard to test.</p>
  
  <p>There's another problem on the client side, where I have to listen for the socket events in multiple places, so I have to have a kind of singleton global socket object, and hook event listeners in multiple places to it.</p>
  
  <p><strong>Am I doing something wrong, or is this callback hell the result of working with websockets with no way around it?</strong></p>
  
  <p>Are there any ways to make developing applications like this easier? For example alternative technology to Socket.io? So far I only found <a href="https://github.com/Flotype/now">NowJS</a>, which has last commit 5 months ago, and <a href="http://meteor.com/">meteor</a>, which is really cool, but looking at the website it doesn't really seem to be stable.</p>