Chapter 2. Building a multiroom chat application


This chapter covers

  • A first look at various Node components
  • A sample real-time application using Node
  • Server and client-side interaction

In chapter 1, you learned how asynchronous development using Node differs from conventional synchronous development. In this chapter, we’ll take a practical look at Node by creating a small event-driven chat application. Don’t worry if the details in this chapter seem over your head; our intent is to demystify Node development and give you a preview of what you’ll be able to do when you’ve completed the book.

This chapter assumes you have experience with web application development, have a basic understanding of HTTP, and are familiar with jQuery. As you move through the chapter, you’ll

  • Tour the application to see how it will work
  • Review technology requirements and perform the initial application setup
  • Serve the application’s HTML, CSS, and client-side JavaScript
  • Handle chat-related messaging using Socket.IO
  • Use client-side JavaScript for the application’s UI

Let’s start with an application overview—you’ll see what the application will look like and how it’ll behave when it’s completed.

2.1. Application overview

The application you’ll build in this chapter allows users to chat online with each other by entering messages into a simple form, as shown in figure 2.1. A message, once entered, is sent to all other users in the same chat room.

Figure 2.1. Entering a message into the chat application

2.2. Application requirements and initial setup

2.3. Serving the application’s HTML, CSS, and client-side JavaScript

2.4. Handling chat-related messaging using Socket.IO

2.5. Using client-side JavaScript for the application’s user interface

2.6. Summary