Node.js + Socket.IO for real-time chat

This is a follow up to the previous lesson,Node.js, Comet, real-time chat — a great first project. Although useful, it’s not required to have gone through it.

Let’s take that real-time chat we made and convert it to use Socket.IO.

Node.js, Comet, real-time chat — a great first project

For my own learning process, I usually start by reading a bunch of articles on a topic. Once I feel I have a basic understanding, I find that building something really improves my knowledge and retention about the subject quickly. I also know once I’ve achieved that milestone (you could call it a beyond-Hello-World program), it becomes a lot easier to learn the more advanced concepts regarding the subject.

Taking that philosophy, I’m sharing my first experience building a NodeJS project — a real-time group chat. There’s a few reasons I thought this would be a good project:

  • Managing many requests and responses is what NodeJS excels at, assuming that waiting for I/O and user responses is the key slowdown
  • I’ve been meaning to learn more about Comet techniques (to do HTTP push)
  • It’s a pretty small project

The idea is for you to try to code this on your own. Peek at my code as necessary, but take a stab at doing it yourself first.

Understanding Connect and Middleware

If you’ve started learning about using common Node frameworks, such as Express, you’ve probably heard about Connect and middleware.  Most tutorials gloss over these concepts, so this is a stab at explaining it.

This tutorial describes middleware for Node.js, focusing on the Connect framework.  It covers how to add basic features like session state, routing, authorization, etc to a Node web server.

Prerequisites:  basic node.js knowledge.  To get up to speed read A Beginner’s Tutorial for Learning Node.js.

A Beginner’s Tutorial for Node.js

I’ve been spending some time learning Node.js.  Since there isn’t a clear definitive guide out there, I decided to put together a some of the best online resources I’ve found.

The goal of this tutorial is to bring a beginner fully up to speed with Node.  At the end you will understand Node’s eventing model and be able to create a site using the most popular modules and frameworks.  It should take about 4 to 5 hours total.

Prerequisites:  some knowledge of javascript in particular and web programming in general.