SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
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.

Más contenido relacionado

La actualidad más candente

Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET CoreAvanade Nederland
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular ComponentsSquash Apps Pvt Ltd
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...Edureka!
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 

La actualidad más candente (20)

Angular
AngularAngular
Angular
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Arquitetura Node com NestJS
Arquitetura Node com NestJSArquitetura Node com NestJS
Arquitetura Node com NestJS
 
Node js
Node jsNode js
Node js
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Express js
Express jsExpress js
Express js
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Angular 8
Angular 8 Angular 8
Angular 8
 
NEXT.JS
NEXT.JSNEXT.JS
NEXT.JS
 
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 

Similar a 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
 
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
 
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011telestax
 

Similar a 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
 
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
 
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
CDI Telco Framework & Arquillian presentation at Mobicents Summit, Sochi 2011
 

Más de 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
 

Más de 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
 

Último

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Último (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

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.