SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
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

Weitere Àhnliche Inhalte

Was ist angesagt?

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
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an IntroductionRoberto 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
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shahVatsal N Shah
 
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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101Amit Ranjan
 

Andere mochten auch (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
 

Ähnlich wie 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 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
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptxrani marri
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket APIDavid Lindkvist
 

Ähnlich wie 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
 

Mehr von 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!
 

Mehr von 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
 

KĂŒrzlich hochgeladen

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 

KĂŒrzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 

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