Backend Development
Step 18 / 2060 min

Logging & Health Checks

Reliability

Explanation

Structured logs and /health endpoints tell you when a database or dependency is down.

Code example

javascript
app.get("/health", async (_req, res) => {
  try {
    await prisma.$queryRaw`SELECT 1`;
    res.json({ ok: true });
  } catch {
    res.status(503).json({ ok: false, db: "down" });
  }
});

Helpful resources

Exercise

Add /health that checks the database and log method, path, and status for every request.