Node and Express are the runtime and HTTP framework for your API. Topics here cover bootstrapping the app, parsing JSON bodies, and structured logging—everything that runs before a route handler executes. Master this layer first so later routers and controllers plug into a consistent foundation.

How to configure logging — Intermediate

Centralize logger setup in a config module with log level and custom request IDs.
Learn: Centralizing logger setup avoids duplicating log level and formatting rules. Use environment variables for LOG_LEVEL in development vs production, and generate a request ID (e.g. nanoid) so log lines for one request can be correlated.

Supplementary examples

Logger module with level from env

const pino = require("pino");
const { nanoid } = require("nanoid");

module.exports = pino({
  level: process.env.LOG_LEVEL || "info",
  genReqId: () => nanoid(8),
});

Course example

const pinoHttp = require("pino-http");
const { nanoid } = require("nanoid");
const level = process.env.LOG_LEVEL
const nodeEnv = process.env.NODE_ENV || 'development'
const prettyPrint = nodeEnv === "development"
const logger = pinoHttp({
genReqId: (request) => request.headers['x-request-id'] || nanoid(),
level,
prettyPrint
});
module.exports = logger;

Additional references & examples

← All Application-level middleware · Node / Express