Middleware functions have access to the request object (req), the response object (res), and the next() middleware in the application's request-response cycle.
⊞Code Example
const express = require('express');
const cors = require('cors');
const app = express();
// 1. Enable Cross-Origin Resource Sharing
app.use(cors());
// 2. Parse incoming JSON request bodies
app.use(express.json());
// 3. Custom Request Logger Middleware
app.use((req, res, next) => {
console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
next(); // Pass control to next handler
});
