SlideShare une entreprise Scribd logo
1  sur  56
Node.js from zero to hero
Nicola Del Gobbo – Mauro Doganieri
WHAT IS Node.js?
A JavaScript Runtime Asynchronous I/O based on event loops Ecosystem of packages
~100k LOC of JS and C++
Node glue
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient
Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world
WHAT CAN I DO WITH Node.js?
EVERYTHING
Great thank you to Node.js Community and Working Groups
WHAT CAN I DO WITH Node.js?
CLI APPLICATION DESKTOP APPLICATIONDISRTRUBUTED SYSTEM REAL TIME SYSTEM
ARCHITECTURE
CONCURRENCY MODEL?
ASINCHRONOUS I/O
SINGLE THREADED
SINCHRONOUS MODEL?
Blocking the whole process or you need to have multiple execution stacks
ASINCHRONOUS MODEL?
The main process is never blocked. No strategy is required to handle competing requests
EVENT LOOP
ASINCHRONOUS IN LOW LEVEL
ASINCHRONOUS IN LOW LEVEL
JAVASCRIPT
“The world's most misunderstood programming language“
Douglas Crockford
STRICT MODE
ECMAScript 5's strict mode is a way to opt in to a restricted variant of
JavaScript.
Strict mode isn't just a subset: it intentionally has different semantics
from normal code.
STRICT MODE - HOW TO
Scripts Functions
SCOPE
Where your variables are actually created depends on
• how you declare them, using var, let or const
• if you are in strict mode or not
• if you are explicitly declaring them or not
SCOPE var DECLARATION AND HOISTING
• Declared variables are constrained in the execution context in which they are declared
• Declared variables are created before any code is executed
SCOPE UNDECLARATION VARIABLES
• Undeclared variables are always global
• Undeclared variables do not exist until the code assigning to them is executed
SCOPE - DECLARATION USING let
Variables declared by let have as their scope the block in which they are defined, as well as in any
contained sub-blocks
SCOPE - NO REDECLARATION USING let
Redeclaring the same variable within the same function or block scope raises a SyntaxError
SCOPE - REDECLARATION USING var vs let
FUNCTIONS
In JavaScript, functions are first-class objects, because they
can have properties and methods just like any other object
FUNCTIONS - HOW TO REPRESENT AN OBJECT
FUNCTIONS - HOW TO REPRESENT AN OBJECT
FUNCTIONS - THE class KEYWORD
FUNCTIONS - ARROW FUNCTIONS
An arrow function expression has a shorter syntax than a function expression and does
not have its own this, arguments, super...
These function expressions are best suited for non-method functions, and they cannot
be used as constructors
FUNCTIONS - ARROW FUNCTIONS
FUNCTIONS - CLOSURES
A closure is the combination of a function and the lexical environment within which that
function was declared
FUNCTIONS - CLOSURES
THE LONG HARD ROAD OUT OF CALLBACK HELL
From callbacks to promises and async/await, trying to understand the
event loop
THE EVENT LOOP
MODULARITY
CommonJS Module
ES6 Module from v8.5.0
“Se non hai provato Node.js non sai cos’è la
modularità e il riuso”
Matteo Collina
MODULARITY
MODULARITY
EVENT EMITTER
EventEmitter is a very important class in Node.js. It provides a channel for events to be
dispatched and listeners notified. Many objects you will encounter in Node.js inherit
from EventEmitter
EVENT EMITTER
NODEJS
HTTP
SERVER
WEB APPLICATION
CLIENT
Browser
Mobile
App
REQUEST
HANDLER
http://your-web-application
Request
Response
~40k req/s
Hard to maintain
FRAMEWORKS
EXPRESS
EXPRESS
• Minimalist
• Unopinionated
• Fast (about 21k req/sec)
• Simple (do one thing well philosophy from Unix world)
• Wrapper of http core module
EXPRESS MILESTONES
• Middleware
• Error handler
• Router
• Views / template engine
MIDDLEWARES
It’s always a question to manipulate the Request
and Response object
MIDDLEWARES
MIDDLEWARES
MIDDLEWARES
MIDDLEWARES
http://expressjs.com/en/resources/middleware.html
ERROR HANDLER
ROUTING
Routing refers to determining how an application responds
to a client request to a particular endpoint, which is a URI
(or path) and a specific HTTP request method
VALIDATE YOUR INPUT
The fastest JSON Schema validator for
Node.js and browser
Ajv
npm install ajv
https://github.com/epoberezkin/ajv
VIEWS / TEMPLATE ENGINE
Pug - Mustache - Dust - Nunjuks - EJS
SECURITY
Helmet helps you secure your Express apps
by setting various HTTP headers
npm install helmet
https://github.com/helmetjs/helmet
LOGGER
Log everything that happens in your application
npm install winston
https://github.com/winstonjs/winston
Pay attention there is a cost for logging
DOMANDE?
GRAZIE
https://github.com/NickNaso/nodejs-tsw-2017

Contenu connexe

Tendances

Automating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and PerlAutomating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and Perl
nohuhu
 
Perf onjs final
Perf onjs finalPerf onjs final
Perf onjs final
qi yang
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
Tengwen Wang
 

Tendances (20)

Automating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and PerlAutomating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and Perl
 
1.3 tools and-repl
1.3 tools and-repl1.3 tools and-repl
1.3 tools and-repl
 
Gdg dev fest 2107 to kotlin, with love
Gdg dev fest 2107   to kotlin, with loveGdg dev fest 2107   to kotlin, with love
Gdg dev fest 2107 to kotlin, with love
 
Introduction to Functional Reactive Programming
Introduction to Functional Reactive ProgrammingIntroduction to Functional Reactive Programming
Introduction to Functional Reactive Programming
 
War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)War of Native Speed on Web (SITCON2016)
War of Native Speed on Web (SITCON2016)
 
MVVM on iOS
MVVM on iOSMVVM on iOS
MVVM on iOS
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
Dive into Akka Actors
Dive into Akka ActorsDive into Akka Actors
Dive into Akka Actors
 
Perf onjs final
Perf onjs finalPerf onjs final
Perf onjs final
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
 
The Architect Way
The Architect WayThe Architect Way
The Architect Way
 
ColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your MonolithColdBox Hierarchical MVC - Transform Your Monolith
ColdBox Hierarchical MVC - Transform Your Monolith
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017Solving cross cutting concerns in PHP - PHPSerbia-2017
Solving cross cutting concerns in PHP - PHPSerbia-2017
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
Java 8 parallel stream
Java 8 parallel streamJava 8 parallel stream
Java 8 parallel stream
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshop
 
Let it crash! The Erlang Approach to Building Reliable Services
Let it crash! The Erlang Approach to Building Reliable ServicesLet it crash! The Erlang Approach to Building Reliable Services
Let it crash! The Erlang Approach to Building Reliable Services
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
 

Similaire à Nodejs from zero to hero

Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 

Similaire à Nodejs from zero to hero (20)

An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptx
 
slides-students-C03.pdf
slides-students-C03.pdfslides-students-C03.pdf
slides-students-C03.pdf
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Take a Look at Akka+Java (English version)
Take a Look at Akka+Java (English version)Take a Look at Akka+Java (English version)
Take a Look at Akka+Java (English version)
 
Oracle application container cloud back end integration using node final
Oracle application container cloud back end integration using node finalOracle application container cloud back end integration using node final
Oracle application container cloud back end integration using node final
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Reactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xReactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.x
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
 
Akka (1)
Akka (1)Akka (1)
Akka (1)
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
 
Introduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptIntroduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with Clojurescript
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Get Started with JavaScript Frameworks
Get Started with JavaScript FrameworksGet Started with JavaScript Frameworks
Get Started with JavaScript Frameworks
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-final
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 

Plus de Nicola Del Gobbo

Plus de Nicola Del Gobbo (9)

Next Generation N-API
Next Generation N-APINext Generation N-API
Next Generation N-API
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
Nodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to heroNodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to hero
 
Expressjs from-zero-to-hero
Expressjs from-zero-to-heroExpressjs from-zero-to-hero
Expressjs from-zero-to-hero
 
Introduzione a Node.js
Introduzione a Node.jsIntroduzione a Node.js
Introduzione a Node.js
 
Node js with steroids
Node js with steroidsNode js with steroids
Node js with steroids
 
Lexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologieLexgenda Documenti d’archivio e nuove tecnologie
Lexgenda Documenti d’archivio e nuove tecnologie
 
Automatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profilingAutomatic generation of inspection checklist by user profiling
Automatic generation of inspection checklist by user profiling
 
Lexgenda
LexgendaLexgenda
Lexgenda
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Nodejs from zero to hero