Introduction to NestJS
Learn what NestJS is, why it was created, how it relates to Node.js and Express, and the core building blocks every Nest application is made of.
On this page 12 sections
Introduction
Node.js made it possible to write servers in JavaScript, and libraries like Express made it easy to start one in a few lines. But as backends grow — dozens of routes, authentication, validation, databases, multiple developers — "easy to start" often turns into "hard to maintain", because every project invents its own folder structure and patterns.
NestJS exists to solve exactly that problem. This lesson explains what Nest is, where it sits relative to Node.js and Express, and introduces the small set of building blocks that every Nest application — from a tiny API to a large enterprise system — is made of.
- What NestJS is and what kind of framework it is.
- The problem NestJS was designed to solve.
- How NestJS relates to Node.js, Express and Fastify.
- The core building blocks: modules, controllers and providers.
- What a minimal piece of Nest code looks like.
What is NestJS?
NestJS is an open-source, progressive Node.js framework for building server-side applications. It is built with and fully supports TypeScript, and combines ideas from object-oriented programming, functional programming and functional reactive programming (via RxJS).
The word "framework" matters here. A library like Express gives you tools and lets you decide how to organize everything; a framework like Nest gives you an architecture — a set of rules about where code lives and how pieces connect. You trade a little freedom for a lot of consistency.
Why NestJS Was Created
NestJS was created by Kamil Myśliwiec and first released in 2017. He noticed that while the Node.js ecosystem had excellent libraries, it lacked a widely adopted architecture for building large server-side applications — the kind of structure that Java developers get from Spring or .NET developers get from ASP.NET Core.
Nest borrowed heavily from Angular's design: modules to group features, decorators to describe behavior, and dependency injection to connect classes without hard-coding them together. The result is a backend framework where testability, loose coupling and maintainability are the default rather than something each team must invent.
Node.js, Express & NestJS
It is important to understand the layers, because beginners often confuse them:
| Layer | What It Is | Role |
|---|---|---|
| Node.js | A JavaScript runtime | Runs your JavaScript/TypeScript code on a server instead of in a browser. |
| Express / Fastify | HTTP server libraries | Receive HTTP requests and send responses. Nest uses Express by default, Fastify optionally. |
| NestJS | An application framework | Adds structure on top: modules, controllers, providers, DI, validation, guards, testing and more. |
Because Nest talks to Express or Fastify through an adapter, most of your Nest code does not depend on which one is underneath. You can even switch from Express to Fastify for extra performance with very few changes.
Core Building Blocks
Almost everything you write in Nest is one of these building blocks — each one is a TypeScript class marked with a decorator:
Modules — @Module()
Group related code (e.g. everything about "users") into one cohesive unit. Every app has at least one root module.
Controllers — @Controller()
Receive incoming HTTP requests on specific routes and return responses.
Providers — @Injectable()
Services, repositories and helpers that hold business logic and get injected wherever they are needed.
Pipes
Transform and validate incoming data before it reaches your controller method.
Guards
Decide whether a request is allowed to proceed — the home of authentication and authorization.
Interceptors & Filters
Add logic around a request (logging, response shaping) and turn errors into clean HTTP responses.
Your First Look at Nest Code
Here is a complete controller that responds to GET /hello. You will build and run this yourself in the next lesson — for now, just notice how decorators describe what the class does.
import { Controller, Get } from '@nestjs/common';
@Controller('hello')export class HelloController { @Get() sayHello(): string { return 'Hello, NestJS!'; }}Click Run to see what this code prints.
@Controller('hello') says "this class handles routes starting with /hello", and @Get() says "this method handles GET requests". Nest reads these decorators at startup and builds the routing table for you — there is no app.get(...) call anywhere.
Where NestJS Is Used
| Use Case | How Nest Helps |
|---|---|
| REST APIs | Controllers, DTO validation and Swagger generation make clean, documented APIs straightforward. |
| GraphQL APIs | The official @nestjs/graphql package supports code-first and schema-first approaches. |
| Microservices | Built-in transports (TCP, Redis, NATS, RabbitMQ, Kafka, gRPC) for service-to-service messaging. |
| Real-time apps | WebSocket gateways for chat, notifications and live dashboards. |
| Enterprise backends | Modules and DI keep large, multi-team codebases organized and testable. |
Common Mistakes
- Thinking NestJS replaces Node.js — Nest runs on Node.js, it is not a separate runtime.
- Assuming Nest is a frontend framework because it looks like Angular — Nest is strictly for server-side code.
- Skipping TypeScript basics — decorators, classes and types appear in every single Nest file.
- Treating Nest like Express and putting all logic inside controllers — business logic belongs in providers (lesson 5).
Best Practices
- Learn the three core building blocks (modules, controllers, providers) thoroughly before reaching for advanced features.
- Keep the official documentation (docs.nestjs.com) open while learning — it is well written and full of examples.
- Use the Nest CLI (lesson 2) to generate code so your project follows standard conventions from day one.
- Think in features ("users", "orders") rather than layers when organizing code — that is how Nest modules are meant to be used.
Frequently Asked Questions
Yes. NestJS is MIT-licensed and free to use for personal and commercial projects.
No. Knowing Angular makes Nest feel familiar, but this course assumes no Angular knowledge at all.
It is a great choice once you know JavaScript and basic TypeScript. It has more concepts than Express, but its structure actually prevents many of the messy-code habits beginners pick up elsewhere.
Nest handles the backend. It pairs naturally with any frontend — React, Next.js, Angular, Vue or a mobile app — that talks to it over HTTP, GraphQL or WebSockets.
Key Takeaways
- NestJS is a TypeScript-first framework for building structured Node.js backends.
- It was created by Kamil Myśliwiec, first released in 2017, and is inspired by Angular.
- Nest runs on top of Express (default) or Fastify and adds architecture, DI and tooling.
- Modules, controllers and providers are the building blocks of every Nest application.
- Decorators like @Controller() and @Get() declaratively describe routes and behavior.
Summary
You now know what NestJS is, why it exists, how it layers on top of Node.js and Express, and which building blocks every Nest app uses. Next, you will install the Nest CLI, generate your first real project and walk through every file it creates.