In this section, you'll learn how to use Express middleware. Express middleware is a fantastic tool. It allows you to add on to the existing functionality that Express has. So if Express doesn't do something you'd like it to do, you can add some middleware and teach it how to do that thing. Now we've already used a little bit of middleware. In server.js file, we used some middleware and we teach Express how to read from a static directory, which is shown here:
app.use(express.static(__dirname + '/public'));
We called app.use, which is how you register middleware, and then we provided the middleware function we want to use.
Now middleware can do anything. You could just execute some code such as logging something to the screen. You could make a change to the request or the response object. We'll do just that in the next chapter...