Sequence NODE_257
Medium

Add Health Check & Metrics Endpoint

Express.js
Node.js
Technical Specification

Add GET /health and GET /metrics endpoints for monitoring status and basic stats (uptime, request count).

Input/Output Samples
Input:GET /metrics
Output:{ uptime: 123.4, requests: 42 }
Optimal Logic Path
let requestCount = 0;
app.use((req, res, next) => {
  requestCount++;
  next();
});

app.get("/health", (req, res) => {
  res.json({ status: "ok" });
});

app.get("/metrics", (req, res) => {
  res.json({
    uptime: process.uptime(),
    requests: requestCount,
  });
});
Architectural Deep-Dive
Health and metrics endpoints are standard for checking service health and traffic.