1. Concept library
  2. Backend with Node.js
  3. Module 11: Deployment

Concept

Logging and monitoring

Structured logs, one JSON object per line with a request id, let you search and correlate what happened. Metrics and health checks tell you how the service is doing before users do.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what structured logs with a request id make possible
  2. Log one JSON object per line with a request id across a request
  3. Spot the request body logged wholesale

In practice

A few lines that show Logging and monitoring doing its job.

JavaScript
import Fastify from "fastify";
const app = Fastify({
  logger: { level: process.env.LOG_LEVEL ?? "info", redact: ["req.headers.authorization"] },
  genReqId: (req) => req.headers["x-request-id"] ?? crypto.randomUUID(),
});

app.get("/health", async () => ({ ok: true, uptime: process.uptime() }));

app.get("/orders/:id", async (req) => {
  req.log.info({ orderId: req.params.id }, "loading order");
  ...
});

The common mistake

Watch for

Logging request bodies and headers wholesale. Passwords, tokens and personal data end up in the log system with a different retention and access policy. Redact and log what you need.

What to know first

Your roadmap puts these before Logging and monitoring, unless you already know them.

How it stays learned

Once a session shows you understand Logging and monitoring, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← Containers