1. Application-level Middleware
Runs across the entire Express application and handles common logic for incoming requests.
- Registered using
app.use()orapp.METHOD(). - Executes for routes and HTTP methods according to how it is registered.
- Common uses: logging, authentication, body parsing, and headers.
app.use(express.json());
app.use((req, res, next) => {
console.log('Request received:', req.method, req.url);
next();
});