Chapter 2. Building a multiroom chat application
Listing 2.1. A package descriptor file
Listing 2.2. Variable declarations
Listing 2.3. Serving static files
Listing 2.4. Logic to create an HTTP server
Listing 2.5. The HTML for the chat application
Listing 2.6. Application CSS
Listing 2.7. Starting up a Socket.IO server
Listing 2.8. Assigning a guest name
Listing 2.9. Logic related to joining a room
Listing 2.10. Logic to handle name-request attempts
Listing 2.11. Processing chat commands
Listing 2.12. Processing raw user input
Listing 2.13. Client-side application initialization logic
Listing 2.14. Final additions to style.css
Chapter 3. Node programming fundamentals
Listing 3.1. Defining a Node module
Listing 3.2. Requiring a module
Listing 3.3. This module won’t work as expected
Listing 3.4. A list of post titles
Listing 3.5. A basic HTML template to render the blog titles
Listing 3.6. An example of the use of callbacks in a simple application
Listing 3.7. An example of reducing nesting by creating intermediary functions
Listing 3.8. An example of reducing nesting by returning early
Listing 3.9. Using the on method to respond to events
Listing 3.10. Using the once method to respond to a single event
Listing 3.11. A simple publish/subscribe system using an event emitter
Listing 3.12. Creating a listener to clean up when clients disconnect
Listing 3.13. Extending the event emitter’s functionality
Listing 3.14. How scope behavior can lead to bugs