
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!
In this video, you are going to learn how to create controller in Nest.js. You will learn how to define routes in NestJs
Controllers are responsible for handling incoming requests and returning responses to the client.
In this video, I will teach you how to access the express request object in NestJs.Handlers often need access to the client request details. Nest provides access to the request object of the underlying platform (Express by default). We can access the request object by instructing Nest to inject it by adding the @Req() decorator to the handler's signature.
Earlier, we defined an endpoint to fetch the cats resource (GET route). We'll typically also want to provide an endpoint that creates new records. For this, let's create the POST handler:
In this video, I will teach you how to set status code manually using @HTTPCODE. You will also learn how to redirect user to another external URL. I will teach you how to get Route Parameters from the request url.
A major part of software engineering is building components that not only have well-defined and consistent APIs, but are also reusable. Components that are capable of working on the data of today as well as the data of tomorrow will give you the most flexible capabilities for building up large software systems.
In languages like C# and Java, one of the main tools in the toolbox for creating reusable components is generics, that is, being able to create a component that can work over a variety of types rather than a single one. This allows users to consume these components and use their own types.
In this lecture, I will teach you how to install and setup typescript with Node.js
There are two main ways to get the TypeScript tools:
Via npm (the Node.js package manager)
By installing TypeScript’s Visual Studio plugins
For NPM users:
> npm install -g typescript
You have to create the .ts file and run the tsc and typescript file
The primary reason you create a generic function is because you have some code that meets two criteria:
It's a function or class that will work with a variety of data types
The function or class uses that data type in several places
You have other options: When you have code that works with a variety of data types, you could write one version of the function for each data type, but that's a lot of work and a maintenance nightmare. You could also write one function and have it use the any keyword for its data types, but that would mean abandoning type safety.
Provided that the data types involved are used in several places in your code, a generic function or class is a better solution than your other options: generic functions let you write one version of your code and ensure that the code consistently uses data types (and then, of course, let the developer specify the data type when calling the function/instantiating the class).
In the above example, the type variable T is specified with the function in the angle brackets getArray<T>. The type variable T is also used to specify the type of the arguments and the return value. This means that the data type which will be specified at the time of a function call, will also be the data type of the arguments and of the return value.
In this lecture I will teach how you can create generic function to accept multiple type variables. You can also create a generic function with multiple Type variables
In this lecture, I will teach you how to restrict the generic function to specified type.
In this lecture you will learn how to define interfaces to define the object properties and function type
In this lecture, I will teach you how to create Interface to describe the function type
Each kind of decorator requires a different function signature, as the decorator is provided with different parameters depending on the decorator use. This section will provide several practical examples that can be used as a starting point for your own decorators.
You can make a decorator configurable by converting your decorator function into a decorator factory. A decorator factory is a function that returns a decorator function. The factory can have any number of parameters that can be used in the creation of the decorator.
In this video, we are going to learn about property decorator. A property decorator can only be used to observe that a property of a specific name has been declared for a class. Property decorators ignore any return, underscoring their inability to affect the decorated properties
In this video, you are going to learn about Parameter decorator. A parameter decorator can only be used to observe that a parameter has been declared on a method.
In this lecture, you are going to learn about class decorator. It allows programmers to modify the behaviour of function or class.Decorators allow us to wrap another function in order to extend the behaviour of the wrapped function, without permanently modifying it.
In this video, I will teach you what are you going to build in this section. We will build basic CRUD functionalities with Array.
In this video, I will teach you how to create a POST endpoint to save record in Array. I will teach you how to inject the service into controller by using dependency injection pattern
In this video, I will teach you how to get request payload using DTO. A DTO is an object that defines how the data will be sent over the network. We could determine the DTO schema by using TypeScript interfaces, or by simple classes. Interestingly, we recommend using classes here
In this video, we will create a find all endpoint to fetch all the records. You will also learn how to implement delete endpoint to delete all the records
Pipes have two typical use cases:
transformation: transform input data to the desired output
validation: evaluate input data and if valid, simply pass it through unchanged; otherwise, throw an exception when the data is incorrect
In this video, we are going to validate request payload using built-in ValidationPipe. We will define decorator based validations in DTO object.
In this video, we will review the source code of ValidationPipe. I will show you how ValidationPipe works in under the hood. How ValidationPipe uses class-validator and class-transformer package
Middleware is a function which is called before the route handler. Middleware functions have access to the request and response objects, and the next() middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next.
In this video, you are going to learn how to create a custom logging middleware in NestJs. You are going to learn middlewares works in Nestjs
While the base (built-in) exception filter can automatically handle many cases for you, you may want full control over the exceptions layer. For example, you may want to add logging or use a different JSON schema based on some dynamic factors. Exception filters are designed for exactly this purpose.
In this video, I will teach you what are interceptors and why do we need them. An interceptor is a class annotated with the @Injectable() decorator. Interceptors should implement the NestInterceptor interface.
In this video, I will show you how to map the response before sending to the client. We will create a custom interceptor to map the response
In this lesson, I will teach you how to install Mysql server on your machine. You will also learn how to install Mysql workbench on your machine
Connect a NestJS application to MySQL using TypeORM, define entities in TypeScript, and leverage repositories, transactions, and automatic schema synchronization to map objects to relational tables.
In this video, we will create an Entity in NestJs Project. Entity is a class that maps to a database table (or collection when using MongoDB). You can create an entity by defining a new class and mark it with @Entity():
In this video, I will teach you how to save new record in new record in MySQL database table using TypeORM repository API. TypeORM Repository provides CRUD functions , we are going to use these functions
In this video, I will teach you how to find, update and delete products from Mysql database. I will show you how to use TypeORM repository to implement these methods
One-to-one is a relation where A contains only one instance of B, and B contains only one instance of A. Let's take for example User and Profile entities. User can have only a single profile, and a single profile is owned by only a single user.
In this video, I will show you how to perform Create, Update, Delete, and Find the records with one to one relation. You will learn how to add data in relation entities
Many-to-one / one-to-many is a relation where A contains multiple instances of B, but B contains only one instance of A. Let's take for example User and Photo entities. User can have multiple photos, but each photo is owned by only one single user.
In this video, I will teach you how to implement many to many relationship. Many-to-many is a relation where A contains multiple instances of B, and B contain multiple instances of A. Let's take for example Question and Category entities. Question can have multiple categories, and each category can have multiple questions.
In this lecture, You will learn how to install MongoDB on your machine
In this video, I will teach you how to connect NestJs application with MongoDB using Mongoose package.
In this lecture, I will teach you what is Authentication and why Authentication is important. I will also teach you the basics of JSON Web Token authentication. How Json Web Token Authentication works
Implement signup by checking existing users by email, inject a password hash service to encrypt passwords before saving to MongoDB, and throw an unauthorized error on duplicates.
Implement the login method in the user service, verify email and password with a hash service, and generate a JWT token to return a login response.
Passport is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter,
In this video, You are going to learn how to authenticate user using Passport JWT Strategy in NestJs application. A Passport strategy for authenticating with a JSON Web Token. This module lets you authenticate endpoints using a JSON web token. ... secretOrKey is a string or buffer containing the secret (symmetric) or PEM-encoded public key (asymmetric) for verifying the token's signature.
Nest.js is a progressive Node.js framework for building efficient, reliable and scalable server-side applications. NestJS is a server-side (backend) application framework beautifully crafted to support developers productivity and make their lives happier. Well, it's not only a framework, it's an enabler of entering the world of advanced engineering concepts such as Domain Driven Design, Event Sourcing, Microservices architecture.
I spent a good few years in my career developing large scale apps and it didn’t let me down any single time. It’s well written, having quality as an objective, modular web framework with a good documentation, delivering nice developer experience. Exactly the same way I’d describe Nest.
NestJs is built on the top of Typescript and Express.js. It also combines some elements of Object Oriented Programming and functional programming.
Here comes NestJS, a framework which is fully written in TypeScript (it supports JS too, but types are good), it’s easily testable and brings in all the necessary stuff you always think about but you don’t know what to choose.
Why NestJs?
NestJS doesn’t try to limit you to a particular way of doing things, it just provides the tooling you need. It doesn’t try to reinvent the wheel, it utilize existing tools you already know. For example, it uses express behind the scenes which makes your app compatible with the majority of express middlewares.
Here are some good reasons why NestJS shines:
Dependency Injection — NestJS provides DI straight out of the box, increasing efficiency, modularity and testability of applications.
Modularisation — NestJS provides a modular structure for organizing code within the same domain boundary into separate modules.
Flexibility — NestJS provides structure, which helps large teams build complex applications and yet comes in as lightweight as possible, so how you want to build is your choice.
Familiar APIs you already know — NestJS is heavily inspired by Angular, it is also quite similar to much established frameworks like Spring and .NET. This provides a shorter learning curve and lower entry threshold for developers.
Community — NestJS is the fastest rising framework, already with 14K stars surpassing HapiJS. Also, with NestJS leveraging on the Angular way of doing things, things can only get better for the community.
In this course, I will teach you the foundations/fundamentals of NestJs. I will teach you how to build RESTFUL APIs step by step. You will also learn how to plan, design and deploy APIs. I have also another separate section of GraphQL.