Sikau

NestJS · Day 1 · about 25 min

What is NestJS?

Structured, TypeScript-first backends.

Express, with architecture

Express gives you freedom — and big Express apps often become a tangle. NestJS builds on Express with a clear structure borrowed from Angular and Java's Spring: modules, controllers, services, dependency injection and decorators. Large teams love it because every Nest app looks familiar.

Bootstrap, module, controller

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

@Controller()
class AppController {
  @Get()
  hello() {
    return { message: "Namaste from Nest" };
  }
}

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
  console.log(await (await fetch("http://localhost:3000/")).json());
}
bootstrap();
  • Start a real project with npm i -g @nestjs/cli then nest new cafe-api.
  • Under the hood Nest uses Express (or Fastify) — everything from the Node course still applies.
  • Decorators need experimentalDecorators and emitDecoratorMetadata in tsconfig — the CLI sets them up.

The rest of this lesson

  • The shape of a Nest projectexplain
  • Why decorators and classes?explain
  • What's returned?predict
  • Which file does what?match
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of NestJS