SlideShare a Scribd company logo
1 of 28
Download to read offline
www.edureka.co/mastering-node-js
View Mastering Node.js course details at www.edureka.co/mastering-node-js
Communication in Node.js
Slide 2Slide 2Slide 2Slide 2 www.edureka.co/mastering-node-js
 Introduction of Node.js
 Use Cases of Node.js
 Network Communication in Node.js
 Two Way Communication in Node.js
What will you learn today?
Slide 3 www.edureka.co/mastering-node-jsSlide 3
Traditional Multithreaded Model
Slide 4 www.edureka.co/mastering-node-jsSlide 4
Problem with Multithreaded Model
Thread 1 Thread 3
Shared
Resource
wants to
update
wants to
update
Thread 2
wants to
update
 In a multi-threaded HTTP server, for each and every request that the server receives, it creates a separate
thread which handles that request
 If a request acquires a lock in the shared resource and it is ‘exclusive’, it will affect result of other requests
Slide 5 www.edureka.co/mastering-node-jsSlide 5
Single Threading
Event
Loop
Event
Queue
Thread Pool
file system
network
process
other
One Thread at a Time
 On the other hand, framework like Node.js is event driven, handling all requests asynchronously from single
thread
 Almost no function in Node directly performs I/O, so the process never blocks
Slide 6 www.edureka.co/mastering-node-jsSlide 6
What is Node.js ?
 Node.js is a server-side runtime environment for networking applications. It is single threaded.
 Node.js applications are written in JavaScript, and its open source based on Google’s V8 JavaScript Engine
 It is cross platform and can run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD,
NonStop and IBM
Slide 7 www.edureka.co/mastering-node-jsSlide 7
Node.js Detailed Architecture
Client 1
Request
1
Request
1
Blocking
IO
Request
?
Client 2
Client n
Request
2
Request
n
Request
2
Event Loop
Single
Threaded
Non Blocking I/O
Tasks Processed
here
Request 1
Request 2
Request n
Response 1
Response 2
Response n
No
No
Non-Blocking IO
Non-Blocking IO
Request
1
Request
2
Send
Responses
Pick up requests from queue
Event Queue
Slide 8 www.edureka.co/mastering-node-jsSlide 8
Node.js Detailed Architecture
Client 1
Request
1
T-1
Request
1
Database
Filesystem
Blocking
IO
Request
?
Client 2
Client n
Request
2
Request
n
T-2 T-m
Thread
T-1
Request
n
Request
2
Request
n
Event Loop
Single
Threaded
Non Blocking I/O
Tasks Processed
here
Request 1
Request 2
Request n
Response 1
Response 2
Response n
No
No
Yes
handle by
Non-Blocking IO
Non-Blocking IO
Request
1
Request
2
Send
Responses
Pick up requests from queue
Node.js Platform internal Thread PoolEvent Queue
Send Response to Request n
Pick up one
Thread from
pool
Blocking IO
Slide 9 www.edureka.co/mastering-node-jsSlide 9
Use-Cases of Node.js (Contd.)
 Previously LinkedIn Mobile was powered by Ruby on Rails
 It was a synchronous app in which clients used to make several calls
for a single page, consequently the system was bursting because of
the load
Slide 10 www.edureka.co/mastering-node-jsSlide 10
Use-Cases of Node.js (Contd.)
 Previously LinkedIn Mobile was powered by Ruby on Rails
 It was a synchronous app in which clients used to make several calls
for a single page, consequently the system was bursting because of
the load
Advantage of using Node.js
 The LinkedIN moved to Node.js which enabled them to move to a
model where the client makes a single request for a page
 It led to reduction in the number of machines used to host their
services greater than 10:1
Slide 11 www.edureka.co/mastering-node-jsSlide 11
Use-Cases of Node.js (Contd.)
 Ebay was making real time applications with huge number of eBay-
specific services
 As eBay was having java infrastructure, it consumed many more
resources than expected, raising questions about scalability for
production
Slide 12 www.edureka.co/mastering-node-jsSlide 12
 Ebay was making real time applications with huge number of eBay-
specific services
 As eBay was having java infrastructure, it consumed many more
resources than expected, raising questions about scalability for
production
 Node.js solved this issue as it is scalable because its single
threaded so less overheads and that is why it utilizes the resources
in the right manner, so no extra consumption of resources
Use-Cases of Node.js (Contd.)
Advantage of using Node.js
Slide 13 www.edureka.co/mastering-node-jsSlide 13
Uber’s Story
 Uber is a transportation company which allows users to get a taxi, private car or rideshare from their smartphones
Uber uses NodeJS to implement their cab dispatch operation
Slide 14 www.edureka.co/mastering-node-jsSlide 14
Uber - Old Architecture
PHP
PHP
PHP
PHP
Slide 15 www.edureka.co/mastering-node-jsSlide 15
Uber - Multiple Dispatch Problem
 Since PHP is a multithreaded language , each user’s request is handled in a separate thread
 Once one car is dispatched for a user, in between the same car get dispatched to another user
 Reason was car dispatch operation was executed from multiple threads
Slide 16 www.edureka.co/mastering-node-jsSlide 16
Uber - New Architecture
iPhone
Android
NodeJS
Dispatch
(NodeJS)
Dispatch State
(MongoDB)
Real-time Logic
Business Logic
Persistent Store
(MySQL)
Python
Slide 17 www.edureka.co/mastering-node-jsSlide 17
Job Trends
From the graph below : The number of jobs are skyrocketing.
Let us see how communication
works in Node.js
Slide 19 www.edureka.co/mastering-node-jsSlide 19Slide 19Slide 19
 For Network communication on Node.js, we use the “net” module
 net.createServer([options][,callback]) :
 If allowHalfOpen is true then when the other side initiates Connection Termination the server WILL NOT send the FIN
packet
Network Communication - TCP
//options object
{
allowHalfOpen : false , pauseOnConnect : false
}
//values : true or false, default : false
Slide 20 www.edureka.co/mastering-node-jsSlide 20Slide 20Slide 20
//Creating a TCP Server
var net = require(‘net’);
var server = net.createServer(function(socket)
{
socket.end(‘Hello World’); //Socket is a Duplex stream
});
server.listen(3000,function()
{
console.log(“Server is listening on Port 3000”);
});
Network Communication - TCP
Slide 21 www.edureka.co/mastering-node-jsSlide 21Slide 21Slide 21
//A TCP client
var net = require(‘net’);
var socket = net.createConnection({port: 3000,host: ‘192.168.0.1’);
socket.on(‘connect’,function()
{
console.log(‘connected to the server’);
})
socket.end(‘Hello Server’);
//we can now create a command line TCP chat server and client by using the //process.stdin
(Readable Stream) and process.stdout(Writable)
Network Communication - TCP
Demo
Slide 23 www.edureka.co/mastering-node-jsSlide 23Slide 23Slide 23
Two Way Communication : Socket.io
 Socket.io is a fast, real-time engine.
 Transmitting messages and Receiving message between client and server is simple: Events.
 On server/client when sending a message use socket.emit(‘eventname’,data). “eventname” can be any string
 And data can be any data: even Binary data!
 On server/client when you want to listen to events-messages use socket.on(‘eventname’,callbackFunction).
 Where the callbackFunction is a function that accepts a Data argument : Data sent by the other party.
Slide 24 www.edureka.co/mastering-node-jsSlide 24Slide 24Slide 24
 A simple example:
//Server-side
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(80);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
//client-side
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
Two Way Communication : Socket.io
Slide 25 www.edureka.co/mastering-node-jsSlide 25Slide 25Slide 25
 Besides ‘connect’, ‘message’ and ‘disconnect’ you can use any custom event names
 You could also have a separation of concerns by namespacing. Namespacing also means, that the same
websocket connection is used but is multiplexed
var io = require('socket.io').listen(80);
var chat = io
.of('/chat')
.on('connection', function (socket) {
socket.emit('a message', {
that: 'only'
, '/chat': 'will get'
}); });
var news = io
.of('/news')
.on('connection', function (socket) {
socket.emit('item', { news: 'item' });
});
<script>
var chat = io.connect('http://localhost/chat')
, news = io.connect('http://localhost/news');
chat.on('connect', function () {
chat.emit('hi!');
});
news.on('news', function () {
news.emit('woot');
});
</script>
Two Way Communication : Socket.io
Demo
Slide 27Slide 27Slide 27Slide 27 www.edureka.co/mastering-node-js
Certifications
Get certified in Mastering Node.js by Edureka
Edureka's Mastering Node.js course:
• You will learn how to develop fast real-time network applications using Node.js, ExpressJS and MongoDB, deal with templating
engines like Jade/Hogan/Handlebars and understand testing using Mocha/Jasmine
• It will train you to build networking and web based applications that are far more superior and efficient than applications build
in other languages.
• Get to work on a To-Do List App Project towards the end of the course, which gives you complete insights on the Node.js
framework.
• Online Live Courses: 27 hours
• Assignments: 20 hours
• Project: 20 hours
• Lifetime Access + 24 X 7 Support
Go to www.edureka.co/mastering-node-js
Thank You
Questions/Queries/Feedback
Recording and presentation will be made available to you within 24 hours

More Related Content

What's hot

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS ExpressDavid Boyer
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejsAmit Thakkar
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Expressjguerrero999
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)Chris Richardson
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaNurul Ferdous
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.jsFDConf
 

What's hot (20)

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Node.js
Node.jsNode.js
Node.js
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
NodeJS
NodeJSNodeJS
NodeJS
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)NodeJS: the good parts? A skeptic’s view (devnexus2014)
NodeJS: the good parts? A skeptic’s view (devnexus2014)
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.js
 

Viewers also liked

Handling web servers of high traffic sites
Handling web servers of high traffic sitesHandling web servers of high traffic sites
Handling web servers of high traffic sitesAshfame
 
Go and Uber’s time series database m3
Go and Uber’s time series database m3Go and Uber’s time series database m3
Go and Uber’s time series database m3Rob Skillington
 
Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907NodejsFoundation
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Mobile Data Terminal M710W Presentation
Mobile Data Terminal M710W PresentationMobile Data Terminal M710W Presentation
Mobile Data Terminal M710W PresentationHarvey Wang
 
Wso2 con 2014 event driven architecture Publish/Subscribe Pubsub
Wso2 con 2014 event driven architecture Publish/Subscribe PubsubWso2 con 2014 event driven architecture Publish/Subscribe Pubsub
Wso2 con 2014 event driven architecture Publish/Subscribe PubsubJohn Mathon
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron SchildkroutKafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkroutconfluent
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
Tutorial on Question Answering Systems
Tutorial on Question Answering Systems Tutorial on Question Answering Systems
Tutorial on Question Answering Systems Saeedeh Shekarpour
 
用十分鐘將你的網站送上雲端
用十分鐘將你的網站送上雲端用十分鐘將你的網站送上雲端
用十分鐘將你的網站送上雲端鍾誠 陳鍾誠
 
Siddhi: A Second Look at Complex Event Processing Implementations
Siddhi: A Second Look at Complex Event Processing ImplementationsSiddhi: A Second Look at Complex Event Processing Implementations
Siddhi: A Second Look at Complex Event Processing ImplementationsSrinath Perera
 
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014Ahmed Mahmoud
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkEdureka!
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.jsNodejsFoundation
 

Viewers also liked (18)

Handling web servers of high traffic sites
Handling web servers of high traffic sitesHandling web servers of high traffic sites
Handling web servers of high traffic sites
 
Go at uber
Go at uberGo at uber
Go at uber
 
Go and Uber’s time series database m3
Go and Uber’s time series database m3Go and Uber’s time series database m3
Go and Uber’s time series database m3
 
Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Mobile Data Terminal M710W Presentation
Mobile Data Terminal M710W PresentationMobile Data Terminal M710W Presentation
Mobile Data Terminal M710W Presentation
 
Wso2 con 2014 event driven architecture Publish/Subscribe Pubsub
Wso2 con 2014 event driven architecture Publish/Subscribe PubsubWso2 con 2014 event driven architecture Publish/Subscribe Pubsub
Wso2 con 2014 event driven architecture Publish/Subscribe Pubsub
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron SchildkroutKafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
Tutorial on Question Answering Systems
Tutorial on Question Answering Systems Tutorial on Question Answering Systems
Tutorial on Question Answering Systems
 
用十分鐘將你的網站送上雲端
用十分鐘將你的網站送上雲端用十分鐘將你的網站送上雲端
用十分鐘將你的網站送上雲端
 
Siddhi: A Second Look at Complex Event Processing Implementations
Siddhi: A Second Look at Complex Event Processing ImplementationsSiddhi: A Second Look at Complex Event Processing Implementations
Siddhi: A Second Look at Complex Event Processing Implementations
 
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014
Talk on Industrial Internet of Things @ Intelligent systems tech forum 2014
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 

Similar to Master Node.js Communication and Build Real-Time Apps

NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayEdureka!
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8amix3k
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Create simple api using node js
Create simple api using node jsCreate simple api using node js
Create simple api using node jsEdwin Andrianto
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 

Similar to Master Node.js Communication and Build Real-Time Apps (20)

NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Node js
Node jsNode js
Node js
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Create simple api using node js
Create simple api using node jsCreate simple api using node js
Create simple api using node js
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Proposal
ProposalProposal
Proposal
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 textsMaria Levchenko
 
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 Processorsdebabhi2
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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 AutomationSafe Software
 
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 interpreternaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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...Igalia
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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...
 

Master Node.js Communication and Build Real-Time Apps

  • 1. www.edureka.co/mastering-node-js View Mastering Node.js course details at www.edureka.co/mastering-node-js Communication in Node.js
  • 2. Slide 2Slide 2Slide 2Slide 2 www.edureka.co/mastering-node-js  Introduction of Node.js  Use Cases of Node.js  Network Communication in Node.js  Two Way Communication in Node.js What will you learn today?
  • 3. Slide 3 www.edureka.co/mastering-node-jsSlide 3 Traditional Multithreaded Model
  • 4. Slide 4 www.edureka.co/mastering-node-jsSlide 4 Problem with Multithreaded Model Thread 1 Thread 3 Shared Resource wants to update wants to update Thread 2 wants to update  In a multi-threaded HTTP server, for each and every request that the server receives, it creates a separate thread which handles that request  If a request acquires a lock in the shared resource and it is ‘exclusive’, it will affect result of other requests
  • 5. Slide 5 www.edureka.co/mastering-node-jsSlide 5 Single Threading Event Loop Event Queue Thread Pool file system network process other One Thread at a Time  On the other hand, framework like Node.js is event driven, handling all requests asynchronously from single thread  Almost no function in Node directly performs I/O, so the process never blocks
  • 6. Slide 6 www.edureka.co/mastering-node-jsSlide 6 What is Node.js ?  Node.js is a server-side runtime environment for networking applications. It is single threaded.  Node.js applications are written in JavaScript, and its open source based on Google’s V8 JavaScript Engine  It is cross platform and can run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM
  • 7. Slide 7 www.edureka.co/mastering-node-jsSlide 7 Node.js Detailed Architecture Client 1 Request 1 Request 1 Blocking IO Request ? Client 2 Client n Request 2 Request n Request 2 Event Loop Single Threaded Non Blocking I/O Tasks Processed here Request 1 Request 2 Request n Response 1 Response 2 Response n No No Non-Blocking IO Non-Blocking IO Request 1 Request 2 Send Responses Pick up requests from queue Event Queue
  • 8. Slide 8 www.edureka.co/mastering-node-jsSlide 8 Node.js Detailed Architecture Client 1 Request 1 T-1 Request 1 Database Filesystem Blocking IO Request ? Client 2 Client n Request 2 Request n T-2 T-m Thread T-1 Request n Request 2 Request n Event Loop Single Threaded Non Blocking I/O Tasks Processed here Request 1 Request 2 Request n Response 1 Response 2 Response n No No Yes handle by Non-Blocking IO Non-Blocking IO Request 1 Request 2 Send Responses Pick up requests from queue Node.js Platform internal Thread PoolEvent Queue Send Response to Request n Pick up one Thread from pool Blocking IO
  • 9. Slide 9 www.edureka.co/mastering-node-jsSlide 9 Use-Cases of Node.js (Contd.)  Previously LinkedIn Mobile was powered by Ruby on Rails  It was a synchronous app in which clients used to make several calls for a single page, consequently the system was bursting because of the load
  • 10. Slide 10 www.edureka.co/mastering-node-jsSlide 10 Use-Cases of Node.js (Contd.)  Previously LinkedIn Mobile was powered by Ruby on Rails  It was a synchronous app in which clients used to make several calls for a single page, consequently the system was bursting because of the load Advantage of using Node.js  The LinkedIN moved to Node.js which enabled them to move to a model where the client makes a single request for a page  It led to reduction in the number of machines used to host their services greater than 10:1
  • 11. Slide 11 www.edureka.co/mastering-node-jsSlide 11 Use-Cases of Node.js (Contd.)  Ebay was making real time applications with huge number of eBay- specific services  As eBay was having java infrastructure, it consumed many more resources than expected, raising questions about scalability for production
  • 12. Slide 12 www.edureka.co/mastering-node-jsSlide 12  Ebay was making real time applications with huge number of eBay- specific services  As eBay was having java infrastructure, it consumed many more resources than expected, raising questions about scalability for production  Node.js solved this issue as it is scalable because its single threaded so less overheads and that is why it utilizes the resources in the right manner, so no extra consumption of resources Use-Cases of Node.js (Contd.) Advantage of using Node.js
  • 13. Slide 13 www.edureka.co/mastering-node-jsSlide 13 Uber’s Story  Uber is a transportation company which allows users to get a taxi, private car or rideshare from their smartphones Uber uses NodeJS to implement their cab dispatch operation
  • 14. Slide 14 www.edureka.co/mastering-node-jsSlide 14 Uber - Old Architecture PHP PHP PHP PHP
  • 15. Slide 15 www.edureka.co/mastering-node-jsSlide 15 Uber - Multiple Dispatch Problem  Since PHP is a multithreaded language , each user’s request is handled in a separate thread  Once one car is dispatched for a user, in between the same car get dispatched to another user  Reason was car dispatch operation was executed from multiple threads
  • 16. Slide 16 www.edureka.co/mastering-node-jsSlide 16 Uber - New Architecture iPhone Android NodeJS Dispatch (NodeJS) Dispatch State (MongoDB) Real-time Logic Business Logic Persistent Store (MySQL) Python
  • 17. Slide 17 www.edureka.co/mastering-node-jsSlide 17 Job Trends From the graph below : The number of jobs are skyrocketing.
  • 18. Let us see how communication works in Node.js
  • 19. Slide 19 www.edureka.co/mastering-node-jsSlide 19Slide 19Slide 19  For Network communication on Node.js, we use the “net” module  net.createServer([options][,callback]) :  If allowHalfOpen is true then when the other side initiates Connection Termination the server WILL NOT send the FIN packet Network Communication - TCP //options object { allowHalfOpen : false , pauseOnConnect : false } //values : true or false, default : false
  • 20. Slide 20 www.edureka.co/mastering-node-jsSlide 20Slide 20Slide 20 //Creating a TCP Server var net = require(‘net’); var server = net.createServer(function(socket) { socket.end(‘Hello World’); //Socket is a Duplex stream }); server.listen(3000,function() { console.log(“Server is listening on Port 3000”); }); Network Communication - TCP
  • 21. Slide 21 www.edureka.co/mastering-node-jsSlide 21Slide 21Slide 21 //A TCP client var net = require(‘net’); var socket = net.createConnection({port: 3000,host: ‘192.168.0.1’); socket.on(‘connect’,function() { console.log(‘connected to the server’); }) socket.end(‘Hello Server’); //we can now create a command line TCP chat server and client by using the //process.stdin (Readable Stream) and process.stdout(Writable) Network Communication - TCP
  • 22. Demo
  • 23. Slide 23 www.edureka.co/mastering-node-jsSlide 23Slide 23Slide 23 Two Way Communication : Socket.io  Socket.io is a fast, real-time engine.  Transmitting messages and Receiving message between client and server is simple: Events.  On server/client when sending a message use socket.emit(‘eventname’,data). “eventname” can be any string  And data can be any data: even Binary data!  On server/client when you want to listen to events-messages use socket.on(‘eventname’,callbackFunction).  Where the callbackFunction is a function that accepts a Data argument : Data sent by the other party.
  • 24. Slide 24 www.edureka.co/mastering-node-jsSlide 24Slide 24Slide 24  A simple example: //Server-side var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server); server.listen(80); app.get('/', function (req, res) { res.sendfile(__dirname + '/index.html'); }); io.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); //client-side <script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); </script> Two Way Communication : Socket.io
  • 25. Slide 25 www.edureka.co/mastering-node-jsSlide 25Slide 25Slide 25  Besides ‘connect’, ‘message’ and ‘disconnect’ you can use any custom event names  You could also have a separation of concerns by namespacing. Namespacing also means, that the same websocket connection is used but is multiplexed var io = require('socket.io').listen(80); var chat = io .of('/chat') .on('connection', function (socket) { socket.emit('a message', { that: 'only' , '/chat': 'will get' }); }); var news = io .of('/news') .on('connection', function (socket) { socket.emit('item', { news: 'item' }); }); <script> var chat = io.connect('http://localhost/chat') , news = io.connect('http://localhost/news'); chat.on('connect', function () { chat.emit('hi!'); }); news.on('news', function () { news.emit('woot'); }); </script> Two Way Communication : Socket.io
  • 26. Demo
  • 27. Slide 27Slide 27Slide 27Slide 27 www.edureka.co/mastering-node-js Certifications Get certified in Mastering Node.js by Edureka Edureka's Mastering Node.js course: • You will learn how to develop fast real-time network applications using Node.js, ExpressJS and MongoDB, deal with templating engines like Jade/Hogan/Handlebars and understand testing using Mocha/Jasmine • It will train you to build networking and web based applications that are far more superior and efficient than applications build in other languages. • Get to work on a To-Do List App Project towards the end of the course, which gives you complete insights on the Node.js framework. • Online Live Courses: 27 hours • Assignments: 20 hours • Project: 20 hours • Lifetime Access + 24 X 7 Support Go to www.edureka.co/mastering-node-js
  • 28. Thank You Questions/Queries/Feedback Recording and presentation will be made available to you within 24 hours