If you don’t know NestJS, it’s like Angular but for the backend. With it, we can write our backend using the same concepts and object-oriented APIs that we already use to structure our Angular frontend: components, services, modules, pipes, etc. NestJS is also quite similar to popular libraries that you might already be used to, such as example, the Spring library in the Java ecosystem, or ASP.NET MVC for the C# ecosystem.
In this tutorial, you are going to learn from scratch how to design and develop a NestJS backend that will take the form of a REST API that queries a MongoDB database using the Mongoose ODM (Object Document Mapping) library. We will be providing a complete CRUD example showing how to perform the most common REST data retrieval and data modification operations using NestJS.
No prior NestJS, MongoDB, or Mongoose knowledge is assumed as we will explain everything from scratch. We will cover all the essential NestJS concepts such as Modules, Controllers, and injectable services. We will learn in detail how to validate business data using a decorator-based approach (with decorators like @IsString(), @IsPhoneNumber(), etc.) by leveraging the built-in NestJS Validation pipe.
We will also implement using NestJS commonly needed backend security functionality such as User Authentication, RBAC (Role-Based Access Control) Authorization, error handling, and cover more advanced NestJS concepts such as Filters, Pipes, Guards, interceptors, and middleware.
Table of Contents.
After taking this tutorial, you will feel comfortable designing and developing applications using NestJS. You will have learned everything that you need to know in practice for designing and developing production-ready secure backends using the NestJS framework. It’s like Angular but for the backend. Build a modern REST backend with Typescript and the familiar Angular API.
What you’ll learn:
- Code in Github repository with downloadable ZIP files per section.
- NestJS Deep Dive – Modules, Controllers, Services, Pipes, Middleware, Guards.
- NestJS Design Patterns – Controllers and Repositories.
- Complete NestJS / MongoDB CRUD example.
- Mongoose ODM (Object to Document Mapping) library.
- Introduction to MongoDB.
- Decorator-based Data Validation.
- Authentication in NestJS with JSON Web Tokens (JWT).
- NestJS RBAC Authorization (Role-Based Access Control).
Requirements:
- No prior knowledge of NestJS or Angular is needed.
- Prior knowledge of Typescript is important.
This tutorial covers the following topics:
- Introduction to NestJS.
- Running NestJS in Hot Reload and Debug mode.
- Writing our first NestJS REST endpoint.
- NestJS Modules, Controllers and injectable Services.
- Introduction to MongoDB.
- Setting up a cloud MongoDB database.
- Introduction to the Mongoose ODM library.
- Querying MongoDB from a NestJS REST endpoint.
- Complete CRUD example with NestJS and MongoDB.
- NestJS Filters and custom error handling.
- NestJS Pipes, building a custom pipe.
- Data Validation with class-validator and the Validation pipe.
- NestJS Middleware.
- User Authentication with NestJS.
- NestJS RBAC (Role-Based Access Control) Authorization.
- NestJS Guards.
Who this tutorial is for:
- Web Developers in general, looking for a detailed guide to the NestJS framework.
- Angular Developers, looking to reuse some of the same Angular concepts and apply them to the backend as well.