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 add HTTP request logging — Basic

Register pino-http (or similar) on the app to log each incoming request.
Learn: Request logging answers “what hit the server?” in production. pino-http attaches a logger to each request so handlers can log with context. Place it early in the middleware stack, after body parsers if you log POST bodies sparingly.

Supplementary examples

Attach pino-http to the app

const pinoHttp = require("pino-http");
const logger = require("./config/logger");

app.use(pinoHttp({ logger }));

Log inside a handler with req.log

async function list(req, res, next) {
  req.log.info({ path: req.path }, "listing pastes");
  // ...
}

Course example

const pinoHttp = require('pino-http')
const app = express();
app.use(pinoHttp());
app.use(cors());
app.use(express.json());
// Some code omitted for brevity

Additional references & examples

  • pino-http

    HTTP request logging integration for Express.

  • Express.js guide

    Routing, middleware order, and request/response lifecycle.

← All Application-level middleware · Node / Express