Part 2. Core

 

In part 1, I set the scene, introducing Node.js, the server-side JavaScript runtime. I also introduced the main character: Express.

You saw that Express has four major features:

  • Middleware —In contrast to vanilla Node.js, where your requests flow through only one function, Express has a middleware stack, which is effectively an array of functions.
  • Routing —Routing is a lot like middleware, but the functions are called only when you visit a specific URL with a specific HTTP method. You could run a request handler only when the browser visits yourwebsite.com/about, for example.
  • Extensions —Express extends the request and response objects with extra methods and properties for developer convenience.
  • Views —Views allow you to dynamically render HTML. This allows you to both change the HTML on the fly and write the HTML in other languages.

The next four chapters will delve into each of these features in depth:

Chapter 4 will talk about middleware, perhaps the most important core feature of the framework. Almost every piece of the Express stack is influenced by middleware in some respect, so this is a critical chapter.

Chapter 5 discusses routing, the mechanism by which URLs are mapped to JavaScript functions. The basics of routing are simple, but there’s a lot more in the Express routing system that can come in handy. We’ll explore all of that in chapter 5.