NestJS is a TypeScript-first Node.js framework that layers an opinionated application architecture — modules, controllers, and providers — on top of an underlying HTTP platform such as Express, and ships a CLI that scaffolds and builds projects following that architecture.
In simpler words
Nest is Express (or Fastify) with a structure enforced on top, plus a command-line tool that generates the files and builds the project for you.
After Node and Express, map what Nest adds: modules, DI, decorators, and the CLI that scaffolds them. Nest ≠ Next — Nest is an HTTP API and database owner, while a React/Next frontend is a client that calls it over HTTP.
Explain nest-cli.json and know what nest build/start do
Trace main.ts from bootstrap to listening port
Say why Nest and Next are unrelated despite similar names
Nest vs Next — and what Nest actually is
Definition
NestJS is a backend Node.js framework for building HTTP APIs, while Next.js is a frontend/full-stack React framework for building rendered UI; the two share a similar name but no codebase or runtime relationship.
In simpler words
Nest answers HTTP requests with JSON and owns the database; Next renders React pages. A full-stack project can use both, for different jobs.
A Nest application owns the database (for example Postgres via TypeORM), exposes an HTTP surface such as tickets/health/auth routes, and returns JSON.
A Next.js application renders React UI and calls the Nest API over HTTP/cookies. It does not import Nest modules or touch the database directly.
Nest sits on an HTTP platform adapter — Express by default (Fastify is swappable) — and adds modules, controllers, providers, and a dependency-injection container around it.
If you find yourself writing SQL in the Next.js app or JSX in the Nest app, you are in the wrong app.
What the Nest CLI generates and builds
Definition
The Nest CLI (@nestjs/cli) is a command-line tool that scaffolds new Nest projects and files from schematics, and compiles a project according to nest-cli.json.
In simpler words
nest new starts a project, nest generate adds a piece (module/controller/service) with the right boilerplate, and nest build/start compile and run it.
nest-cli.json sets sourceRoot: "src" and deleteOutDir: true so nest build cleans dist/ before compiling.
A package.json typically wires the CLI: "build": "nest build" and "dev": "nest start --watch". Even without a nest generate script wired in, the CLI is a devDependency you can run directly (npx nest generate module <name>) to scaffold new features consistently.
nest start --watch recompiles and restarts on save during local development.
Mistake: hand-rolling module boilerplate
// Wrong — copy-pasted from another feature, drifts from convention
touch tickets.module.ts // then guess the shape
// Right
npx nest generate module tickets
npx nest generate controller tickets
npx nest generate service tickets
Generators keep @Module/@Controller/@Injectable wiring consistent across a team.
From CLI output to a running app
Definition
A compiled Nest application boots by creating a root application instance from the root module, then Node executes the resulting HTTP listener.
In simpler words
nest build turns TypeScript into dist/, then node dist/main.js starts the server that main.ts describes.
main.ts calls NestFactory.create(AppModule) to build the app from the root module, applies cookies/CORS/global pipes/filters/interceptors, sets up Swagger at /docs, then calls app.listen(env.PORT).
AppModule is the entry point the CLI-built app boots from — every controller and provider must be reachable from it through module imports.