SlideShare a Scribd company logo
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 applications
Tom Croucher
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Vikash Singh
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
Roberto Casadei
 
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
 
Node.js
Node.jsNode.js
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
Vatsal N Shah
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
Ryan 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.js
Dinesh U
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
David Boyer
 
NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
Kamal Hussain
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit 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 scale
Tom 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 Express
jguerrero999
 
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, Dhaka
Nurul 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.js
FDConf
 

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 sites
Ashfame
 
Go at uber
Go at uberGo at uber
Go at uber
Rob Skillington
 
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
Rob Skillington
 
Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907Node Foundation Membership Overview 20160907
Node Foundation Membership Overview 20160907
NodejsFoundation
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
ravisankar munusamy
 
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
Francois Zaninotto
 
Mobile Data Terminal M710W Presentation
Mobile Data Terminal M710W PresentationMobile Data Terminal M710W Presentation
Mobile Data Terminal M710W Presentation
Harvey 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 Pubsub
John Mathon
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
Steven 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 Schildkrout
confluent
 
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 Implementations
Srinath 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 2014
Ahmed 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 Framework
Edureka!
 
The Enterprise Case for Node.js
The Enterprise Case for Node.jsThe Enterprise Case for Node.js
The Enterprise Case for Node.js
NodejsFoundation
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
Amit Ranjan
 

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 Communication in Node.js

NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
Edureka!
 
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
Edureka!
 
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
Edureka!
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
Van-Duyet Le
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
amix3k
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
Collaboration Technologies
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
Node js
Node jsNode js
Node js
Chirag Parmar
 
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
Ben 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.js
soft-shake.ch
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
Jackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
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 Stack
Nir Noy
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
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
Edwin Andrianto
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
Gonzalo Ayuso
 
Proposal
ProposalProposal
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
rani marri
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
David Lindkvist
 

Similar to Communication in Node.js (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 | Edureka
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
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
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
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
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
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
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
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
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
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 

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

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 

Recently uploaded (20)

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 

Communication in Node.js

  • 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