
Learn to build modern APIs with NestJS using MongoDB and Postgres, implement authentication with Passport JWT, pagination and search, unit and E2EE tests, image uploads to S3, and deployment.
Build a restaurant API in NestJS with authentication and meals, enabling search with keyword and pagination, plus geocoding, S3 image uploads, and PostgreSQL relations.
Explore NestJS as a progressive, TypeScript-friendly backend framework for building scalable, testable APIs. Experience its architecture for scalable, testable apps and a command line interface to generate boilerplate and modules.
Follow along by accessing the project's source code branches, each representing a course section; clone the repo from the master branch to view section-specific code and the production-ready API.
Install the required tools for building modern nestjs APIs, including Node, Postman, Visual Studio Code, MongoDB Community Server, MongoDB Compass, Typekit, and Postgres may be used later.
Install MongoDB community server on macOS using Homebrew. Ensure Xcode command line tools are installed, then verify the installation with the mongo shell by running show dbs.
Install and configure MongoDB community server on Windows, including MongoDB Compass and shell; set the path, start the server, and verify connections with mongod, mongosh, and Compass.
Install the Nest CLI globally and generate a new Nest project to scaffold the restaurants API with modules, controllers, and services.
Explore the NestJS project structure, including modules, src, and test folders, and learn how the bootstrap uses NestFactory to start the app on port 3000.
Explore nest js modules as single entities defined by the module decorator, with providers, controllers, imports, and exports, and see a restaurant module auto-added to the app module.
Learn how nest.js controllers handle incoming requests and return responses, using get and post routes in the restaurants module. Use the controller decorator to wire routes and tests later.
Explore providers and services in nestjs and how a provider is injected as a dependency. Register providers in modules, use the injectable decorator, and generate a service with the cli.
Connect your NestJS app to MongoDB with Mongoose by installing nestjs/mongoose, configuring MongooseModule.forRoot with a localhost database, and managing development variables with @nestjs/config.
Create a restaurant schema in NestJS using the schema decorator and prop for name, description, email, phone, address, category, and images; define an enum category and register in the module.
learn to fetch all restaurants in a nestjs api by injecting the restaurant model, using a service to find all, and exposing a /restaurants endpoint that returns the array.
learn to create and save a new restaurant via a NestJS post endpoint, using body data, a restaurant service create function, and saving to the database, with dto concepts introduced.
Learn how a dto, a data transfer object, defines how data is sent over the network and why using a class enforces required fields such as name, age, and breed.
Create a restaurant dto to collect name, description, email, phone, address, and category, with read-only fields and upcoming validations, wired into the controller and service.
Create a get restaurant by id endpoint in the NestJS restaurant service to fetch a restaurant by id with mongoose, throw not found if absent, and return it.
Learn to update a restaurant by id using a put request in NestJS, leveraging the restaurant service, find by id, and validators to ensure correct data.
Delete a restaurant by id using a NestJS delete endpoint, implemented in the restaurant service and controller, returning a boolean to indicate success, with Postman verification.
Implement a search api that finds restaurants by name using a keyword query with case-insensitive matching, returning matches or all restaurants when no keyword is provided; verify with postman.
Learn to implement pagination in NestJS APIs using page and per-page parameters, calculate skip values, and apply Mongoose find with limit and skip.
Explore NestJS pipes, an injectable middleware that transforms input and validates data before processing, such as converting strings to integers using a validation pipe.
Enable a global validation pipe in NestJs and use class-transformer and class-validator to enforce rules (strings, emails, phones, enums), configure a global /api prefix, and test with Postman.
Learn how to add validation to the update restaurant dto in NestJS, making all fields optional while validating strings, emails, phones, addresses, and categories with decorators.
Validate incoming ids with Mongoose's isValidObjectId, throw a 400 bad request on invalid ids, and apply the check across restaurant service and controllers.
learn to generate coordinates from a restaurant address using node geocoder with MapQuest or Google, extracting latitude, longitude, city, country, and zip code, and store results in the database.
Geocode restaurant addresses into coordinates with MapQuest, returning latitude, longitude, and formatted address for NestJs APIs. Integrate the utility in the restaurant service to store location data in the database.
Learn to add a location field to the restaurant schema, define coordinates and a formatted address, and save the restaurant with its location in the database.
Create an Amazon S3 bucket with public access, configure a policy, and set up an IAM user with programmatic access and S3 full permissions, then add a restaurants folder.
Learn to handle multiple file uploads in NestJS using the FilesInterceptor, at the restaurant upload endpoint, wiring form-data files to the restaurant id and testing with Postman.
Build a NestJS image upload workflow to S3, creating a reusable utility, generate unique file names, configure the S3 client, and upload multiple files with upload responses.
Save restaurant images in a NestJs API by updating a restaurant by id. Send images as an array, validate them, and store them in the database.
Delete restaurant images by extracting image keys, deleting them from the bucket via a dedicated function, and removing the restaurant record when no images remain, in NestJS.
Generate the auth module, controller, and service to enable authentication and sign up and log in, then install passport, JWT, and password packages for secure authentication in NestJS.
Define a user schema in NestJS using mongoose, including name, email (unique), password, and role with a default user, and register the model.
Create a sign up dto with name, email, and password fields, applying validators for required fields, string types, email format with a custom message, and a minimum password length.
Build a nestjs user sign up flow with a model, service, and controller, validating name, email, and password, and saving the user to the database, with password hashing to come.
Hash the user password during signup using bcrypt, store the hashed password in MongoDB, and test with Postman, while handling duplicate email errors in a future step.
Handle duplicate email errors in NestJS by wrapping the operation in a try-catch, detecting MongoDB's duplicate key error (code 11000), and returning a conflict error with a clear message.
Learn to implement user login in NestJs, validating email and password, handling unauthorized errors, comparing passwords, and issuing a token for protected routes.
Set up passport with the JWT strategy in a NestJS app, configure the JWT module using config service to provide secret and expiration, and prepare token issuance for user login.
Sign a JWT token on user login by signing a payload that contains the user id with the NestJS JWT service, and optionally on signup, to secure subsequent requests.
Set up a JWT-based authorization strategy in NestJS by implementing a JWT strategy, extracting tokens from headers, and validating the user to protect routes.
Protect restaurant routes with a jwt auth guard in nestjs. Test access via postman using a saved token from login.
Create a custom current user decorator in NestJs to access the request user from the execution context. Access the user via the decorator or directly from request in controllers.
Learn how to save the current user in a restaurant record using NestJS and Mongoose, including user reference, guards, and authorization checks.
Define a roles decorator and roles guard in NestJS, attach roles metadata, and use a reflector to enforce access so only users with allowed roles can reach protected routes.
Learn to create and apply a roles decorator in NestJS, using metadata with the roles key and a roles guard to authorize access for multiple roles on routes.
Validate restaurant ownership by checking the current user against the owner, enforce forbidden errors for unauthorized updates, and implement authorization checks in NestJs controllers.
If you want to build a powerful API in the modern backend framework Nest Js or if you want to learn how to unit test API then welcome to this Ultimate NestJs course.
Nest Js is a Node.js framework for building efficient, reliable, and scalable Node.js server-side applications. NestJs is a complete framework that will help us to perform everything whether it is authentication or testing a complete API, NestJs provides us with everything that we want. The architecture of NestJs is unmatchable.
Throughout this course, we will use TypeScript which will level up our development. Typescript will help us to write neat and clean code. We will be able to find our errors and bug right on the spot.
NestJs provides us with a lot of flexibility by providing a lot of modules, when it comes to testing, NestJs provides us with Testing Module that makes Unit testing fun. Connecting to a database whether it is Relational (SQL, POSTGRES, etc) or NoSQL (MongoDB) is just fun and can be done in one line of code.
Really NestJs has made life a lot easier when it comes to building backend applications. The API built with this amazing framework is highly testable, scalable, loosely coupled, and easily maintainable applications.
=== Super Fiendly Support ===
If you ever get stuck in any problem, I'm here to unstuck you. I always respond as fast as I can. Because I know there’s nothing worse than getting stuck into problems, especially programming problems. So, I am always here to support you.
Below are some points that we will cover in this course:
We will discuss what is NestJs and its CLI
Build a complete restaurant API
Use MongoDB to store our data
Add Pagination and Search in our API
Best practices for Error handling & Validations with PIPES
Generate the coordinates of the restaurant address
Uploading multiple images of the restaurant to AWS S3 Bucket
Add Jwt Authentication with Passport
Authorization of Roles with Guards
Build a CRUD Library API with Postgres & TypeORM
Unit Testing of complete API
e2e Testing to API
Deploying API on Heroku
Interested in learning this amazing NestJs framework for building your next backend API? Then Enroll now and I will see you in the course. Happy Coding!!!