NestJS

NestJS

NestJS - A progressive Node.js framework NestJS is a framework for building efficient, scalable Node.js web applications.
Torrey  Kuphal

Torrey Kuphal

1620543752

NestJS Authentication: JWTs, Sessions, Logins, and More! | NestJS PassportJS Tutorial

In this video we’ll discuss the fundamentals of adding authentication to your NestJS API. We’ll talk about utilizing passport to use different types of authentication strategies. Specifically we will try the passport-local strategy as a basic login with username and password example. Next, we’ll take a look at potentially using sessions to store user information and persist their login state. Finally we will also take a look at a state-less approach with JSON Web Tokens (JWTs). We’ll create our own JWTs and I’ll show you how you can use that to protect your API routes!

  • 00:00 - Intro
  • 03:35 - Initial routes
  • 04:41 - UsersService
  • 07:50 - AuthService
  • 10:40 - Implementing passport-local strategy (username/password login)
  • 18:08 - AuthGuards
  • 23:25 - Summary of local login flow
  • 29:02 - Guard to check if user is authenticated
  • 31:41 - Setting up sessions
  • 40:37 - Summary of login with sessions flow
  • 44:25 - Setting up JWT strategy, signing and validating
  • 1:00:25 - Summary of JWT strategy flow
  • 1:04:22 - Conclusion
  • 1:05:20 - Outro

#nestjs #nest #node #nodejs #security

NestJS Authentication: JWTs, Sessions, Logins, and More! | NestJS PassportJS Tutorial
Alfredo  Yost

Alfredo Yost

1591199520

NestJS | Why you should use NestJS | APIs Development | Node JS MVC | Webcast

Learn Geek stuff [Angular, React, Redux, Nodejs, Web development, Docker, AWS, Vue JS, All about Javascript]

#nestjs #apis development #apis development

NestJS | Why you should use NestJS | APIs Development | Node JS MVC | Webcast
Shukran  Ihsan

Shukran Ihsan

1620356700

Google Authentication using NestJs | NestJs Google oAuth | Source Code

In this video, we will learn about How to Authenticate Google using NestJs | NestJs Google oAuth | Source cod

Source Code:
https://github.com/adavijit/AVDOJO-TU

Subscribe: https://www.youtube.com/c/AVDojo/featured

#nestjs #node #javascript

Google Authentication using NestJs | NestJs Google oAuth | Source Code
Markus  Bartell

Markus Bartell

1611215460

Why NestJS Is Awesome

– Why NestJS Is Awesome –
In this video I’'m explaining why NestJS is awesome and why you should use it for your next project.

#nestjs

Why NestJS Is Awesome
Alex Lambert

Alex Lambert

1587671280

Swagger in NestJS

A quick demonstration how you could add swagger to a nestjs application to document your api.


Links

My Code - https://github.com/kelvin-mai/nestjs-blog

#nodejs #nestjs #javascript

Swagger in NestJS
Luca Fecarotta

Luca Fecarotta

1584166789

What's New in NestJS 7?

Today I am excited to announce the official release of NestJS 7. This is a major release spanning the entire platform, including the framework, numerous changes to the @nestjs/graphql package, CLI improvements, and updated documentation.

In case you’re not familiar with NestJS, it is a TypeScript Node.js framework that helps you build enterprise-grade efficient and scalable Node.js applications.

Last year was great for our community. In 2019, Nest has been recognised as the fastest-growing Node.js technology in the world. We’ve also made it to the TOP 20 GitHub repositories on the whole globe, and, according to NPM metrics, experienced an almost 400% growth in number of downloads on NPM, and thus becoming one of the most popular Node.js libraries with roughly 1 million of downloads each month! 2019 was amazing and we expect 2020 to be even better for the whole ecosystem!

What’s new?

This release brings lots of great features and long-awaited improvements. There are far too many to list here, but let’s take a high-level look at some of the most exciting ones.

GraphQL ❤️ TypeScript

In the version 6 major release of NestJS, we introduced the code first approach as a compatibility layer between the amazing type-graphql package and the official @nestjs/graphql module. This allowed us to solve types redundancy problems by automatically generating GraphQL SDL from TypeScript metadata using decorators.

However, despite the numerous new opportunities that this integration has brought, we have faced many challenges that did not seem easily solvable down the road.

  • The integration required developers to mix decorators coming from two different libraries. If you’ve messed up the imports, all your resolvers would stop injecting dependencies through constructor (all of them would be equal to undefined). Thus, developers reported many bugs and issues, assuming that the integration doesn’t work at all.

  • To generate a schema, type-graphql generates resolve function for each field. However, Nest has its own DI system that links dependencies and instantiates classes (in this case, providers), which methods are later being bounded to GraphQL fields. Hence, it led to unnecessary memory allocations.

  • Lastly, the code first approach requires using many additional decorators to define input types, args, etc. Initially, we decided to simply link to the external library documentation. However, the API of decorators which wrapped external decorators was somewhat different (because we must support schema first approach as well). We also didn’t want to duplicate the documentation in the NestJS documentation because maintaining it would become impossible in the long run (adjusting to API changes, etc.).

So what did we do?

In order to future-proof the library to meet the needs of the community, we needed to reimplement all the features from scratch due to a lack of predictability and flexibility while dealing with the third party library.

To avoid lots of breaking changes, we did our best to make sure that the public API IS backwards-compatible.

Therefore, with a simple update: (search & replace) all the type-graphql imports to use @nestjs/graphql, and that’s it. 🎊

import { Field, Int, ObjectType } from '@nestjs/graphql';
import { Post } from './post';

@ObjectType()
export class Author {
  @Field(type => Int)
  id: number;

  @Field({ nullable: true })
  firstName?: string;

  @Field({ nullable: true })
  lastName?: string;

  @Field(type => [Post])
  posts: Post[];
}

Learn more about the code first approach here.

NestJS GraphQL Plugin

In addition, switching to our own Typescript & GraphQL implementation, allowed us to create a plugin

To reduce the amount of boilerplate code required, Nest now provides a new GraphQL plugin (for code first applications) that enhances the TypeScript compilation process.

Hint This plugin is also opt-in. If you prefer, you can declare all decorators manually, or only specific decorators where you need them.

The new GraphQL plugin will automatically:

  • annotate all input object (@InputObject), object type (@ObjectType) and args (@Args) classes properties with @Field decorator unless @HideField is used
  • set the nullable property depending on the question mark (e.g. name?: string will set nullable: true)
  • set the type property depending on the type (supports arrays as well)

Therefore, the example shown above can be rewritten as follows:

import { Field, Int, ObjectType } from '@nestjs/graphql';
import { Post } from './post';

@ObjectType()
export class Author {
  @Field(type => Int)
  id: number;
  firstName?: string;
  lastName?: string;
  posts: Post[];
}

The plugin adds appropriate decorators on the fly based on the Abstract Syntax Tree.

TIP: You no longer have to struggle with @Field boilerplate decorators scattered throughout the entire project. They will be added automatically.

Learn how to enable the plugin here.

Flexible Custom Decorators

The custom decorators API has been unified for all types of applications. Now, whether you’re creating a GraphQL application or a REST API, the factory passed into the createParamDecorator() function will take the ExecutionContext (read more here) object as a second argument.

import { createParamDecorator, ExecutionContext } from '@nestjs/common';

export const User = createParamDecorator(
  (data: unknown, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest();
    return request.user;
  },
);

Now, to determine the type of application that our decorator is currently evaluated, use the getType() method:

const type = host.getType();
if (type === 'http') {
  // HTTP application
} else if (type === 'rpc') {
  // Microservice
}

Improved Microservices

To enable the request-response message style, Nest creates two logical channels - one is responsible for transferring the data while the other waits for incoming responses.

For some underlying transports, such as NATS, this dual-channel support is provided out-of-the-box. For others, Nest compensates by manually creating separate channels.

Let’s say that we have a single message handler @MessagePattern('getUsers'). In the past, Nest built two channels from this pattern: getUsers_ack (for requests) and getUsers_res (for responses). With version 7, this naming scheme changes. Now Nest will build getUsers channel (for requests) and getUsers.reply (for responses) instead. Also, specifically for the MQTT transport strategy, the response channel would be getUsers/reply.

This change simplifies the integration with external systems, existing legacy applications, and also, allows avoiding clashes with wildcard subscriptions available in, for example, MQTT strategy.

Furthermore, the overall performance will improve. From now on, Nest will no longer send out redundant information as part of the message packets (in the request-response message style), hence, decreasing their size.

New Pipes

Nest v7 comes with 2 NEW pipes available out-of-the-box, respectively ParseBoolPipe and ParseArrayPipe (both exported from the @nestjs/common package).

While ParseBoolPipe is just another transformer pipe which along with the existing ParseIntPipe can implicitly transform & validate values based on the expected type (read more here), ParseArrayPipe is a solution for sending either unwrapped or serialized arrays through the network.

Basically, TypeScript does not store metadata about generics or interfaces, so when you use them in your DTOs (Data Transfer Objects), ValidationPipe may not be able to properly validate incoming data. For instance, the code below won’t be correctly validated:

@Post()
createBulk(@Body() createUserDtos: CreateUserDto[]) {
  return 'This action adds new users';
}

Previously, to validate the array you had to create a dedicated class which contained a property that wraps the array. Now, you can simply use the ParseArrayPipe.

@Post()
createBulk(
  @Body(new ParseArrayPipe({ items: CreateUserDto }))
  createUserDtos: CreateUserDto[],
) {
  return 'This action adds new users';
}

In addition, the ParseArrayPipe may come in handy when parsing query parameters. Let’s define the findByIds() method that returns users based on identifiers passed as query parameters.

@Get()
findByIds(
  @Query('id', new ParseArrayPipe({ items: Number, separator: ',' }))
  ids: number[],
) {
  return 'This action return users by ids';
}

And test this endpoint using cURL:

$ # GET /?ids=1,2,3
$ curl http://localhost:3000/?ids=1,2,3

The stringified ids query parameter (ids=1,2,3) will be automatically transformed to an array. In addition, each item will be validated and eventually, parsed to a number.

Implicit type conversion

With the auto-transformation option enabled (transform: true), the ValidationPipe will now perform conversion of primitive types. In the following example, the findOne() method takes one argument which represents an extracted id path parameter:

@Get(':id')
findOne(@Param('id') id: number) {
  console.log(typeof id === 'number'); // true
  return 'This action returns a user';
}

By default, every path parameter and query parameter comes over the network as a string. In the above example, we specified the id type as a number (in the method signature). Therefore, the ValidationPipe will try to automatically convert the string identifier to a number.

Documentation

Our official documentation has significant improvements to GraphQL section. We now cover most of features / functionalities you may need to get started with either schema first or code first approaches.

We strongly believe that this update will strongly improve the development experience. 🐈

Thank you

#nestjs #nodejs #webdev #javascript

What's New in NestJS 7?

Sistawan Ketut

1615018740

NestJS MongoDB CRUD

In this video, we will create a simple Microservices example with NestJS, We learn how to create an Event-Driven Architecture with RabbitMQ. We will explore how to use NestJS with a Relational Database like MySQL and a NoSQL Database like MongoDB.

Subscribe: https://www.youtube.com/channel/UCljAHzX-PBxv6WrXkI2rnQw

#nestjs #mongodb #javascript

NestJS MongoDB CRUD

A Sample On NestJS Queues

Hi everyone,

Separate CPU-bound operations or long time is taken operations as separate jobs using Queues in NestJS.

The entire session made as a blog:
https://www.learmoreseekmore.com/2021/04/guide-on-nestjs-queues.html

video about Redis docker setup:
https://youtu.be/xE8SYYj0Xpg

#naveentechseeker #nestjs #queues #naveenbommidi

#nestjs

A Sample On NestJS Queues
Lulu  Hegmann

Lulu Hegmann

1614589083

Getting Started with NestJS

NestJS is a backend framework, build on top of NodeJS and ExpressJS to create server-side applications, it is best suited for REST APIs as it is really quick to get a REST API running with NestJS. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript), and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming). The architecture of the NestJS is mostly inspired by AngularJS.

Pre-requisite in terms of technical knowledge:

  • Knowledge of modern JS programming approaches.
  • Experience in working with NodeJS, ExpressJS, Typescript (Not a requirement, but this will help you to understand and get things running quickly)
  • Experience working with MongoDB, mongoose
  • Basic knowledge of Decorators

Requirements for your system:

  • You will need to have NodeJS & NPM (Node package manager) installed, You can download the latest version from here.


#nodejs #nestjs #javascript #node #nest

Getting Started with NestJS

Sistawan Ketut

1615282500

NestJS Microservices Introduction

In this video, we will create a simple Microservices example with NestJS, We learn how to create an Event-Driven Architecture with RabbitMQ. We will explore how to use NestJS with a Relational Database like MySQL and a NoSQL Database like MongoDB.

Subscribe: https://www.youtube.com/channel/UCljAHzX-PBxv6WrXkI2rnQw

#nestjs #javascript

NestJS Microservices Introduction

Event Sourcing with NestJS

In my latest post, I have described how Event Sourcing can be a better architectural choice then CRUD, especially when it is necessary to capture intent, purpose, or reason. I have also shown that by integrating the CQRS pattern with Event Sourcing, we can achieve a performant read model, as this pattern allows us to separate the Read Model from the Write Model, making them independently scalable.
In the following post, we will show how to apply those principles when designing the Write Model of an IoT analysis platform. For the sake of simplicity, we will focus on implementing one single write functionality — Connecting a new device to the platform.
Why NestJS?
NestJS is a progressive Node.js framework for building efficient, reliable, and scalable server-side applications — Using modern JavaScript, built with Typescript, combining elements of OOP, FP, and FRP and is heavily inspired by Angular framework.

#nestjs #nodejs #event-sourcing #iot #domain-driven-design

Event Sourcing with NestJS
Bongani  Ngema

Bongani Ngema

1620906360

How to Use Versioning in NestJS

When developing REST APIs, it’s not uncommon that there are breaking changes that need to be made, potentially affecting the contract or behavior of the endpoint.

The issue with making breaking changes is that consumers will be affected, whether they need to quickly change their application to address your breaking changes, or have unexpected behavior that previously didn’t occur. Regardless of the impact, it’s not practical to make breaking changes without supporting the previous version.

That is where versioning comes in. Versioning allows you to have different versions of endpoints that are simultaneously active. It allows developers to make a new version that includes breaking changes, while still being able to support the previous version(s). This allows consumers to upgrade on their own timeline and overall reduces headaches.

Versioning has been added to v8 of NestJS, which at the time of writing this article, has not been fully released. However, the preview version 8.0.0-alpha.3 has been released and includes the versioning functionality, so we will be using that version in the examples of this article.

Within NestJS, there are 3 types of versioning that are supported:

  1. URI Versioning: The version is passed within the URI of the request
  2. Header Versioning: A custom request header will specify the version
  3. Media Type Versioning: The Accept request header will specify the version

For the focus of this article, we’ll be using Media Type Versioning .

Setting up your NestJS application

This section will walk you through setting up a new NestJS application with the required setup for versioning.

First, ensure that you have node v10.13.0 or higher installed, as well as npm, which should be installed with node automatically.

Next, we’ll install and use the NestJS CLI to generate a new application.

$ npm i -g @nestjs/cli
$ nest new nest-versioning-demo

#nodejs #nestjs #javascript

How to Use Versioning in NestJS

NestJS File Upload

Hi everyone,

This video on file uploading endpoint in NestJS application

This entire session made as a blog:
https://www.learmoreseekmore.com/2021/01/nestjs-file-upload.html

#naveentechseeker #nestjs #fileupload #nest

#nestjs

NestJS File Upload

Sistawan Ketut

1615192518

How to Connect NestJS with RabbitMQ

In this video, we will create a simple Microservices example with NestJS, We learn how to create an Event-Driven Architecture with RabbitMQ. We will explore how to use NestJS with a Relational Database like MySQL and a NoSQL Database like MongoDB.

Subscribe: https://www.youtube.com/channel/UCljAHzX-PBxv6WrXkI2rnQw

#nestjs #nodejs #javascript #node

How to Connect NestJS with RabbitMQ

NestJS Roadmap for Beginners

Getting started with NestJS — a tutorial for beginners.

Introduction

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

Why use NestJS?

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.

There are superb libraries, helpers, and tools that 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 that allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. The architecture is heavily inspired by Angular.

#programming #nodejs #javascript #nestjs #typescript

NestJS Roadmap for Beginners