Chapter 3. Foundations of Express

 

This chapter covers

  • The four main features of Express:
    • Middleware for letting a request flow through multiple headers
    • Routing for handling a request at a specific spot
    • Convenience methods and properties
    • Views for dynamically rendering HTML

As you saw in the previous chapter, Node.js comes with a number of built-in modules, one of which is called http. Node’s http module allows you to build an HTTP server that responds to HTTP requests from browsers (and more). In short, the http module lets you build websites with Node.

Although you can build full web servers with nothing but Node’s built-in http module, you might not want to. As we discussed in chapter 1 and as you saw in chapter 2, the API exposed by the http module is pretty minimal and doesn’t do a lot of heavy lifting for you.

That’s where Express comes in: it’s a helpful third-party module (that is, not bundled with Node). When you get right down to it, Express is an abstraction layer on top of Node’s built-in HTTP server. You could, in theory, write everything with plain vanilla Node and never touch Express. But as you’ll see, Express smooths out a lot of the difficult parts and says “Don’t worry; you don’t need to deal with this ugly part. I’ll handle this!” In other words, it’s magic!

3.1. Middleware

3.2. Routing

3.3. Extending request and response

3.4. Views

3.5. Example: putting it all together in a guestbook

3.6. Summary

sitemap