SlideShare a Scribd company logo
1 of 34
Download to read offline
Real Time Ninja
Hands On MEAN
Giovanni Lela
CTO @ LinkMe
Cofounder @ MeanMilan
Matteo Scandolo
MEAN Dev @ LinkMe
Cofounder @ MeanMilan
What's next
When / why did it start
Extremely boring theory
What to do aka common use cases
Differences from client side javascript
App example: a RESTful ninja managament tools
with real time notifications
Pre - nodejs
1994 - Netscape enterprise server
1996 - Microsoft Internet Information service
Enter node js
In 200* Ryan Dahl saw a polling progress bar
He wanted a super easy way to implement sites with push
capabilities
In 2009 node.js was born
Joyent takes control
Hype and dissatisfaction
In the following years node.js gains substantial traction
In 2014, community dissatisfaciton lead to io.js
What now?
Why should I care?
It can can handle a lot of concurrent I/O operations
Because of non blocking I/O and javascript's own nature
Blocking I/O analogy
Each cashier (thread) server one
customer at a time
Blocking I/O analogy (2)
The cashier waits for your food
to be cooked before doing
anything else (he’s blocked)
The cashier is not able to help the
next person until you got your
food and went your way
Blocking I/O analogy (3)
The more customers you want to serve at once the more cashier
lines you need
Cashier lines -> thread
Multi-threaded parellel execution
Non-blocking I/O analogy
As soon as you place your order, it’s sent off for someone to fulfill
while the cashier is still taking your payment.
When you are done paying, you have to step aside because the
cashier is already looking to service the next customer.
When your food is set, the cashier – or someone – will signal you by
calling out your name, (callback)
Non-blocking I/O (2)
You use your web browser to make a request for “/about.html” on
a Node.js web server.
The Node server accepts your request and calls a function to
retrieve that file from disk.
While the Node server is waiting for the file to be retrieved, it
services the next web request.
When the file is retrieved, there is a callback function that is
inserted in the Node servers queue.
The Node server executes that function which in this case would
render the “/about.html” page and send it back to your web browser.
So:
Every I/O operation is non blocking
Your code is single threaded
Everything runs in parallel except your code
"Everything runs in parellel
except your code"
http://slides.com/adamterlson/promises#/
Event loop
A JavaScript runtime contains an event queue, which is a list of
tasks to be processed
Each message event is bound to a callback function
The said runtime loops on the queue, executing all the event callbacks
Event loop
while(queue.waitForMessage()){
  queue.processNextMessage();
}
Event loop as a language
In javascript the event loop is not a library it's a language construct
Event loop in ruby /
eventmachine
require 'eventmachine'
module Echo
 def post_init
  puts "Connection Connected Yo"
 end
 def receive_data
  send_data "#{data}"
  close_connection if data =~ /quit/if
 end
end
EventMachine.run {
  EventMachine.start_server "127.0.0.1", 8081, Echo
}
Event loop in node.js (and es6!)
require('net')
.createServer((socket)=>{
 console.log('Connection connected');
 socket.on('data', req => socket.write(req.toString()))
})
.listen(8000);
What not to do
everything that is CPU intensive
image/video processing
heavyweight number crunching
compressing files
everything involving complex algorithms
Event loops are highly specialized and not general purpose
"Everything runs in parellel
except your code"
http://slides.com/adamterlson/promises#/
What to do - APIs
REST/JSON Api
Plays well with non relational db
LOTS of stable and mature frameworks: hapi, restify, express,
loopback
What to do - Fullstack apps
Good ol’ MEAN stack
Isomorphic applications:
Shared models
Shared rendering
What to do - Real time web
apps
It was born for this
Lots of stable mature frameworks (again) - primus, socket I/O ecc
It ca ben integrated into an existing web stack
http://webandphp.com/IntegratingNode.jswithPHP
Other interesting fields of
application
Desktop Apps
Microservices
Embedded
Differences from the front end
No DOM api
No browser APIs globals: window, document
No browser inconsistencies: you just get the V8
Excellent parts of javascripts
Array.prototype.forEach(), Array.prototype.map(), Object.keys() [...]
http://kangax.github.io/compat-table/es5/
http://kangax.github.io/compat-table/es6/
Different globals
process
__filename
__dirname
CommonJS globals
global
Common js globals
//hello.js
exports.getGreetings = function() {
  return 'Hello World';
};
//example.js
var hello = require('./hello.js');
var greetings = hello.getGreetings();
Built in libraries
fs
net
stream
Many, many callbacks
can lead to really confused code
many tools to manage this
some FP is necessary
And now?
Let's Code!
What are we going to do?
Setup the environment
Connect to MongoDB
Define "Models"
Define Routes and Middlewares
Implement a basic CRUD
A basic FrontEnd
And finally... Realtime!
Try it on
ninja.link-me.it
Thanks for listening
Keep in touch
Giovanni Lela: @lambrojos
Matteo Scandolo: @_teone
LinkMe: @LinkMeSRL -
@MM_MeanMilan -
www.link-me.it
github.com/MeanMilan

More Related Content

What's hot

JQuery
JQueryJQuery
JQueryJ B
 
Web workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIWeb workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIpcnmtutorials
 
Unobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQueryUnobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQuerySimon Willison
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websitesoazabir
 

What's hot (9)

Hack Rio/OS
Hack Rio/OSHack Rio/OS
Hack Rio/OS
 
JQuery
JQueryJQuery
JQuery
 
NodeJS
NodeJSNodeJS
NodeJS
 
Web workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIWeb workers | JavaScript | HTML API
Web workers | JavaScript | HTML API
 
Unobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQueryUnobtrusive JavaScript with jQuery
Unobtrusive JavaScript with jQuery
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
Node js Global Packages
Node js Global PackagesNode js Global Packages
Node js Global Packages
 
Web worker
Web workerWeb worker
Web worker
 

Viewers also liked

Viewers also liked (15)

Memoria
MemoriaMemoria
Memoria
 
Audience profile
Audience profile Audience profile
Audience profile
 
Practica8 lqr
Practica8 lqrPractica8 lqr
Practica8 lqr
 
Introduction
IntroductionIntroduction
Introduction
 
AnthonyGonzales
AnthonyGonzalesAnthonyGonzales
AnthonyGonzales
 
Audio Video Conference
Audio Video ConferenceAudio Video Conference
Audio Video Conference
 
Page 18 rosario ramirez
Page 18 rosario ramirezPage 18 rosario ramirez
Page 18 rosario ramirez
 
алкены химия
алкены химияалкены химия
алкены химия
 
T shirt 3
T shirt 3T shirt 3
T shirt 3
 
Stylers Panel Omg! its 2017
Stylers Panel Omg! its 2017  Stylers Panel Omg! its 2017
Stylers Panel Omg! its 2017
 
Muhammad asal final cv
Muhammad asal final cvMuhammad asal final cv
Muhammad asal final cv
 
الدرس الثالث
الدرس الثالثالدرس الثالث
الدرس الثالث
 
Analyse takrouna
Analyse takrounaAnalyse takrouna
Analyse takrouna
 
Mapa conceptual sobre la gerencia
Mapa conceptual sobre la gerenciaMapa conceptual sobre la gerencia
Mapa conceptual sobre la gerencia
 
20 Best Inspiring Quotes on Leadership
20 Best Inspiring Quotes on Leadership20 Best Inspiring Quotes on Leadership
20 Best Inspiring Quotes on Leadership
 

Similar to Real timeninja - Codemotion 2015 Roma

"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M SnellFwdays
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to nodegirish82
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.jsjubilem
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right toolsChristian Heilmann
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.jsvaluebound
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009pauldix
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 

Similar to Real timeninja - Codemotion 2015 Roma (20)

Proposal
ProposalProposal
Proposal
 
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
Ob Essay
Ob EssayOb Essay
Ob Essay
 
Real time web
Real time webReal time web
Real time web
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node
NodeNode
Node
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.js
 
Node js
Node jsNode js
Node js
 
Building with JavaScript - write less by using the right tools
Building with JavaScript -  write less by using the right toolsBuilding with JavaScript -  write less by using the right tools
Building with JavaScript - write less by using the right tools
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Nodejs
NodejsNodejs
Nodejs
 

Recently uploaded

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 MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Real timeninja - Codemotion 2015 Roma