
Learn to build and deploy a modular, high-performing RESTful list API with NestJS and MongoDB, from basics to production deployment, following best practices for scalable web services.
Learn representational state transfer concepts, resources and representations, and how content negotiation with accept and content-type headers enables http verbs on resources such as /api/contacts.
Discover how NestJS, an open source MIT-licensed framework, enables scalable, testable server-side apps with TypeScript, Express by default, and architecture inspired by Angular.
Install node.js and npm, install visual studio code, configure the code command in path, install the NestJS CLI globally, verify versions, and prepare to create a NestJS project.
Create your first NestJS application by running nest new, select npm, and start the dev server to see hello world on localhost:3000; explore modules, controllers, and decorators.
Learn to generate a NestJS module and controller for a contacts resource, implement http get handlers to list all contacts and retrieve a single contact by id, with error handling.
Implement a NestJS post handler that accepts a single or multiple contacts, assigns new ids, and adds them to the contacts collection, returning the updated data as json.
Implement a put handler using the id parameter and request body to find and replace a contact, returning the updated contact. Return a not found error on a missing id.
Learn to perform partial updates with HTTP patch in a NestJS MongoDB REST service by merging the patch body into the existing contact data, updating only the specified fields.
Explore soft deletes with isActive and discontinued, and implement delete by id in a NestJS sample, removing an array element with splice while testing via Postman.
Explore providers in NestJS: classes annotated with @Injectable enable dependency injection, with singleton or per-request scope, and register providers in a module to inject via constructor.
Create a Nest project to understand providers by building a context module, controller, and contact service with dependency injection, and persist contacts to a JSON file using fs-extra.
Implement a NestJS post /contacts endpoint with a service that adds one or many contacts, assigns generated ids, updates an in-memory array, and persists data to a file.
Define a get all contacts endpoint in NestJS, where the service returns a copy of the contacts and the controller handles a get request, returning the contacts array.
Implement a get /contacts/:id endpoint with a get one contact service, returning the contact when found and undefined if not. Map the id path segment to the parameter.
Implement put to replace an entire payload by id, patch to update specific fields such as name or email, and delete by id with no payload.
Demonstrate three restful operations in a NestJS service: update full, patch, and delete by id, with id existence checks, array indexing, and file writes, plus controller wiring and verification.
Understand nest middleware runs before controllers, mirroring express. It can modify request or response and uses next() to continue, implemented as a function or injectable class for logging and auth.
Register a class-based logger middleware in NestJS to log incoming requests, including method, path, and body, then apply it to routes using a middleware consumer.
Learn to implement function-based and third-party middlewares in a NestJS restful API, register them in the app module, and configure access-control headers and helmet for security.
Nest's built-in exception Leon handles unhandled errors and returns user-friendly json. The lecture demonstrates checking the authorization header, throwing an http exception with a status code, and customizing the response.
Learn to create a custom exception hierarchy in NestJS, extend the base http exception, and throw a file not found exception to produce precise error responses in JSON.
Learn to build and apply custom exception filters in NestJS to take control of error handling, log details, and return structured JSON responses at the handler, controller, or global level.
Explore NestJS pipes, including built-in validation and transformation pipes, to convert inputs (like strings to numbers), apply default values, and handle pagination with page and limit parameters.
Learn to create and use a custom NestJS pipe for input validation and transformation, including a mandatory fields pipe, payload checks, and simple transformations like uppercase.
Explore validating incoming payloads in NestJS using the validation pipe and class-validator, defining a contact model with decorators for required fields, min and max length, email, and class-transformer.
Discover MongoDB as a cross-platform, document-oriented NoSQL database, with collections of flexible documents and fast queries through sharding, while noting lack of transactions and joins.
Install MongoDB community server on your local machine, unzip the download, set the data directory, start mongod on port 27017, and connect with the mongo shell to view databases.
Learn the basics of the MongoDB shell, including show databases, switch databases, create collections on the fly by inserting data (auto-generated _id), and query with find, findOne, and pretty.
Create a new nest project with class-validator, class-transformer, and mongoose, install dependencies, run the dev server on port 3000, and scaffold context module, controller, and service.
Create a contacts module with a controller and a service in a NestJS app, wiring in mongoose for MongoDB and preparing a contact model for resource management.
Create a contact class and a Mongoose schema in a NestJS app to validate and persist contact data using decorators for email, name, phone, city, state, and country.
register the contact model with mongoose, inject it into the service, and implement a post /contacts endpoint that validates input and saves a contact with unique email and phone.
Implement a get all contacts endpoint with pagination by using page and limit query parameters, apply a skip offset, and return a paginated subset from MongoDB.
Implement a NestJS get endpoint to fetch a contact by id from MongoDB, mapping the id parameter and using async/await to resolve the find by id, with error handling.
Learn to update a document via put in NestJS with an id path parameter and a payload, validate input, and return 204 no content on success or 400 bad requests.
Learn to implement a bottom-up delete endpoint in nestjs with mongodb by building a delete contact function, using async/await, returning 204 no content, and handling not found scenarios.
Implement partial document updates with a PATCH request in nestjs and mongodb, using path id and a possibly different body, returning 204 no content on success.
Connect a NestJS app to a cloud MongoDB Atlas cluster, set up IP whitelisting and a user, and test get and post /contacts against the phonebook Contacts collection.
Deploy your app on Heroku, a platform as a service with managed containers and data services. Sign up for a free account to use the Heroku CLI.
Install the Heroku CLI across Windows, Linux, and Ubuntu using npm install -g heroku or alternative methods, with sudo when needed. Log in to authenticate and push code to Heroku.
Deploy a NestJS and MongoDB app to Heroku, configuring port and cors. Create a Heroku app and Procfile, push code with git, and test endpoints with Postman.
Explore MongoDB's document model where collections hold dynamic BSON documents with varying field structures, and learn how single-document storage avoids joins, subqueries, and lacks transactions.
Install MongoDB on Windows by downloading the installer and configuring the data folder and environment variables. Start the server with mongod, then verify connectivity using the mongo shell.
Insert documents into a MongoDB collection using insert commands, illustrating a schema-less database where each document can have different structures. Use find and pretty to view results.
Import data into MongoDB from external files (CSP, DSV, JSON) using mongoimport; specify data type, database, and collection (created if needed), then verify with find.
Learn to execute multiple MongoDB commands by creating a script and feeding it to the mongo shell, connecting to localhost:27017 and the test database's contacts collection.
This lecture compares save() and insert() in MongoDB, showing insert creates a new document and may fail on duplicate _id, while save updates an existing document.
Learn how to use selection and projection in MongoDB queries by defining criteria and a projection to include fields like first name, last name, and city, with _id included.
Learn to select documents in MongoDB for a NestJS RESTful service by specifying a condition like city equals Chicago, using projection and operators such as $eq to filter results.
Import sales data into a MongoDB collection named sales, then run complex queries such as finding documents with a sales amount greater than ten thousand and pretty-print results.
Explore building MongoDB queries in NestJS apps using $and, $or, and $in to filter sales data by amount between 5000 and 6000 and by quarters 1 or 3.
Use the $where operator to filter documents in the sales collection with a JavaScript condition evaluated on the current document, including equals and range checks.
Master aggregation in MongoDB by grouping employees by department and counting members with sum. Compute department-level average salaries, filter with match for averages over 4000, and sort by salary.
Explore using the mapReduce function in MongoDB to group documents by department and summarize salaries with a map and reduce workflow, using conditional emission to filter results.
Create and use a single field index on the phone property in contacts to speed queries, verify with explain, and manage indexes with get indexes and drop index.
Demonstrates updating MongoDB documents by filtering with _id, highlighting the difference between replacing a whole document and using $set to modify specific fields or add new ones.
Explains the upsert operation in MongoDB: update a product when found, or insert it when not found, using a sample with id 100 and $set to preserve fields.
Learn how to update multiple documents in MongoDB from a NestJS app by incrementing the price of all Fishell brand products, using multi update options and verification.
Learn how to remove documents in a MongoDB collection with the remove command, deleting multiple matching records or a single document with limit 1, noting deletions are irreversible.
Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!
Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. This allows developers the freedom to use the myriad of third-party modules which are available for the underlying platform.
In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications. This has given rise to awesome projects like Angular, React and Vue, which improve developer productivity and enable the creation of fast, testable, and extensible frontend applications. However, while plenty of superb libraries, helpers, and tools exist for Node (and server-side JavaScript), none of them effectively solve the main problem of - Architecture.
Nest provides an out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. The architecture is heavily inspired by Angular.
In this course I am going to guide you through the process of planning, developing and deploying a fully-featured RESTful web service using TypeScript+NestJS on Node platform.