SlideShare a Scribd company logo
Author: Bhushan Patil
Date: 08 Mar 2014
Nodejs






Node.js or nodejs or “node” simply is
“server side JavaScript”
Node.js is software platform
for scalable server-side and networking
applications.
Allows you to build scalable network
applications using JavaScript on the serverside.
Node.js
V8 JavaScript Runtime




The V8 JavaScript Engine is an open
source JavaScript engine developed
by Google for the Google Chrome web
browser.
V8 compiles JavaScript to native machine
code (IA-32, x86-64, ARM,
or MIPS ISAs) before executing it, instead
of more traditional techniques such as
executing bytecode or interpreting it.


“JavaScript has certain characteristics that

make it very different than other dynamic
languages, namely that it has no concept of
threads. Its model of concurrency is
completely based around events.” - Ryan
Dahl (Author node.js)




A Web Framework
For Beginners – it’s very low level
Multi-threaded – You can think of it as
single threaded server
Nodejs


Node js is for real-time web
◦ Node shines in real-time web applications
employing push technology over websockets Vs
stateless-web based on the stateless requestresponse paradigm.





Uses event-driven asynchronous callbacks

Handles concurrency very well than other
traditional web server
Traditional way
var result = database.query("SELECT * FROM hugetable");
console.log("Hello World");

Vs
Asynchronous way
database.query("SELECT * FROM hugetable", function(rows) {
var result = rows;
});
console.log("Hello World");
Nodejs
var
max
var
for

i, a, b, c, max;
= 1000000000;
d = Date.now();
(i = 0; i < max; i++) {
a = 1234 + 5678 + i;
b = 1234 * 5678 + i;
c = 1234 / 2 + i;

}
console.log(Date.now() - d);

$a = null; $b = null; $c = null; $i = null;
$max = 1000000000;
$start = microtime(true);
for ($i = 0; $i < $max; $i++) {
$a = 1234 + 5678 + $i;
$b = 1234 * 5678 + $i;
$c = 1234 / 2 + $i;
}
var_dump(microtime(true) - $start);

Time comparison in milliseconds

It means PHP is 93% slower than Node.js!
Nodejs





Websocket Server - like chat application
Fast File Upload Client
Ad Server
Any Real-Time Data Apps
Nodejs


No Need of separate Server
◦ it does not require a separate webserver like Apache
or Nginx or IIS. It has an inbuilt HTTP Server library
which makes it possible to run a webserver without
external software, and allowing more control of how
the webserver works.



Non-blocking code
◦ It does not execute line by line like other traditional
languages.



Asynchronous programming
◦ Every function in Node.js is asynchronous. Therefore,
everything that would normally block the thread is
instead executed in the background.
Blocking code
var contents = fs.readFileSync('/etc/hosts');
console.log(contents); //Stop process until complete
console.log('Doing something else');

Non-Blocking code
fs.readFile('/etc/hosts', function(err, contents) {
console.log(contents);
});
console.log('Doing something else');
Traditional way
var result = database.query("SELECT * FROM hugetable");
console.log("Hello World");

Asynchronous way
database.query("SELECT * FROM hugetable", function(rows) {
var result = rows;
});
console.log("Hello World");
Nodejs
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
If run at command prompt:

% node example.js
Server running at http://127.0.0.1:1337/
At browser: http://127.0.0.1:1337/

Hello World
Nodejs


npm, short for Node Package Manager, is
two things: first and foremost, it is an
online repository for the publishing of opensource Node.js projects; second, it is a
command-line utility for interacting with
said repository that aids in package
installation, version management, and
dependency management.








Some of the most popular NPM modules today are:
Express - Express.js, a Sinatra-inspired web
development framework for Node.js, and the defacto standard for the majority of Node.js
applications out there today.
connect - Connect is an extensible HTTP server
framework for Node.js, providing a collection of
high performance “plugins” known as
middleware; serves as a base foundation for
Express.
socket.io and sockjs - Server-side component of
the two most common websockets components
out there today.






Jade - One of the popular templating
engines, inspired by HAML, a default in
Express.js.
mongo and mongojs - MongoDB wrappers to
provide the API for MongoDB object databases in
Node.js.
redis - Redis client library.






coffee-script - CoffeeScript compiler that allows
developers to write their Node.js programs using
Coffee.
underscore (lodash, lazy) – The most popular
utility library in JavaScript, packaged to be used
with Node.js, as well as its two counterparts,
which promise better performance by taking a
slightly different implementation approach.
forever - Probably the most common utility for
ensuring that a given node script runs
continuously. Keeps your Node.js process up in
production in the face of any unexpected failures.
// Include http module,
var http = require('http'),
// And mysql module
mysql = require("mysql");
// Create the connection.
// Data is default to new mysql installation and should be changed according to your configuration.
var connection = mysql.createConnection({
user: "root",
password: "",
database: "db_name"
});
// Create the http server.
http.createServer(function (request, response) {
// Attach listener on end event.
request.on('end', function () {
// Query the database.
connection.query('SELECT * FROM your_table;', function (error, rows, fields) {
response.writeHead(200, {
'Content-Type': 'x-application/json'
});
// Send data as JSON string.
// Rows variable holds the result of the query.
response.end(JSON.stringify(rows));
});
});
// Listen on the 8080 port.
}).listen(8080);
Nodejs
And many .....
Nodejs
Nodejs







http://nodejs.org/
http://en.wikipedia.org/wiki/Nodejs
http://node.codeschool.com/
http://stackoverflow.com/questions/235381
8/how-do-i-get-started-with-node-js
http://code.tutsplus.com/tutorials/nodejsfor-beginners--net-26314
Nodejs

More Related Content

PDF
PPTX
Node js for beginners
PDF
Best node js course
PPTX
Introduction to Node js
PPTX
3 Things Everyone Knows About Node JS That You Don't
PPT
Node js
PDF
Node js (runtime environment + js library) platform
PDF
Node js projects
Node js for beginners
Best node js course
Introduction to Node js
3 Things Everyone Knows About Node JS That You Don't
Node js
Node js (runtime environment + js library) platform
Node js projects

What's hot (20)

PPTX
Introduction to node.js
PDF
Fundamental of Node.JS - Internship Presentation - Week7
PPTX
Node.js tutoria for beginner
PDF
Nodejs
ODP
Node.js architecture (EN)
PPT
8 Most Effective Node.js Tools for Developers
PPTX
NodeJS guide for beginners
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
PPTX
Nodejs basics
PPTX
Basic Concept of Node.js & NPM
PPTX
Node js Global Packages
PPT
Node.js an introduction
PPT
Node.js Basics
PDF
Node JS Crash Course
PDF
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
PPT
PDF
Node.js - Introduction and role in Frontend Development
PDF
Webconf nodejs-production-architecture
PPTX
Nodejs
PPTX
Introduction to NodeJS
Introduction to node.js
Fundamental of Node.JS - Internship Presentation - Week7
Node.js tutoria for beginner
Nodejs
Node.js architecture (EN)
8 Most Effective Node.js Tools for Developers
NodeJS guide for beginners
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Nodejs basics
Basic Concept of Node.js & NPM
Node js Global Packages
Node.js an introduction
Node.js Basics
Node JS Crash Course
What is Node.js | Node.js Tutorial for Beginners | Node.js Modules | Node.js ...
Node.js - Introduction and role in Frontend Development
Webconf nodejs-production-architecture
Nodejs
Introduction to NodeJS
Ad

Viewers also liked (17)

PPTX
Summer training seminar
PPT
Web Fendamentals
PPTX
Turning Marketing Words into a Branded People Experience
PPTX
Basic Website 101
PDF
PHPNW14 - Getting Started With AWS
PDF
Why Node.js
PPT
Web Security Introduction Webserver hacking refers to ...
PDF
Ajax And JSON
ODP
Joomla REST API
PPT
Pentesting web applications
KEY
Server side scripting smack down - Node.js vs PHP
PDF
Webservices: connecting Joomla! with other programs.
PDF
PPTX
WebSphere App Server vs JBoss vs WebLogic vs Tomcat
PDF
Client Vs. Server Rendering
PPTX
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
PPT
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
Summer training seminar
Web Fendamentals
Turning Marketing Words into a Branded People Experience
Basic Website 101
PHPNW14 - Getting Started With AWS
Why Node.js
Web Security Introduction Webserver hacking refers to ...
Ajax And JSON
Joomla REST API
Pentesting web applications
Server side scripting smack down - Node.js vs PHP
Webservices: connecting Joomla! with other programs.
WebSphere App Server vs JBoss vs WebLogic vs Tomcat
Client Vs. Server Rendering
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
Ad

Similar to Nodejs (20)

PPTX
Kalp Corporate Node JS Perfect Guide
PDF
Node.js Web Development .pdf
PPT
node.js
PPTX
02 Node introduction
PPTX
Beginners Node.js
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
PPTX
Difference between Node.js vs Java script
PDF
Node JS Interview Question PDF By ScholarHat
PPTX
Nodejs
PPTX
Node.js
PDF
Developing realtime apps with Drupal and NodeJS
PDF
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
PDF
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
PDF
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
PPTX
Top 10 frameworks of node js
PPTX
PPTX
World of Node.JS
DOCX
Understanding Node.js and Django.docx
Kalp Corporate Node JS Perfect Guide
Node.js Web Development .pdf
node.js
02 Node introduction
Beginners Node.js
Server Side Web Development Unit 1 of Nodejs.pptx
Difference between Node.js vs Java script
Node JS Interview Question PDF By ScholarHat
Nodejs
Node.js
Developing realtime apps with Drupal and NodeJS
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Построение простого REST сервера на Node.js | Odessa Frontend Code challenge
Top 10 frameworks of node js
World of Node.JS
Understanding Node.js and Django.docx

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence

Nodejs

  • 3.    Node.js or nodejs or “node” simply is “server side JavaScript” Node.js is software platform for scalable server-side and networking applications. Allows you to build scalable network applications using JavaScript on the serverside. Node.js V8 JavaScript Runtime
  • 4.   The V8 JavaScript Engine is an open source JavaScript engine developed by Google for the Google Chrome web browser. V8 compiles JavaScript to native machine code (IA-32, x86-64, ARM, or MIPS ISAs) before executing it, instead of more traditional techniques such as executing bytecode or interpreting it.
  • 5.  “JavaScript has certain characteristics that make it very different than other dynamic languages, namely that it has no concept of threads. Its model of concurrency is completely based around events.” - Ryan Dahl (Author node.js)
  • 6.    A Web Framework For Beginners – it’s very low level Multi-threaded – You can think of it as single threaded server
  • 8.  Node js is for real-time web ◦ Node shines in real-time web applications employing push technology over websockets Vs stateless-web based on the stateless requestresponse paradigm.   Uses event-driven asynchronous callbacks Handles concurrency very well than other traditional web server
  • 9. Traditional way var result = database.query("SELECT * FROM hugetable"); console.log("Hello World"); Vs Asynchronous way database.query("SELECT * FROM hugetable", function(rows) { var result = rows; }); console.log("Hello World");
  • 11. var max var for i, a, b, c, max; = 1000000000; d = Date.now(); (i = 0; i < max; i++) { a = 1234 + 5678 + i; b = 1234 * 5678 + i; c = 1234 / 2 + i; } console.log(Date.now() - d); $a = null; $b = null; $c = null; $i = null; $max = 1000000000; $start = microtime(true); for ($i = 0; $i < $max; $i++) { $a = 1234 + 5678 + $i; $b = 1234 * 5678 + $i; $c = 1234 / 2 + $i; } var_dump(microtime(true) - $start); Time comparison in milliseconds It means PHP is 93% slower than Node.js!
  • 13.     Websocket Server - like chat application Fast File Upload Client Ad Server Any Real-Time Data Apps
  • 15.  No Need of separate Server ◦ it does not require a separate webserver like Apache or Nginx or IIS. It has an inbuilt HTTP Server library which makes it possible to run a webserver without external software, and allowing more control of how the webserver works.  Non-blocking code ◦ It does not execute line by line like other traditional languages.  Asynchronous programming ◦ Every function in Node.js is asynchronous. Therefore, everything that would normally block the thread is instead executed in the background.
  • 16. Blocking code var contents = fs.readFileSync('/etc/hosts'); console.log(contents); //Stop process until complete console.log('Doing something else'); Non-Blocking code fs.readFile('/etc/hosts', function(err, contents) { console.log(contents); }); console.log('Doing something else');
  • 17. Traditional way var result = database.query("SELECT * FROM hugetable"); console.log("Hello World"); Asynchronous way database.query("SELECT * FROM hugetable", function(rows) { var result = rows; }); console.log("Hello World");
  • 19. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); If run at command prompt: % node example.js Server running at http://127.0.0.1:1337/ At browser: http://127.0.0.1:1337/ Hello World
  • 21.  npm, short for Node Package Manager, is two things: first and foremost, it is an online repository for the publishing of opensource Node.js projects; second, it is a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management.
  • 22.     Some of the most popular NPM modules today are: Express - Express.js, a Sinatra-inspired web development framework for Node.js, and the defacto standard for the majority of Node.js applications out there today. connect - Connect is an extensible HTTP server framework for Node.js, providing a collection of high performance “plugins” known as middleware; serves as a base foundation for Express. socket.io and sockjs - Server-side component of the two most common websockets components out there today.
  • 23.    Jade - One of the popular templating engines, inspired by HAML, a default in Express.js. mongo and mongojs - MongoDB wrappers to provide the API for MongoDB object databases in Node.js. redis - Redis client library.
  • 24.    coffee-script - CoffeeScript compiler that allows developers to write their Node.js programs using Coffee. underscore (lodash, lazy) – The most popular utility library in JavaScript, packaged to be used with Node.js, as well as its two counterparts, which promise better performance by taking a slightly different implementation approach. forever - Probably the most common utility for ensuring that a given node script runs continuously. Keeps your Node.js process up in production in the face of any unexpected failures.
  • 25. // Include http module, var http = require('http'), // And mysql module mysql = require("mysql"); // Create the connection. // Data is default to new mysql installation and should be changed according to your configuration. var connection = mysql.createConnection({ user: "root", password: "", database: "db_name" }); // Create the http server. http.createServer(function (request, response) { // Attach listener on end event. request.on('end', function () { // Query the database. connection.query('SELECT * FROM your_table;', function (error, rows, fields) { response.writeHead(200, { 'Content-Type': 'x-application/json' }); // Send data as JSON string. // Rows variable holds the result of the query. response.end(JSON.stringify(rows)); }); }); // Listen on the 8080 port. }).listen(8080);