Sequence NODE_243
Easy

Add Centralized Request Logging Middleware

Express.js
Node.js
Technical Specification

Create a custom middleware that logs method, URL, and response time for each request.

Input/Output Samples
Input:GET /items
Output:LOG: GET /items 200 - 15ms
Optimal Logic Path
function requestLogger(req, res, next) {
  const start = Date.now();
  res.on("finish", () => {
    const ms = Date.now() - start;
    console.log(`${req.method} ${req.originalUrl} ${res.statusCode} - ${ms}ms`);
  });
  next();
}

app.use(requestLogger);
Architectural Deep-Dive
Middleware has access to req, res, and can attach listeners to measure time and log after response finishes.