SlideShare a Scribd company logo
MasterClass
Enter NestJS
Nir Kaufman | 2019
Nir Kaufman
@nirkaufman
Principal developer & consultant @ 500Tech
Google Developer Expert in Web Technologies
https://500tech.com/
meetup.com/reactNYC
Enter NestJS
The framework we where waiting for
Kamil Myƛliwiec
@kammysliwiec 
The building blocks
Modules
Package of related classes
Modules
Application Module
Modules
Application Module
Feature Module Feature Module Feature Module
Modules
Application Module
Feature Module Feature Module Feature Module
Shared Module
Modules
Blog
Posts Users Media
Utils
Modules
Root
Feature Feature
Shared
Controllers
Handling requests & responses
Controllers
Controller
Controller
Controller
HTTP Request
Providers
Plain Injectable classes
Providers
Controller
Controller
Controller
Provider
Provider
Provider
The structure
Clear separation of concerns
Layers architecture style
Providers
Controllers
Data
Wiring the database
Let’s do it the OOP style
Object-relational mapping
EntitiesEntities
Onion architecture style
Entities
Services
Controllers
Additional API
ControllerClient
Determine whether a given request will be handled by the controller
Guards
Guard
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const token = context.switchToHttp().getRequest().headers.token;
return validateToken(token);
}
}
Auth Guard
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const token = context.switchToHttp().getRequest().headers.token;
return validateToken(token);
}
}
Auth Guard
@Injectable()
export class AuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const token = context.switchToHttp().getRequest().headers.token;
return validateToken(token);
}
}
Auth Guard
ControllerClient
 Implements the generic ExceptionFilter<T> interface
Exception ïŹlters
Guard
Filter
Filter
@Catch(ForbiddenException)
export class AuthFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message: 'Protected method'
Auth Filter
@Catch(ForbiddenException)
export class AuthFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message: 'Protected method'
Auth Filter
@Catch(ForbiddenException)
export class AuthFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message: 'Protected method'
Auth Filter
@Catch(ForbiddenException)
export class AuthFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message: 'Protected method'
Auth Filter
@Catch(ForbiddenException)
export class AuthFilter implements ExceptionFilter {
catch(exception: ForbiddenException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status = exception.getStatus();
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
message: 'Protected method'
Auth Filter
ControllerClient
Transform input into desired output. validate input data 
Pipes
Guard
Filter
Filter
Pipe
Pipe
@Injectable()
export class ValidatePipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
return value;
}
}
Basic Pipe
@Injectable()
export class ValidatePipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
return value;
}
}
Basic Pipe
@Injectable()
export class ValidatePipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
return value;
}
}
Basic Pipe
ControllerClient
bind extra logic before / after method execution
Interceptors
Guard
Filter
Filter
Pipe
Pipe
Interceptor
Interceptor
@Injectable()
export class LogInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const requestInfo = {
time: new Date().toLocaleTimeString(),
controller: context.getClass().name,
method: context.getHandler().name
};
console.log(requestInfo);
return next.handle();
}
}
Log Interceptors
@Injectable()
export class LogInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const requestInfo = {
time: new Date().toLocaleTimeString(),
controller: context.getClass().name,
method: context.getHandler().name
};
console.log(requestInfo);
return next.handle();
}
}
Log Interceptors
@Injectable()
export class LogInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const requestInfo = {
time: new Date().toLocaleTimeString(),
controller: context.getClass().name,
method: context.getHandler().name
};
console.log(requestInfo);
return next.handle();
}
}
Log Interceptors
Where to go from here
Freedom within the Frame
Choose your patterns
Freedom within the Frame
Choose your database
OïŹƒcial docs.
Community.
Build something.
Contribute.
Thank you!
@nirkaufman
nir@500tech.com

More Related Content

PDF
NestJS
PDF
Nest.js Introduction
PDF
TypeScript Introduction
PDF
Expressjs
PDF
Decomposing Applications for Scalability and Deployability (April 2012)
PPT
TypeScript Presentation
PDF
NEXT.JS
PDF
Universal React apps in Next.js
NestJS
Nest.js Introduction
TypeScript Introduction
Expressjs
Decomposing Applications for Scalability and Deployability (April 2012)
TypeScript Presentation
NEXT.JS
Universal React apps in Next.js

What's hot (20)

PDF
Clean backends with NestJs
PDF
Solid NodeJS with TypeScript, Jest & NestJS
PPTX
.Net Core
PDF
NestJS - O framework progressivo
ODP
An Introduction to Vuejs
PPTX
Express js
PPTX
Intro to React
PPTX
Angular
PPTX
Spring boot Introduction
PPTX
React hooks
PPTX
Angular Data Binding
PDF
Why Vue.js?
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
PPT
MVC ppt presentation
ODP
Routing & Navigating Pages in Angular 2
PPTX
Introduction to React JS for beginners
PDF
Angular - Chapter 4 - Data and Event Handling
PPTX
Introduction Node.js
PPTX
ASP.NET Web API
PDF
react redux.pdf
Clean backends with NestJs
Solid NodeJS with TypeScript, Jest & NestJS
.Net Core
NestJS - O framework progressivo
An Introduction to Vuejs
Express js
Intro to React
Angular
Spring boot Introduction
React hooks
Angular Data Binding
Why Vue.js?
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
MVC ppt presentation
Routing & Navigating Pages in Angular 2
Introduction to React JS for beginners
Angular - Chapter 4 - Data and Event Handling
Introduction Node.js
ASP.NET Web API
react redux.pdf
Ad

Similar to Nestjs MasterClass Slides (20)

PDF
JS Fest 2019 Node.js Antipatterns
PDF
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
PPTX
Koajs as an alternative to Express - OdessaJs'16
PPTX
Rapid API development examples for Impress Application Server / Node.js (jsfw...
PPTX
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
PDF
Node.js Course 2 of 2 - Advanced techniques
PDF
Serverless Security Guy Podjarny Liran Tal
PDF
"#Microfrontends #LowConnectivity #AsianMarket", Maxim Demidenko
 
PPTX
PDF
One tool to rule them all
PDF
Reduxing like a pro
PDF
The working architecture of NodeJs applications
PDF
Heroku pop-behind-the-sense
PDF
Rest with-spray
PDF
RESTful API in Node.pdf
PPT
How to Build Secure APIs with Node.js for Remote Applications.ppt
PDF
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
PDF
The working architecture of node js applications open tech week javascript ...
PDF
yelding-the-flow-presentation-2016-year-
PDF
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
JS Fest 2019 Node.js Antipatterns
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Koajs as an alternative to Express - OdessaJs'16
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Node.js Course 2 of 2 - Advanced techniques
Serverless Security Guy Podjarny Liran Tal
"#Microfrontends #LowConnectivity #AsianMarket", Maxim Demidenko
 
One tool to rule them all
Reduxing like a pro
The working architecture of NodeJs applications
Heroku pop-behind-the-sense
Rest with-spray
RESTful API in Node.pdf
How to Build Secure APIs with Node.js for Remote Applications.ppt
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
The working architecture of node js applications open tech week javascript ...
yelding-the-flow-presentation-2016-year-
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
Ad

More from Nir Kaufman (20)

PDF
Angular Dependency Injection
PDF
Angular Prestige: Less-known API and techniques
PDF
Angular CLI custom builders
PDF
Electronic music 101 for developers
PDF
Redux pattens - JSHeroes 2018
PDF
Angular EE - Special Workshop by Nir Kaufman
PDF
Boosting Angular runtime performance
PDF
Decorators in js
PDF
Styling recipes for Angular components
PDF
Introduction To Angular's reactive forms
PDF
Webstorm
PDF
Redux with angular 2 - workshop 2016
PDF
Angular Pipes Workshop
PDF
Data Structures in javaScript 2015
PDF
redux and angular - up and running
PDF
Angular redux
PDF
How Angular2 Can Improve Your AngularJS Apps Today!
PDF
Angular2 workshop
PDF
Solid angular
PDF
Webpack and angularjs
Angular Dependency Injection
Angular Prestige: Less-known API and techniques
Angular CLI custom builders
Electronic music 101 for developers
Redux pattens - JSHeroes 2018
Angular EE - Special Workshop by Nir Kaufman
Boosting Angular runtime performance
Decorators in js
Styling recipes for Angular components
Introduction To Angular's reactive forms
Webstorm
Redux with angular 2 - workshop 2016
Angular Pipes Workshop
Data Structures in javaScript 2015
redux and angular - up and running
Angular redux
How Angular2 Can Improve Your AngularJS Apps Today!
Angular2 workshop
Solid angular
Webpack and angularjs

Recently uploaded (20)

PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
System and Network Administration Chapter 2
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Cost to Outsource Software Development in 2025
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
iTop VPN Free 5.6.0.5262 Crack latest version 2025
System and Network Administration Chapter 2
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms II-SECS-1021-03
Introduction to Artificial Intelligence
wealthsignaloriginal-com-DS-text-... (1).pdf
Designing Intelligence for the Shop Floor.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Cost to Outsource Software Development in 2025
Softaken Excel to vCard Converter Software.pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions

Nestjs MasterClass Slides