SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Solid NodeJS
with TypeScript, Jest & Nest
“We build our computer systems
the way we build our cities:
over time, without a plan, on top of ruins.”
Ellen Ullman
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 3
Flexibility
Its multi-paradigm nature, dynamic type
system and minimal core allow great flexibility.
Ecosystem
Great system with largest amount of
packages and best evolution.
Ubiquity
Presence both in client and server, along with
mobile environment and almost everywhere.
JavaScript
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 4
Modularity
Keep simple parts short,
connected with clean interfaces.
Composition
Make those independent packages
work together to build applications
Simplicity
JavaScript succinct syntax and flexibility,
along with Node inherent asynchrony
NodeJS
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 5
Lack of common architecture
Different approaches for directory and file structure,
and even module design.
Fragile execution
Input / Output non-standard type validation,
lack of testable parts because of coupling and derived
problems from lack of standards.
Problematic growth
Hard to scale and distribute work among
different developers and teams.
Medium to Large NodeJS Applications
What’s the STRUCTURE?
How do I get ROBUSTNESS?
What if I need SCALABILITY?
Application Issues
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 6
Jest
Testing complete solution,
with zero config, fast execution,
and built-in coverage
.
Nest
Framework based on
combination of OOP/FP/FRP,
DI and building blocks.
TypeScript
JavaScript that scales
through latest features
and solid type static analysis.
Weapons
Solutions for Robustness, Scalability and Structure
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 7
Why TypeScript?
๏ Types are optional (ideal for
validation)
๏ Type inference for static analysis
and tooling
๏ Interfaces for solid components
๏ Advanced ESNext features in
Development
๏ Compiles to clean, efficient,
compatible JavaScript
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 8
Why Jest?
๏ Complete Testing Solution
๏ Minimum configuration
๏ Fast parallelization of tests across
workers
๏ Selective execution when
watching
๏ Built-in code coverage report with
Istanbul
๏ Snapshot Testing included
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 9
Application Architecture
Nest provides building blocks around a execution
context to give a common architecture, that includes
controllers, modules, pipes, guards, etc.
Middleware structure
Built on top of Express, it leverages the
middleware capabilities of this framework..
Dependency Injection
All elements in Nest are defined around
DI principles, so services, modules, controllers,
all can be injected and thus easily testable.
Platform-agnostic
Reusable pieces that can be used in
different contexts, like GraphQL, Microservices
or Websockets..
Nest
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 10
• Starter with TypeScript
• V5 is coming (beta) with

dedicated CLI
• Basic structure with

conventions
• Main entry point
First steps
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 11
๏ Each Part of the Application
๏ Can be only one: Root Module
๏ Domain Bounded Contexts
๏ Module Decorator describes:
➡ Imports: Other modules
➡ Controllers: Created by the module
➡ Components/Providers: Instantiated and shared

across the module
๏ Modules are Singletons so they are shared.
Modules
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 12
Every Module can Import

and Export other Modules
Admin ModuleUsers Module
Application Module
Stats ModuleBilling ModuleChat Module Game Module
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 13
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 14
Controllers
๏ Request Handlers and Response Generators
๏ Must be declared associated to a Module
๏ Metadata in decorator defines prefix like @Controller(‘users’)
๏ Two approaches to handle Response:
➡ Nest: Returns Array or Object automatically as JSON
➡ Express: Injected through @Res() decorator.

Allow express-like response manipulation.
๏ POST handler can use Data Transfer Object (DTO)
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 15
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 16
Components / Providers
๏ Services, Factories, Helpers, etc
๏ They can be Injected into Controllers or

other Components / Providers through constructor
๏ Any complex task performed into Controllers
๏ Pattern of reusability and modularity
๏ Plain TypeScript Classes
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 17
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 18
Middlewares
๏ Function called before the Route Handler
๏ Have access to Request, Response and Next handler
๏ Same capabilities as express middlewares:
➡ Execute code before continuing: And then call next()
➡ Make changes to Request & Response
➡ End Request-Response cycle
๏ Can be defined:
➡ For specific paths
➡ For specific Controllers
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 19
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 20
Exceptions
๏ Global Exception Filter for Unhandled Errors: 500 Server Error
๏ Built-in HttpException that when thrown by handler

it transforms to proper JSON response
๏ A good practice is to create your own Exception Hierarchy with

exceptions inherited by the HttpException class
๏ Nest offers several built-in HTTP Exceptions like:

BadRequestException, UnauthorizedException, 

NotFoundException, ForbiddenException, etc
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 21
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 22
Validation
๏ Validation is done through a specific Pipe
๏ Pipes are classes that implement the PipeTransform Interface
๏ A Pipe transforms the input data to desired output before Route Handler
๏ ValidationPipe is a built-in Pipe
๏ Data Transfer Object (DTO) is required to receive the @Body()
๏ Class-Validator library allow decorator-based validation on DTO definition
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 23
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 24
Testing with Jest
๏ Every building block in Nest (Components, Controllers, etc) are simple decorated classes
๏ As every dependency is injected through constructor, they are easy to mock
๏ Recommendation is to keep your test files near the implementation
๏ Recommendation is always isolated tests
๏ Test class is a utility with createTestingModule() that takes module metadata and creates

a TestingModule instance.
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 25
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 26
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 27
Database Access
๏ Nest uses by default the standard TypeORM for Object Relational Model
๏ Mongoose use the built-in @nestjs/mongoose package
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 28
Example
NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 29
GraphQL
Module for GraphQL
server with Apollo
Websockets
Decorators to include
WS transport
Microservices
NestJS microservices are
TCP interconnected services
Platform-agnosticism allow building apps
with several transport layers and contexts.
Always bet on JavaScript.
Let’s make JS applications more solid.
Let’s do it on scale.
“It's never on how difficult
is to write bad code,
it's on how easy is
to write great code.”
@yonatam
Thank you
No real requests were damaged during this talk.

Weitere ähnliche Inhalte

Was ist angesagt?

Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaBabacar NIANG
 
Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction Kanika Gera
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slidesmattysmith
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureFlavius Stef
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 

Was ist angesagt? (20)

Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction Node.Js: Basics Concepts and Introduction
Node.Js: Basics Concepts and Introduction
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Dependency injection ppt
Dependency injection pptDependency injection ppt
Dependency injection ppt
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slides
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Node.js
Node.jsNode.js
Node.js
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 

Ähnlich wie Solid NodeJS with TypeScript, Jest & NestJS

How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinSigma Software
 
Node.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceNode.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceTimur Shemsedinov
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
Elasticsearch Operations on K8s - Key Specificities
Elasticsearch Operations on K8s - Key SpecificitiesElasticsearch Operations on K8s - Key Specificities
Elasticsearch Operations on K8s - Key SpecificitiesTyler Nguyen
 
ASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in TechnologyASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in TechnologyMałgorzata Borzęcka
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTobias Trelle
 
IBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassIBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassPaul Withers
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platformSreenivas Kappala
 
DevOps, Continuous Integration and Deployment on AWS
DevOps, Continuous Integration and Deployment on AWSDevOps, Continuous Integration and Deployment on AWS
DevOps, Continuous Integration and Deployment on AWSAmazon Web Services
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh! Chalermpon Areepong
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...mfrancis
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
MongoDB.pptx
MongoDB.pptxMongoDB.pptx
MongoDB.pptxSigit52
 
Frankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiFrankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiToni Epple
 

Ähnlich wie Solid NodeJS with TypeScript, Jest & NestJS (20)

How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
 
Node.js for enterprise - JS Conference
Node.js for enterprise - JS ConferenceNode.js for enterprise - JS Conference
Node.js for enterprise - JS Conference
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Elasticsearch Operations on K8s - Key Specificities
Elasticsearch Operations on K8s - Key SpecificitiesElasticsearch Operations on K8s - Key Specificities
Elasticsearch Operations on K8s - Key Specificities
 
ASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in TechnologyASP.NET MVC Workshop for Women in Technology
ASP.NET MVC Workshop for Women in Technology
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
 
IBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClassIBM Think Session 8598 Domino and JavaScript Development MasterClass
IBM Think Session 8598 Domino and JavaScript Development MasterClass
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
Node.js on Azure
Node.js on AzureNode.js on Azure
Node.js on Azure
 
DevOps, Continuous Integration and Deployment on AWS
DevOps, Continuous Integration and Deployment on AWSDevOps, Continuous Integration and Deployment on AWS
DevOps, Continuous Integration and Deployment on AWS
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Just entity framework
Just entity frameworkJust entity framework
Just entity framework
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
MongoDB.pptx
MongoDB.pptxMongoDB.pptx
MongoDB.pptx
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Frankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiFrankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGi
 

Mehr von Rafael Casuso Romate

Rise and Fall of the Frontend Developer
Rise and Fall of the Frontend DeveloperRise and Fall of the Frontend Developer
Rise and Fall of the Frontend DeveloperRafael Casuso Romate
 
Nuxt Avanzado (de Scaffolding a MVP)
Nuxt Avanzado (de Scaffolding a MVP)Nuxt Avanzado (de Scaffolding a MVP)
Nuxt Avanzado (de Scaffolding a MVP)Rafael Casuso Romate
 
Introduction to Weex: Mobile Apps with VueJS
Introduction to Weex: Mobile Apps with VueJSIntroduction to Weex: Mobile Apps with VueJS
Introduction to Weex: Mobile Apps with VueJSRafael Casuso Romate
 
Component-Oriented Progressive Web Applications with VueJS
Component-Oriented Progressive Web Applications with VueJSComponent-Oriented Progressive Web Applications with VueJS
Component-Oriented Progressive Web Applications with VueJSRafael Casuso Romate
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8Rafael Casuso Romate
 
Microservices Architecture For Conversational Intelligence Platform
Microservices Architecture For Conversational Intelligence PlatformMicroservices Architecture For Conversational Intelligence Platform
Microservices Architecture For Conversational Intelligence PlatformRafael Casuso Romate
 

Mehr von Rafael Casuso Romate (12)

Rise and Fall of the Frontend Developer
Rise and Fall of the Frontend DeveloperRise and Fall of the Frontend Developer
Rise and Fall of the Frontend Developer
 
Nuxt Avanzado (de Scaffolding a MVP)
Nuxt Avanzado (de Scaffolding a MVP)Nuxt Avanzado (de Scaffolding a MVP)
Nuxt Avanzado (de Scaffolding a MVP)
 
The Core of Agile
The Core of AgileThe Core of Agile
The Core of Agile
 
The Voice Interface Revolution
The Voice Interface RevolutionThe Voice Interface Revolution
The Voice Interface Revolution
 
Introduction to Weex: Mobile Apps with VueJS
Introduction to Weex: Mobile Apps with VueJSIntroduction to Weex: Mobile Apps with VueJS
Introduction to Weex: Mobile Apps with VueJS
 
Component-Oriented Progressive Web Applications with VueJS
Component-Oriented Progressive Web Applications with VueJSComponent-Oriented Progressive Web Applications with VueJS
Component-Oriented Progressive Web Applications with VueJS
 
Intro to VueJS Workshop
Intro to VueJS WorkshopIntro to VueJS Workshop
Intro to VueJS Workshop
 
Google Assistant Revolution
Google Assistant RevolutionGoogle Assistant Revolution
Google Assistant Revolution
 
VueJS in Action
VueJS in ActionVueJS in Action
VueJS in Action
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
VueJS: The Simple Revolution
VueJS: The Simple RevolutionVueJS: The Simple Revolution
VueJS: The Simple Revolution
 
Microservices Architecture For Conversational Intelligence Platform
Microservices Architecture For Conversational Intelligence PlatformMicroservices Architecture For Conversational Intelligence Platform
Microservices Architecture For Conversational Intelligence Platform
 

Kürzlich hochgeladen

online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptkinjal48
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 

Kürzlich hochgeladen (20)

online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.ppt
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 

Solid NodeJS with TypeScript, Jest & NestJS

  • 2. “We build our computer systems the way we build our cities: over time, without a plan, on top of ruins.” Ellen Ullman
  • 3. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 3 Flexibility Its multi-paradigm nature, dynamic type system and minimal core allow great flexibility. Ecosystem Great system with largest amount of packages and best evolution. Ubiquity Presence both in client and server, along with mobile environment and almost everywhere. JavaScript
  • 4. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 4 Modularity Keep simple parts short, connected with clean interfaces. Composition Make those independent packages work together to build applications Simplicity JavaScript succinct syntax and flexibility, along with Node inherent asynchrony NodeJS
  • 5. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 5 Lack of common architecture Different approaches for directory and file structure, and even module design. Fragile execution Input / Output non-standard type validation, lack of testable parts because of coupling and derived problems from lack of standards. Problematic growth Hard to scale and distribute work among different developers and teams. Medium to Large NodeJS Applications What’s the STRUCTURE? How do I get ROBUSTNESS? What if I need SCALABILITY? Application Issues
  • 6. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 6 Jest Testing complete solution, with zero config, fast execution, and built-in coverage . Nest Framework based on combination of OOP/FP/FRP, DI and building blocks. TypeScript JavaScript that scales through latest features and solid type static analysis. Weapons Solutions for Robustness, Scalability and Structure
  • 7. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 7 Why TypeScript? ๏ Types are optional (ideal for validation) ๏ Type inference for static analysis and tooling ๏ Interfaces for solid components ๏ Advanced ESNext features in Development ๏ Compiles to clean, efficient, compatible JavaScript
  • 8. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 8 Why Jest? ๏ Complete Testing Solution ๏ Minimum configuration ๏ Fast parallelization of tests across workers ๏ Selective execution when watching ๏ Built-in code coverage report with Istanbul ๏ Snapshot Testing included
  • 9. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 9 Application Architecture Nest provides building blocks around a execution context to give a common architecture, that includes controllers, modules, pipes, guards, etc. Middleware structure Built on top of Express, it leverages the middleware capabilities of this framework.. Dependency Injection All elements in Nest are defined around DI principles, so services, modules, controllers, all can be injected and thus easily testable. Platform-agnostic Reusable pieces that can be used in different contexts, like GraphQL, Microservices or Websockets.. Nest
  • 10. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 10 • Starter with TypeScript • V5 is coming (beta) with
 dedicated CLI • Basic structure with
 conventions • Main entry point First steps
  • 11. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 11 ๏ Each Part of the Application ๏ Can be only one: Root Module ๏ Domain Bounded Contexts ๏ Module Decorator describes: ➡ Imports: Other modules ➡ Controllers: Created by the module ➡ Components/Providers: Instantiated and shared
 across the module ๏ Modules are Singletons so they are shared. Modules
  • 12. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 12 Every Module can Import
 and Export other Modules Admin ModuleUsers Module Application Module Stats ModuleBilling ModuleChat Module Game Module
  • 13. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 13 Example
  • 14. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 14 Controllers ๏ Request Handlers and Response Generators ๏ Must be declared associated to a Module ๏ Metadata in decorator defines prefix like @Controller(‘users’) ๏ Two approaches to handle Response: ➡ Nest: Returns Array or Object automatically as JSON ➡ Express: Injected through @Res() decorator.
 Allow express-like response manipulation. ๏ POST handler can use Data Transfer Object (DTO)
  • 15. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 15 Example
  • 16. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 16 Components / Providers ๏ Services, Factories, Helpers, etc ๏ They can be Injected into Controllers or
 other Components / Providers through constructor ๏ Any complex task performed into Controllers ๏ Pattern of reusability and modularity ๏ Plain TypeScript Classes
  • 17. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 17 Example
  • 18. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 18 Middlewares ๏ Function called before the Route Handler ๏ Have access to Request, Response and Next handler ๏ Same capabilities as express middlewares: ➡ Execute code before continuing: And then call next() ➡ Make changes to Request & Response ➡ End Request-Response cycle ๏ Can be defined: ➡ For specific paths ➡ For specific Controllers
  • 19. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 19 Example
  • 20. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 20 Exceptions ๏ Global Exception Filter for Unhandled Errors: 500 Server Error ๏ Built-in HttpException that when thrown by handler
 it transforms to proper JSON response ๏ A good practice is to create your own Exception Hierarchy with
 exceptions inherited by the HttpException class ๏ Nest offers several built-in HTTP Exceptions like:
 BadRequestException, UnauthorizedException, 
 NotFoundException, ForbiddenException, etc
  • 21. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 21 Example
  • 22. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 22 Validation ๏ Validation is done through a specific Pipe ๏ Pipes are classes that implement the PipeTransform Interface ๏ A Pipe transforms the input data to desired output before Route Handler ๏ ValidationPipe is a built-in Pipe ๏ Data Transfer Object (DTO) is required to receive the @Body() ๏ Class-Validator library allow decorator-based validation on DTO definition
  • 23. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 23 Example
  • 24. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 24 Testing with Jest ๏ Every building block in Nest (Components, Controllers, etc) are simple decorated classes ๏ As every dependency is injected through constructor, they are easy to mock ๏ Recommendation is to keep your test files near the implementation ๏ Recommendation is always isolated tests ๏ Test class is a utility with createTestingModule() that takes module metadata and creates
 a TestingModule instance.
  • 25. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 25 Example
  • 26. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 26 Example
  • 27. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 27 Database Access ๏ Nest uses by default the standard TypeORM for Object Relational Model ๏ Mongoose use the built-in @nestjs/mongoose package
  • 28. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 28 Example
  • 29. NODEJS SÓLIDO CON TYPESCRIPT, JEST Y NESTJS. 29 GraphQL Module for GraphQL server with Apollo Websockets Decorators to include WS transport Microservices NestJS microservices are TCP interconnected services Platform-agnosticism allow building apps with several transport layers and contexts.
  • 30. Always bet on JavaScript. Let’s make JS applications more solid. Let’s do it on scale. “It's never on how difficult is to write bad code, it's on how easy is to write great code.” @yonatam
  • 31. Thank you No real requests were damaged during this talk.