Introduction
Middleware runs for every request to handle common tasks like logging or security. It works globally so you don't repeat code in each route.
You want to log every request your app receives.
You need to check user authentication on all routes.
You want to add headers to every response.
You want to measure how long each request takes.
You want to handle errors in a central place.