NestJs: Modern ways to build APIs with Typescript and NestJs
3.8 (52 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
4,686 students enrolled

NestJs: Modern ways to build APIs with Typescript and NestJs

Step by Step guide to build Restful and GraphQL APIs with Node.Js, Nest.Js, MongoDB, Mysql, Postgres, and Typescript etc
3.8 (52 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
4,686 students enrolled
Created by Haider Malik
Last updated 2/2020
English
English [Auto]
Current price: $139.99 Original price: $199.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 11 hours on-demand video
  • 4 articles
  • 45 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • NestJs Fundamentals
  • Typescript Decorators, Generics and Classes
  • Build RESTFUL APIs with NestJs and MongoDB
  • Build RESTFUL APIs with NestJs and MySQL
  • Build RestFUL APIs with NestJs and PostgresQL
  • Deploy RESTFUL APIs
  • Build GraphQL APIs with NestJs
  • Add Documentation for your APIS
  • Authentication and Authorization using PassportJs
Course content
Expand all 90 lectures 10:58:11
+ Getting started with NestJs
5 lectures 21:19

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!

Preview 05:59

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.

Preview 03:25

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.

Preview 04:35

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:

Preview 03:45

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.

Preview 03:35
+ Typescript Foundations (Optional)
15 lectures 43:43

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.

What are Generics
02:34

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

Typescript Setup and Installation
03:57

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).

Generic Function
03:07

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.

Generic Function T Array Type
02:29

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

Generic Function with Multiple Type Variables
02:22

In this lecture, I will teach you how to restrict the generic function to specified type.

Generic Constraints
02:19

In this lecture you will learn how to define interfaces to define the object properties and function type

Generic Interfaces to describe Object Properties
04:46
Create Interface to describe Function Type
03:17

In this lecture, I will teach you how to create Interface to describe the function type

Generic Classes and Interfaces
02:11
Introduction to Decorators
03:03

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.

Arguments in Method Decorator
04:31

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.

Configurable Decorator using Decorator Factory.
01:46

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

Property Decorator
04:28

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.

Parameter Decorator
02:15

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.

Class Decorator
00:38
+ CRUD With NestJs
4 lectures 22:42

In this video, I will teach you what are you going to build in this section. We will build basic CRUD functionalities with Array.

Module Introduction
02:05

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

Create Post Endpoint to Save Record in Array
09:05

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

Request Payload in NestJs
06:41

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

FindAll and Delete Endpoint
04:51
+ Pipes and Validations
3 lectures 14:42

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

What are Pipes
02:37

In this video, we are going to validate request payload using built-in ValidationPipe. We will define decorator based validations in DTO object.

Add Validations using ValidationPipe
06:26

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

Understand How ValidationPipe works
05:39
+ Middlewares and ExceptionFilters
3 lectures 18:53

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.

What are Middlewares
02:12

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

Creating a Custom Logging Middleware
06:27

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.

Creating HttpException Filter
10:14
+ Interceptors
2 lectures 16:39

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.

What are Interceptors
01:44

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

Create Interceptor to Transform the Response
14:55
+ Connecting NestJs app with TypeORM and Mysql
5 lectures 44:56

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

Installing Mysql server
04:44
Connect NestJs to Mysql using TypeORM
06:59

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():

Create an Entity to map a Database Table
05:15

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

Save new record in MySQL Database Table
09:57

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

Get, Update, and Delete Record
18:01
+ Relations between Entities
4 lectures 01:37:06

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.

Adding One to One Relation between Entities
08:01

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

CRUD with One to One Relationship
29:59

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.

Adding One to Many or Many to Many Relation between Entities
36:34

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.

Adding Many to Many Relation between Entities
22:32
+ Connected NestJs App to MongoDB using Mongoose
2 lectures 14:40

In this lecture, You will learn how to install MongoDB on your machine

Installing MongoDB
00:00

In this video, I will teach you how to connect NestJs application with MongoDB using Mongoose package.

Connecting NestJs App with MongoDB
14:40
+ Authentication
5 lectures 01:01:04

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

Introduction to Authentication
04:32
Implement Signup User
14:27
Implement Login User
14:13

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,

Introduction to PassportJs
03:56

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.

Authenticate User using Passport-JWT Strategy
23:56
Requirements
  • Having a basic understanding of JavaScript and/or NodeJS
  • Having basic knowledge of TypeScript is recommended, but not required
Description

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.


Who this course is for:
  • Intermediate JavaScript developers who want to dive into back-end development
  • Any developer wants to learn how to build backend server side applications with Typescript
  • Developers who want to learn how build Restful apis with NestJs, MongoDB and MySQL
  • Developers who want to learn how to secure your APIs using JWT
  • Developers who want to learn how to deploy NestJs application
  • Developers who want to learn how to GraphQL APIs with NestJs