List of Figures

Chapter 1. What is Express?

Figure 1.1. Comparing asynchronous code (like Node.js) to synchronous code. Note that asynchronous code can complete much faster, even though you’re never executing your code in parallel.

Figure 1.2. The flow of a request through a Node.js web application. Circles are written by you as the developer; squares are out of your domain.

Figure 1.3. The flow of a request through an Express. Once again, circles are code you write and squares are out of your domain.

Figure 1.4. Two requests flowing through middleware functions. Notice that middleware sometimes continues on, but sometimes it responds to requests.

Figure 1.5. An example diagram showing how a large application could be broken up into routers

Chapter 2. The basics of Node.js

Figure 2.1. The result of running our “Hello, world!” code

Figure 2.2. Comparing an asynchronous world (like Node) to a synchronous one

Figure 2.3. A simple Hello World app

Figure 2.4. The console from your Hello World app might look something like this.

Chapter 3. Foundations of Express

Figure 3.1. A request without middleware

Figure 3.2. A request with middleware

Figure 3.3. Two requests flowing through middleware functions. Note that middleware sometimes continues on but sometimes responds to requests.

Figure 3.4. The guestbook homepage

Figure 3.5. The page to write a new entry in the guestbook

Chapter 4. Middleware

Figure 4.1. When working with Node by itself, you have one function that gives you a request object representing the incoming request and a response object representing the response node should send back to the client.

Figure 4.2. When working in Express, the one request handler function is replaced with a stack of middleware functions.

Figure 4.3. All middleware functions have the same signature with three functions: request, response, and next.

Figure 4.4. The middleware stack of our static file server application

Figure 4.5. The directory structure of static-file-fun

Figure 4.6. Our application’s logs after adding Morgan

Figure 4.7. If all goes well, error-handling middleware will be skipped.

Figure 4.8. If there’s an error, Express will skip straight to the error-handling middleware.

Chapter 5. Routing

Figure 5.1. Temperature by ZIP Code in action

Chapter 6. Building APIs

Figure 6.1. A website that consumes our JSON API

Figure 6.2. A mobile app that uses your API

Figure 6.3. Terminal-based applications can consume a JSON API.

Figure 6.4. Testing your API in your browser. Try refreshing and you’ll see different numbers.

Figure 6.5. Using the cURL tool to send different requests to our server

Figure 6.6. Testing the two API versions in your browser

Figure 6.7. Testing your versioned API using the cURL command-line tool

Chapter 8. Persisting your data with MongoDB

Figure 8.1. Hierarchy of Mongo’s databases, collections, and documents

Figure 8.2. The empty LAM homepage

Figure 8.3. The Learn About Me (LAM) sign-up page

Figure 8.4. An early LAM homepage, after creating a few users

Figure 8.5. The LAM profile page

Figure 8.6. Profile editor

Figure 8.7. The LAM homepage

Chapter 9. Testing Express applications

Figure 9.1. The repeating redgreen-refactor cycle of TDD

Figure 9.2. What happens when you type npm test into your command line

Figure 9.3. Typing npm test will produce this flow and ultimately end up running the code inside test/capitalize.js.

Chapter 10. Security

Figure 10.1. JSHint integration in the Sublime Text editor. Notice the error on the left side of the window and the message at the bottom in the status bar.

Figure 10.2. A fictional list of my bank contacts

Figure 10.3. A suspicious-looking page that could steal my money

Figure 10.4. An example page for a social network

Figure 10.5. An innocent-looking page that’s concealing a clickjacking attack

Figure 10.6. Not so innocent now, is it?

Chapter 11. Deployment: assets and Heroku

Figure 11.1. less2css.org in action

Figure 11.2. Heroku’s homepage

Figure 11.3. Your Hello World app running on Heroku

Chapter 12. Best practices

Figure 12.1. A common folder structure for Express applications

Figure 12.2. How optimistic versioning looks in package.json

Figure 12.3. Typing npm test flows through a few steps before executing the command.