Much of the functionality that Express brings to the table is through middleware functions that are executed between the point where a request is received by Node.js and the point where a response is sent. Express’s connect
module provides a middleware framework that allows you to easily insert middleware functionality on a global or path level or for a single route.
The middleware supported by Express allows you to quickly serve static files, implement cookies, support sessions, process POST
data, and much more. You can even create your own custom middleware functions and use them to preprocess requests and provide your own functionality.
This chapter focuses on the basics of implementing Express middleware. It also provides some examples of using middleware to handle POST
requests, serve static files, and implement sessions, cookies, and authentication.