Set up an app and serve a route

12.6.0

NestJS organizes a Node.js server into modules, controllers, and providers. This guide uses NestJS 12.6.0.

On this page

Create a project with the CLI

Use the Node.js version recommended in the official first-steps guide. The CLI generators require Node.js 22.22.3+ on 22.x, 24.15+ on 24.x, or 26+. The first-steps guide lists the app runtime requirements separately.

node --version
npm install -g @nestjs/cli
nest new catalog-api --strict
cd catalog-api
npm run start:dev

Match a controller route

The controller prefix and method path combine. Register the controller in a module. When the example controller is registered, GET /catalog/featured returns the object as JSON.

import { Controller, Get, Module } from "@nestjs/common";

@Controller("catalog")
class CatalogController {
  @Get("featured")
  featured() {
    return { name: "Pen" };
  }
}

@Module({ controllers: [CatalogController] })
export class AppModule {}

Official references