
Master NestJS to build scalable, modular backend apps with a real-world REST API for a blog, open API documentation with Swagger, and robust authentication and testing.
Discover how we build a NestJS rest API on Node.js, including user management, authentication, posts, and tags, with OpenAPI and swagger docs and dummy servers for testing.
Nestjs is a NodeJS framework built on NodeJS and TypeScript that enables scalable, modular server-side applications and CLI tools by providing structure, consistency, and a rich set of built-in features.
Set up your NestJS development environment by installing Node.js (LTS) and npm, verifying versions in the terminal, and installing Visual Studio Code.
Install the Nestjs CLI globally with npm to access development commands and generate modules. Use nest start, nest build, and nest generate (or g), with dry run to simulate changes.
Bootstrap your first NestJS application with the CLI, run a dry run, and install dependencies with npm, then start dev to view hello world on localhost:3000.
Understand how NestJS relies on boilerplate code to instantiate modules, controllers, and services, and cultivate a declarative, modular mindset essential for mastering this course.
Code along with me to maximize learning value; treat this course as incremental practice with modules, dependency injection, and validation pipes, reinforced by practice and solution videos.
Explore how NestJS modules group related functionality into cohesive units, connect via app module and main.ts, and organize controllers and services for a blog with users and posts.
Learn how NestJS bootstraps the application from main.ts using NestFactory to create the app with the AppModule, and how the bootstrap function starts the server on port 3000 (or 3300).
Explore why the app module is essential in NestJS, how the main.ts bootstraps the app, and how the module decorator, imports, controllers, and app service implement it.
Learn how to create a new users module in NestJS by manual setup and with the NestJS CLI, and connect it to the app module to activate it.
Understand what a rest api is and the six design principles: client-server decoupling, stateless, cacheable, uniform interface, layered system, and code on demand. Explore code on demand as optional.
Install postman and http yak, then send requests to a NestJS app. Integrate http yak into VS Code and create .http files to run get requests.
Learn how NestJS controllers handle routing by creating a users controller that processes get, post, and delete requests, connects to the users module, and binds to /users on localhost:3000.
Route http requests to NestJS users controller methods using get, post, patch, put, and delete decorators, and build JSON endpoints.
Discover how NestJS decorators extract params, query, and body, differentiate required and optional route parameters (curly braces in NestJS 11 with Express 5), and access the Express request.
Grab specific query params, route params, or body keys using NestJS decorators, then validate entire objects for simpler validation, and access headers and IP with dedicated decorators.
Discover how providers in NestJS implement business logic within modules, separating concerns from controllers and enabling modular, testable code through services, repositories, and helpers.
Explore how pipes validate and transform incoming requests before reaching the controller in NestJS. Understand the request lifecycle from middleware through pipes, and distinguish built-in and custom pipes.
Learn how to implement validation and transformation for a NestJS users endpoint, handling optional id and pagination with defaults, using pipes to convert values from strings to integers.
NestJS demonstrates parsing and validating params with built-in pipes, especially parse int pipe, showing transformation from strings to integers and handling invalid input with a bad request error.
Transform and validate query parameters in NestJS using parse int pipes for limit and page, apply default value pipes to set sensible defaults, and handle validation errors gracefully.
Learn how built-in pipes validate params and queries with defaults and optional fields, and validate large request bodies using data transfer objects with class-validator.
Create your first dto in NestJS, import class-validator decorators to enforce string types, validate required email and password, allow optional last name, and apply min/max length and regex checks.
Connect the create user DTO to the post method and trigger validation with a pipe. Use class-validator and class-transformer for DTO rules and for password and email validation errors.
Learn how to apply global validation pipes in a NestJS app to automatically validate incoming requests via a DTO, enabling whitelist and forbid non-whitelist to prevent extra properties.
Learn how NestJS validation with transform converts a plain create user DTO into an actual DTO instance, boosting type safety in requests.
Learn to validate route params with a DTO, making an optional id param by applying class-validator decorators and class-transformer type, and ensure params are transformed from strings.
learn how mapped types enable reusing create user dto to build a patch user dto, making properties optional with partial type, reducing code repetition and following the dry principle.
Explore dependency injection and inversion of control in NestJS by contrasting naive dependency management with injected singletons, showing how a shared user instance is supplied to post and page classes.
Learn how NestJS handles dependency injection, creating singleton instances in the correct order to decouple components, enable testing with mocks, and share providers across modules through provide and export.
Learn to create a user service, register it as a provider with the injectable decorator, and implement dependency injection by injecting it into the users controller via the NestJS module.
Implement a find all method in a NestJS user service, using dependency injection to move business logic from the controller, and handle get users param DTO, limit, and page.
Implement find one by id in the user service to return a user by id, preparing intermodule dependencies with a new posts module.
create a posts module in NestJS using the command line interface, build a post controller and a post service, and inject the post service into the controller as a dependency.
Use the NestJS CLI to generate a posts module, controller, and a dedicated providers directory for post services. Wire the service into the controller via dependency injection.
Compare intra-module and inter-module dependencies, showing how a post service relies on the user service to access a user. Prepare for circular dependencies and future auth-service interactions in nestjs.
Create a get posts route with a user id parameter in NestJS, demonstrating inter-module dependency injection and wiring to the post service (no dto yet).
Implement a find all posts method in the nestjs post service with user service injection. Fetch and verify the user before returning their posts, using typeorm relationships for inter-module dependency.
Inject the user service into the post service by exporting the user service from the users module, importing the users module into the posts module, and using inter-module dependency injection.
Practice building an auth module in NestJS by creating a module, a controller, and a service, wiring them with dependency injection while addressing circular dependencies.
Create the auth module with a service and controller using the NestJS CLI, and set up dependency injection by injecting the auth service into the controller.
Learn to implement a login method in the auth service that authenticates a user via the user service, returning a token, and manage the circular dependency with forwardRef.
Learn to document your NestJS API with Open API specifications and document your code with Compo doc. See how these documents are generated and hosted with the app.
Explore the open api specification as a standard for describing api endpoints, and see how swagger builds the swagger ui for NestJS documentation.
Enable swagger in a NestJS app by installing @nestjs/swagger, configuring DocumentBuilder and SwaggerModule in main.ts, creating a document with createDocument, and setting up the docs at /api for API documentation.
Enhance NestJS swagger by adding configuration methods—set title, description, terms of service, and license; add a server, and organize endpoints into users and posts groups with api tags.
document and refine the get users endpoint with swagger decorators in both dto and controller, detailing id parameter, limit and page query params, api operation, and a 200 response example.
Create a post api endpoint and a dto for the posts controller, detailing title, post type (enum), slug, status (enum), json ld schema, and tags.
Build post creation endpoint in posts controller with create post DTO, a post decorator, and body decorator, and enums for post type and status, outlining fields like title and content.
Adds validations to the create post DTO with class-validator decorators, enforcing string types, minimum length, not empty, enum membership, slug pattern, optional fields, JSON validation, and array element checks.
Learn to validate nested objects in NestJS by creating a nested post meta options DTO, validating an optional array of key and value objects with class-validator and class-transformer decorators.
Test validations by sending post requests to the posts endpoint, validate the create post dto fields, nested meta options, and ISO date, schema, and enum constraints with live error feedback.
Learn to document a create post dto with NestJS Swagger by tagging dto properties with ApiProperty, adding descriptions, examples, and enum details to reflect in Swagger.
Tag the post endpoint with API response and API operation decorators to document 201 creation and 200 updates, then use PartialType to document partial post DTOs in Swagger.
Discover how to install and configure compo doc to document your entire NestJS codebase—providers, controllers, and DTOs—alongside automatic updates as you code and serve docs on port 3001.
Understand how ORMs provide an abstraction layer between your TypeScript code and SQL databases, enabling repository-based queries, relationships, migrations, and easy database switching with TypeORM.
Install PostgreSQL locally to connect your Nestjs application with type orm. Download the Mac OS installer from postgresql.org, install the Postgres server and Pgadmin, and create the Nestjs blog database.
Learn to add the PostgreSQL bin directory to your path so you can run psql from the terminal, using export PATH and pg_ctl with PostgreSQL 16 on macOS and Windows.
Install TypeORM, NestJS TypeORM bindings, and the PostgreSQL driver, then configure app.module.ts with TypeORM forRoot to connect NestJS to PostgreSQL using entities and development-time synchronization.
Convert the NestJS Postgres connection to an asynchronous setup using forRootAsync with a useFactory, enabling configuration object injection from env files and future configuration service integration.
Explore the repository pattern with TypeORM by modeling a user entity, injecting a repository into the user service, and using the repository to interact with the database.
Create a user entity for NestJS app, mapping first name, last name, email, and password to a users table with generated id, and configure it with TypeORM in app module.
Expand the user entity by adding configuration objects to column decorators in TypeORM, selecting postgres types, enforcing varchar lengths and nullability, and ensuring email uniqueness across the create user DTO.
Inject a user repository into the service with the inject repository decorator and TypeORM, register it via for feature in the user module, and save a new user to PostgreSQL.
Create a post entity file and set up a post table in the database to practice what you've learned in this NestJS masterclass, preparing for the upcoming relationships section.
Create a post entity in NestJS, aligning id, title, post type enum, slug, status enum, content, schema, featured image, published on, tags, and meta options to the create post dto.
Explore how relational databases use table relationships to prevent data duplication, ensure accuracy, and enable flexibility, with practical guidance on 1-to-1, 1-to-many, and many-to-many relationships in Typeorm and Nestjs.
Create a tags module and a tags entity in NestJS, detailing id, name, slug, description, schema, and featured image, with create date, update date, and delete date for soft deletes.
Generate the meta options module and controller, then define the meta option entity with an id, a json meta value, and created and updated dates using a json column.
Update dto files in nestjs backend by moving post meta option dto and creating meta option and tag dtos, validating a json meta value with class-validator for post relationship.
Enable auto load entities in TypeORM to automatically create tables for user, post, tag, and meta option, importing them with forFeature and inspecting pgadmin.
Explore one-to-one relationships by linking each post to a single meta option via a foreign key that references the meta option's primary key; cover unidirectional and bidirectional forms.
Explore how to implement a unidirectional 1-to-1 relationship in NestJS using the 1-to-1 decorator and join column, linking posts to meta options.
Develop a NestJS meta options service and controller to enable a 1-to-1 relationship with posts. Add a post endpoint and create method driven by a create post meta options dto.
Explore creating a post with a 1-to-1 meta option relationship in NestJS, by updating the create post dto and using a JSON meta value.
Learn how cascade creates a post and its meta option in a single save by cascade insert, update, and remove in a 1-to-1 relationship, simplifying tests and reducing interdependencies.
Learn how to query posts with related meta options using TypeORM, exploring explicit relations and eager loading in NestJS, via the post repository and entity configuration.
Learn to delete related entities in a unidirectional 1 to 1 relationship by sequentially removing the post first, then its meta options, to satisfy foreign key constraints.
Learn how bidirectional relationships link post and meta option, with foreign keys in the owning table via the join column decorator, and optional cascade delete to keep data clean.
Learn to build a bidirectional one-to-one relationship between post and meta options in NestJS, using inverse relations, repositories, and eager loading to fetch related posts.
Implement cascade delete in a bidirectional 1-to-1 post and meta option relationship by moving the foreign key to meta option and enabling on delete cascade.
Explore one to many and many to one relationships in nestjs using a user and post, noting bidirectional links, foreign keys on the many side, and join columns omitted.
Create a bidirectional one-to-many relationship between user and post using many-to-one and one-to-many decorators, with author as the user. Upcoming videos cover creating posts and assigning authors.
Create a post with an author using one-to-many and many-to-one relationships between post and user entities in NestJS; add id to create post dto and fetch author via user service.
Learn to fetch posts with their author using a relations object and optional eager loading in a NestJS backend, covering 1-to-1 and one-to-many relationships.
Explore many to many relationships in TypeORM, linking posts and tags via a junction table with foreign keys. Learn to define unidirectional and bidirectional relations with decorators.
Create a new tag service with a create method to insert tags using the tag entity and tag DTO. Update the controller to add a post endpoint for creating tags.
Create and wire a tag service in NestJS, injecting the tag repository and a create tag dto, and expose a post endpoint via the tags controller to save new tags.
Test the tag service by posting a new tag to the localhost:3000 tags endpoint, creating a JavaScript tag with name, slug, and description, and verify with Pgadmin.
Master unidirectional many-to-many between post and tag in NestJS by adding a join table, updating the post DTO to accept tag IDs, and injecting the tag service to assign tags.
Fetch posts with their many-to-many tags by enabling the tags relation in the post service or by turning on eager loading in the post entity.
Learn to update a post and its tags in a NestJS app using a unidirectional many-to-many relationship: fetch tags, update post properties via a patch dto, then save.
Learn how deleting a post in a unidirectional many-to-many relationship on the owning side triggers automatic cascade removals in the join table with TypeORM, while the tags stay intact.
Learn how to implement a bidirectional many-to-many relationship between posts and tags in NestJS, defining both sides with many-to-many decorators and referencing the join table on the Post entity.
Explore cascade delete in a bidirectional many-to-many relationship between posts and tags, focusing on the owning side and enabling on delete to remove join table references.
Learn how to implement soft delete for tags in a NestJS app using a delete date column, create a dedicated soft delete endpoint, and understand its impact on tag-post relationships.
Explore how to manage environments in NestJS using environment variables and the config module. Learn to segregate production, development, staging, and test credentials to keep data secure and stable.
Install and configure the NestJS config module in app.module.ts to read environment variables across the application, using forRoot with isGlobal and a dot env file.
Inject the NestJS config service to safely access environment variables from a dot env file, using get to retrieve S3 bucket and typecast values as needed.
Learn how node_env is set to test during NestJS end-to-end testing and how to configure environment files and module paths for development, testing, and other environments.
Configure environment-specific files in a NestJS app by loading env files based on NODE_ENV. Load variables like the S3 bucket via config, with single or array-based env paths.
Learn to load database details from environment variables using the NestJS config service and inject them into the TypeORM factory, with env files and proper port conversion.
Create custom configuration files with NestJS by using a global config directory and app.config.ts that reads environment variables and exposes database and environment settings via the config module.
Learn to divide configuration files into namespaces using NestJS config's registerAs, creating database and app.config namespaces and exposing properties under their respective namespaces.
Explore module configuration and partial registration in NestJS, enabling module-specific configurations with config module, environment keys, and inject techniques for type-safe access.
Validate environment variables across global and module namespaces with the Joey package, ensuring missing or invalid values trigger bootstrapping errors through a NestJS config schema.
Explore how NestJS handles exceptions across guards, interceptors, pipes, controllers, and services, and use built-in HTTP exception methods to return meaningful error messages.
NestJS provides built-in http exceptions via the nestjs common package, exposing ready-to-use methods. No extra status codes or custom handling are needed, with examples like bad gateway and bad request.
Identify where to add exception handling in NestJS by analyzing service and repository operations, database constraints, and external API calls, and apply built-in HTTP exceptions across services and middleware.
Learn how NestJS handles model constraints by checking for duplicate emails with a try-catch around the database, then throw bad request or request timeout exceptions.
Implement exception handling in a NestJS user service for create and find by id, using try/catch to throw request timeout and bad request exceptions on database errors or missing IDs.
Learn how to throw a custom HTTP exception in NestJS using the HTTP status enum to signal a moved permanently endpoint.
Practice adding exception handling to the post update method in the post-service file, identifying potential failure points as you update posts in the database.
Explain robust exception handling in the update method, including try-catch blocks for fetching tags and post, tag count validation, and throwing timeout or bad request errors for invalid data.
Explore database transactions in Typeorm within NestJS, illustrating atomic CRUD operations that roll back on failure. Apply these patterns to multi-entity tasks like bulk user creation to ensure data integrity.
Learn how TypeORM's query runner retrieves a single connection from a pool to perform a transactional set of CRUD operations, with connect, start transaction, commit, rollback, and release.
Create your first transaction in NestJS using TypeORM by injecting the data source, creating a query runner, starting and committing or rolling back, then releasing the connection.
Learn why you don’t use transactions for every database insertion, comparing a single post creation to creating many users and highlighting when commit and rollback matter.
Refactor the user service by creating a dedicated users create many provider, enabling injection, and adding a create many endpoint with an array data transfer object.
Update create many users dto to validate each user in the array with nested validation and type decorators, swagger metadata, yielding 400 on invalid items and 201 on batch creation.
Practice adding exception handling to the create many users method in the NestJS backend, identifying where errors occur and applying robust error handling for reliable bulk creation.
Demonstrates adding robust exception handling to create-many-users with a database transaction, using try/catch blocks, timeout and conflict exceptions, and safe connection release.
NestJS is a Node.js framework for building efficient, reliable, scalable server-side applications. Its structure is opinionated and draws inspiration from Angular. Nest has gained popularity; more than 3 million downloads on NPM weekly.
While I was learning NestJS, the learning curve was very steep. I wished there was a detailed and well-structured course that would make my learning path easy. That's why I came up with this course: so that other developers who are trying to learn NestJS do not have to go through such a steep learning curve.
I can assure you that the "NestJS Masterclass" is the most detailed, extensive, well-structured, and in-depth course in the marketplace—period! - There is no other course like NestJS Masterclass, Guaranteed!
NestJS Masterclass is a Practical Course! We work together to build a REST API server-side application for a blog. We learn while we code this application, so all the examples in this course are real-world use cases. While programming this application, we will learn various NestJS features and dive deeper into the internal mechanics of NestJS.
Well-designed and Structured Curriculum
While designing the curriculum of the NestJS masterclass, I have spent a lot of time and effort thinking and ensuring that this makes learning NestJS easy for my students. Here is a partial list of topics covered in the NestJS Masterclass and what you can expect to learn from each section. Refer to the curriculum section for a detailed list of all topics covered.
Understanding Modules: I introduce you to NestJS modules, how they work, the internal mechanics of how they are linked to each other, and various schematics that are used with modules, including services and providers.
Validation And Pipes: This is a crucial section that explains how you can leverage packages like class validator and Pipes in NestJS to validate the incoming data to your application.
Dependency Injection: Dependency injection is the backbone of the NestJS framework. We dive deeper into how it works and how to leverage it to ensure that your application remains modular. We work on all possible dependencies, including circular ones between modules.
Documenting Code: We learn about NestJS's features, which let you document the API endpoints using Open API Specification and your application's source code using Compodoc.
TypeORM and Relational Databases: TypeORM has a close integration with NestJS. We use PostgreSQL in the REST API application we build and learn how to leverage all features of TypeORM while building a real-world application.
Database Relations: This section teaches you about relationships in SQL databases and how to use TypeORM to set them. This includes one-to-one, one-to-many, and many-to-many relationships. It is a detailed and well-designed section that eliminates all misconceptions about database connections.
Configuration Environments In NestJS: Applications often run in different environments. Depending on the environment, different configuration settings should be used. NestJS has a well-designed system for managing configurations.
Exception Handling: Elegantly handling exceptions within an application is crucial, as it improves the experience of developers and application users. We look at features NestJS provides that help us handle exceptions within an application.
Database Transactions: Database transactions are important when you want to perform CRUD operations, which impact multiple entities simultaneously and are interdependent. We dive deeper into TypeORM transactions to see how they can be used with NestJS.
User Authentication with JSON Web Tokens: We work on building a user authentication system using JWTs and learn the mechanics behind a secure and well-designed System.
Guards and Decorators: Guards and Decorators are a few of the important schematics offered by NestJS. We use Guards to filter out unauthorized requests and decorators to set meta-data and attach payloads to incoming requests.
Google Authentication: Modern applications are interconnected and usually offer an easy signup process using services like Google OAuth. We use Google Authentication along with the JWTs Authentication service we create for the NestJS application we build.
File Uploads: Most applications need a file upload mechanism for users to upload files to the server and use them later. We learn about NestJS Interceptors and how they can be used to upload files to NestJS.
Unit and End-to-End Testing: NestJS has been developed to keep the code you write modular so you can test it quickly. To live up to this practice, I have created dedicated modules for unit testing and end-to-end testing in NestJS for this course.
Mongoose and MongoDB: Many times, you need to use NoSQL databases like MongoDB with the NestJS application. We do exactly that in this section. So, no matter which database you want to use, NestJS Masterclass is a perfect fit.
Deployment to AWS: We examine all the intrinsic details of deploying a production application to AWS. We also explore using CloudFront CDN and S3 buckets to upload and serve media files for our application.
And lots more ...
Who am I?
I will give a quick introduction about myself I am Manik and I am a full stack developer and working as one since last fifteen years of my life.
Why did I choose to teach NestJS?
NestJS is a robust framework that is very close to my heart. For the last four years, I have been working on It. I have developed and maintained an application using NestJS, which has more than One Million Hits daily. I had a tough time learning NestJS due to the lack of tutorials, and that's why I decided to make this course so that I can teach what I have learned throughout all my years working with NestJS.