SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
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.

Contenu connexe

Tendances

TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 

Tendances (20)

Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 
Express node js
Express node jsExpress node js
Express node js
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Express js
Express jsExpress js
Express js
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Docker swarm
Docker swarmDocker swarm
Docker swarm
 
이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정
 
Vue.js
Vue.jsVue.js
Vue.js
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 

Similaire à Solid NodeJS with TypeScript, Jest & NestJS

Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
google
 
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 Enterprise
Daniel Egan
 

Similaire à 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
 

Plus de Rafael Casuso Romate

Plus 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
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

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.