SlideShare a Scribd company logo
Tech I/O
Node.js Server Side JavaScript
Ganesh Kondal
May 31, 2013
Agenda
Background
Overview & Introduction
Sample Code
• Event Model
• Non Blocking I/O
• Modules
Key Concepts
Applicability
In the Industry
2
• Quick collation of material from various allowed sources
– net, books & slides – to introduce the team to Node.JS
• To provide a glimpse of Node.JS
About
For
Folks who don’t know anything about Node.JS
Background
• Node.js runs on V8 Javascript Engine.
• V8 is Google’s open source engine; written in C++.
• Created by Ryan Dahl in 2009.
• Runs on Linux systems and Windows systems.
• Per Node.js
• IO is too costly
• Thread per connection is too memory intensive
!! (Apache creates one thread per connection)
4
Introduction
• Node.js is ‘server-side JavaScript’.
• High-performance network applications framework,
• Well optimized for high concurrent environments.
• Command line tool to execute nodeJS code.
• Written with 40% JS and 60% C++ code.
• Lightweight - Uses an event-driven, non-blocking I/O model.
• Event-loops / Non-blocking IO via JavaScript’s callbacks.
• Programs for Node.js are written in JavaScript [no DOM
implementation ]
• Everything inside Node.js runs in a single-thread.
• Yes!! Its single threaded. Below code will block the
server for a second.
• All but your code is multi-threaded !!! 
5
‘Hello Node.js’
• Type your JS code, open cmd/terminal and type
this:
‘node FILE_NAME.js’
• To execute the code
• ‘hello world’
var sys = require(“sys”);
setTimeout(function(){
sys.puts(“world”);},
3000);
sys.puts(“hello”);
//it prints ‘hello’ first and waits for 3 seconds and
then prints ‘world’
6
Event Loops
7
Event-loops are the core of event-driven programming, almost
all the UI programs use event-loops to track the user event, for
example: Clicks, Ajax Requests etc.
Client
Event
loop
(main thread)
C++ Thread pool
(worker threads)
Clients send HTTP requests
to Node.js server
An Event-loop is woken up by OS,
passes request and response objects
to the thread-pool
Long-running jobs run
on worker threads
Response is sent
back to main thread
via callback
Event loop returns
result to client
Non Blocking I/O
• Traditional I/O
• Non-traditional, Non-blocking I/O
8
var result = db.query(“select name from student”);
computeStudentExamResult(result); //wait for
result!
informResults(); //execution is blocked!
db.query(“select name from student”,function
(result){
computeStudentExamResult(result); //wait for
result!
});
informResults(); //executes without any delay!
Few things with Node.js
• You can create an HTTP server and print ‘hello world’ on the
browser in just 4 lines of JavaScript.
• You can create a TCP server similar to HTTP server, in just 4
lines of JavaScript. (Example included)
• You can create a DNS server.
• You can create a Static File Server.
• You can create a Web Chat Application like GTalk in the
browser.
• Node.js can also be used for creating online games,
collaboration tools or anything which sends updates to the
user in real-time.
9
Servers… in 3 lines of code
10
• Create HTTP Server and print ‘Hello World’ :
• TCP server on port 9000 that echoes the
request:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200,
{'Content-Type': 'text/plain'});
res.end('Hello Worldn'); })
.listen(5000, "127.0.0.1");
var net = require('net');
net.createServer(function (socket) {
socket.write("Echo serverrn");
socket.pipe(socket); })
.listen(9000,"127.0.0.1");
Node Modules
• Node.js heavily relies on modules, in previous
examples require keyword loaded the http & net
modules.
• Creating a module is easy, just put your JavaScript
code in a separate js file and include it in your code
by using keyword require, like:
var mod = require(‘./modulex’);
• Libraries in Node.js are called packages and they
can be installed by typing
npm install “package_name”; //package should be
available in npm registry @ nmpjs.org
• NPM (Node Package Manager) comes bundled with
Node.js installation.
11
Applicability
• Node.js is good for creating streaming based real-
time services, web chat applications, static file
servers etc.
• If you need high level concurrency and not worried
about CPU-cycles.
• If you are great at writing JavaScript code because
then you can use the same language at both the
places: server-side and client-side.
• High productivity (as long as the developer
understands/thinks in terms of callbacks, async I/O)
• Node.js principle – IO is costly.
• http://blog.mixu.net/2011/02/01/understandin
g-the-node-js-event-loop/
12
Not Applicable For
13
• Computation intensive tasks on server side, as the
event-loops are CPU hungry.
• Still in beta – so be cautious !!
• Can’t guarantee backward compatibility. Not a 1.0
• No match for enterprise level application
frameworks like Spring(java), Django(python), etc.
• Not battle tested yet!!!
Node.js in the Industry
• LinkedIn :
• On the server side, our entire mobile software stack is
completely built in Node. One reason was scale. The
second is Node showed us huge performance gains.
• Clouds 9 IDE
• eBay :
http://www.ebaytechblog.com/2013/05/17/how-we-built-ebays-first-
node-js-application/
For more refer - http://nodejs.org/industry/
14
Thank You

More Related Content

PPTX
Test driven development v1.0
PPTX
Node js for enterprise
PPTX
Introduction to node.js by jiban
ODP
Node.js architecture (EN)
PPTX
Beginners Node.js
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
PPTX
PDF
Node js internal
Test driven development v1.0
Node js for enterprise
Introduction to node.js by jiban
Node.js architecture (EN)
Beginners Node.js
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node js internal

What's hot (20)

PDF
Node js projects
PPT
Scalability using Node.js
PPTX
Let's server your Data
PDF
Afrimadoni the power of docker
PPTX
Kalp Corporate Node JS Perfect Guide
PPTX
Bccon use notes objects in memory and other useful
PPTX
Introduction to Node js
PPT
8 Most Effective Node.js Tools for Developers
PDF
Why You Should Use MERN Stack for Startup Apps?
PPTX
Basic Concept of Node.js & NPM
PPTX
Why Play Framework is fast
PDF
Starting from scratch in 2017
PDF
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
PDF
Bringing Interactivity to Your Drupal Site with Node.js Integration
PDF
Node.js Course 2 of 2 - Advanced techniques
PDF
Node.js an Exectutive View
PDF
Fundamental of Node.JS - Internship Presentation - Week7
PPT
Introduction to Node.js
PPT
PPTX
Saving Time By Testing With Jest
Node js projects
Scalability using Node.js
Let's server your Data
Afrimadoni the power of docker
Kalp Corporate Node JS Perfect Guide
Bccon use notes objects in memory and other useful
Introduction to Node js
8 Most Effective Node.js Tools for Developers
Why You Should Use MERN Stack for Startup Apps?
Basic Concept of Node.js & NPM
Why Play Framework is fast
Starting from scratch in 2017
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Bringing Interactivity to Your Drupal Site with Node.js Integration
Node.js Course 2 of 2 - Advanced techniques
Node.js an Exectutive View
Fundamental of Node.JS - Internship Presentation - Week7
Introduction to Node.js
Saving Time By Testing With Jest
Ad

Viewers also liked (7)

PPTX
Tech io spa_angularjs_20130814_v0.9.5
PPTX
Demysitifying Bitcoin and Blockchain
PPTX
NodeJS - Server Side JS
PDF
ATDD Using Robot Framework
PPT
BDD with JBehave and Selenium
PDF
The Six Highest Performing B2B Blog Post Formats
PDF
The Outcome Economy
Tech io spa_angularjs_20130814_v0.9.5
Demysitifying Bitcoin and Blockchain
NodeJS - Server Side JS
ATDD Using Robot Framework
BDD with JBehave and Selenium
The Six Highest Performing B2B Blog Post Formats
The Outcome Economy
Ad

Similar to Tech io nodejs_20130531_v0.6 (20)

PPT
Introduction to node.js aka NodeJS
PDF
Introduction to Node JS.pdf
PPT
Introducción y comandos en NodeJS slodte
PDF
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
PPTX
02 Node introduction
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
PPTX
Introduction to Node.js
PDF
Real time web
PPTX
Nodejs overview
PPT
18_Node.js.ppt
PDF
Server-side JS with NodeJS
PPTX
Scalable server component using NodeJS & ExpressJS
KEY
20120306 dublin js
KEY
An Introduction to Node.js Development with Windows Azure
PDF
An introduction to Node.js
PPTX
Node js for beginners
PPT
18_Node.js.ppt
PPTX
introduction to node.js
PDF
Introduction to Node.js: What, why and how?
PPTX
Introduction to node.js aka NodeJS
Introduction to Node JS.pdf
Introducción y comandos en NodeJS slodte
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
02 Node introduction
Server Side Web Development Unit 1 of Nodejs.pptx
Introduction to Node.js
Real time web
Nodejs overview
18_Node.js.ppt
Server-side JS with NodeJS
Scalable server component using NodeJS & ExpressJS
20120306 dublin js
An Introduction to Node.js Development with Windows Azure
An introduction to Node.js
Node js for beginners
18_Node.js.ppt
introduction to node.js
Introduction to Node.js: What, why and how?

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.

Tech io nodejs_20130531_v0.6

  • 1. Tech I/O Node.js Server Side JavaScript Ganesh Kondal May 31, 2013
  • 2. Agenda Background Overview & Introduction Sample Code • Event Model • Non Blocking I/O • Modules Key Concepts Applicability In the Industry 2
  • 3. • Quick collation of material from various allowed sources – net, books & slides – to introduce the team to Node.JS • To provide a glimpse of Node.JS About For Folks who don’t know anything about Node.JS
  • 4. Background • Node.js runs on V8 Javascript Engine. • V8 is Google’s open source engine; written in C++. • Created by Ryan Dahl in 2009. • Runs on Linux systems and Windows systems. • Per Node.js • IO is too costly • Thread per connection is too memory intensive !! (Apache creates one thread per connection) 4
  • 5. Introduction • Node.js is ‘server-side JavaScript’. • High-performance network applications framework, • Well optimized for high concurrent environments. • Command line tool to execute nodeJS code. • Written with 40% JS and 60% C++ code. • Lightweight - Uses an event-driven, non-blocking I/O model. • Event-loops / Non-blocking IO via JavaScript’s callbacks. • Programs for Node.js are written in JavaScript [no DOM implementation ] • Everything inside Node.js runs in a single-thread. • Yes!! Its single threaded. Below code will block the server for a second. • All but your code is multi-threaded !!!  5
  • 6. ‘Hello Node.js’ • Type your JS code, open cmd/terminal and type this: ‘node FILE_NAME.js’ • To execute the code • ‘hello world’ var sys = require(“sys”); setTimeout(function(){ sys.puts(“world”);}, 3000); sys.puts(“hello”); //it prints ‘hello’ first and waits for 3 seconds and then prints ‘world’ 6
  • 7. Event Loops 7 Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop (main thread) C++ Thread pool (worker threads) Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool Long-running jobs run on worker threads Response is sent back to main thread via callback Event loop returns result to client
  • 8. Non Blocking I/O • Traditional I/O • Non-traditional, Non-blocking I/O 8 var result = db.query(“select name from student”); computeStudentExamResult(result); //wait for result! informResults(); //execution is blocked! db.query(“select name from student”,function (result){ computeStudentExamResult(result); //wait for result! }); informResults(); //executes without any delay!
  • 9. Few things with Node.js • You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript. • You can create a TCP server similar to HTTP server, in just 4 lines of JavaScript. (Example included) • You can create a DNS server. • You can create a Static File Server. • You can create a Web Chat Application like GTalk in the browser. • Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time. 9
  • 10. Servers… in 3 lines of code 10 • Create HTTP Server and print ‘Hello World’ : • TCP server on port 9000 that echoes the request: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }) .listen(5000, "127.0.0.1"); var net = require('net'); net.createServer(function (socket) { socket.write("Echo serverrn"); socket.pipe(socket); }) .listen(9000,"127.0.0.1");
  • 11. Node Modules • Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules. • Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like: var mod = require(‘./modulex’); • Libraries in Node.js are called packages and they can be installed by typing npm install “package_name”; //package should be available in npm registry @ nmpjs.org • NPM (Node Package Manager) comes bundled with Node.js installation. 11
  • 12. Applicability • Node.js is good for creating streaming based real- time services, web chat applications, static file servers etc. • If you need high level concurrency and not worried about CPU-cycles. • If you are great at writing JavaScript code because then you can use the same language at both the places: server-side and client-side. • High productivity (as long as the developer understands/thinks in terms of callbacks, async I/O) • Node.js principle – IO is costly. • http://blog.mixu.net/2011/02/01/understandin g-the-node-js-event-loop/ 12
  • 13. Not Applicable For 13 • Computation intensive tasks on server side, as the event-loops are CPU hungry. • Still in beta – so be cautious !! • Can’t guarantee backward compatibility. Not a 1.0 • No match for enterprise level application frameworks like Spring(java), Django(python), etc. • Not battle tested yet!!!
  • 14. Node.js in the Industry • LinkedIn : • On the server side, our entire mobile software stack is completely built in Node. One reason was scale. The second is Node showed us huge performance gains. • Clouds 9 IDE • eBay : http://www.ebaytechblog.com/2013/05/17/how-we-built-ebays-first- node-js-application/ For more refer - http://nodejs.org/industry/ 14