How it works...

Express is a framework built on top of Node's core http (and https when relevant) module.

The core http moduleSee Chapter 5, Wielding Web Protocols for more on Node's core http module.

Express decorates the req (http.IncomingMessage) and res (http.ServerResponse) objects, which are passed to the http.createServer request handler function.

To explain this using code, at a very basic level Express essentially performs the following internally:

const http = require('http') 
http.createServer((req, res) => {  
  /* add extra methods and properties to req and res  */  
})) 

When we call the express function, it returns an instance that we called app , which represents our Express server.

The app.use function allows us to register middleware, ...

Get Node Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.