Web Dev Academy Backend frameworks · Express & NestJS Tool 41 / 64
Backend frameworks

Express & NestJS

Two ways to build a Node.js server. Express is a minimal, unopinionated router; NestJS is a structured, TypeScript-first framework with decorators, modules and dependency injection.

Demo 01

Hit an Express route → get JSON back

An Express server maps a METHOD + path to a handler that returns a response. Pick a method, type a path and "send the request" — the simulated server matches a route and replies.

Registered routes:
  • GET /api/users — list users
  • GET /api/users/:id — one user
  • POST /api/users — create user
  • DELETE /api/users/:id — remove user
// response appears here…
const express = require('express');
const app = express();
app.use(express.json());

app.get('/api/users', (req, res) => {
  res.json([{ id: 1, name: 'Ada' }]);
});

app.post('/api/users', (req, res) => {
  res.status(201).json(req.body);
});

app.listen(3000);
Demo 02

Middleware pipeline

Express runs every request through a chain of middleware before the handler. Toggle each layer on/off and "send" a request to watch which ones run, in order.

Logger — logs method & path
Auth — checks the token
CORS — sets headers
JSON body parser
// pipeline output…
Demo 03

NestJS: the decorator-driven way

NestJS wraps Node in structure. A @Controller class declares routes with @Get() / @Post() decorators, and a @Module wires everything together. Same idea as Express — far more organised.

Same GET /api/users — Nest style:
// users.controller.ts
@Controller('api/users')
export class UsersController {
  constructor(private users: UsersService) {}

  @Get()
  findAll() {
    return this.users.findAll();
  }

  @Post()
  create(@Body() dto: CreateUserDto) {
    return this.users.create(dto);
  }
}

The injected UsersService is provided by Nest's dependency-injection container — you never call new UsersService() yourself.

Demo 04

Scaffold a Nest resource with the CLI

The Nest CLI generates a whole feature for you. Click to run nest g resource products and watch the generated files stream in.

Demo 05

Express vs NestJS — when to reach for which

Both run on Node and can serve the same JSON. The difference is philosophy.

  • Express — tiny, flexible, you choose every piece. Great for small APIs, prototypes, custom setups.
  • NestJS — batteries-included structure: modules, DI, guards, pipes, testing. Built on top of Express (or Fastify) under the hood.
  • Shared — both are Node.js, both speak HTTP + JSON, both use middleware. Nest is essentially "Express with rails".
  • i
    The route console, middleware pipeline and CLI scaffolder are simulated with vanilla JavaScript in your browser — real Express & NestJS run on a Node.js server, listening on a port and handling real HTTP requests. The code blocks show the actual framework syntax. The shared CSS shell provides page styling.

    ↑ All 64 tools