R
Rishtaara
Node.js Fundamentals
Lesson 4 of 8Article15 min

Express Basics and Routing

Express simplifies route definitions, middleware composition, JSON handling, and error propagation. It is still a common baseline in Node backend interviews and real projects.

Why Express

Express simplifies route definitions, middleware composition, JSON handling, and error propagation. It is still a common baseline in Node backend interviews and real projects.

Basic Express app
import express from "express";

const app = express();
app.use(express.json());

app.get("/", (req, res) => {
  res.json({ message: "Welcome to Node.js Fundamentals" });
});

app.get("/courses/:slug", (req, res) => {
  res.json({ slug: req.params.slug });
});

app.listen(4000, () => {
  console.log("API running on http://localhost:4000");
});

Routing patterns

  • Route params for dynamic segments.
  • Query params for filtering and pagination.
  • Separate routers for domain modules.
  • Keep controller logic slim and testable.