SlideShare a Scribd company logo
1 of 31
Node JS Introduction
Parth Joshi
Entrepreneur | Techno - Consultant | Corporate Trainer
parthjoshi.in | LinkedIN | Twitter |
The need for node.js like
architecture
Evolution of Web Server and client
architecture
Client Server
HTTP Request
Response
(Static Documents)
Web Client (Browser):
Javascript
HTML
Evolution of Web Server and client
architecture
Client Server
Web Client (Browser):
Javascript
HTML
Web Servers:
Java
Python
PHP
Ruby
.NET
HTTP Request
Response
(Static Documents,
Dynamic Web Pages)
Evolution of Web Server and client
architecture
Client Server
Web Client (Browser):
Javascript
HTML
Mobile Client
Android
iOS
Native Clients
Java
Python
API Servers:
Java
Python
PHP
Ruby
.NET
HTTP Request
Response
Dynamic Pages
Static Documents
XML Response
Evolution of Web Server and client
architecture
Client Server
Web Client (Browser):
Javascript
HTML
Mobile Client
Android
iOS
Native Clients
Java
Python
API Servers:
Java
Python
Node
PHP
Ruby
.NET
HTTP Request
JSON Response
[Employee list]
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{ ...
Enter JSON
JSON VS. XML
JSON file XML File
Evolution of Web Server and client
architecture
How is JSON Used
Client Server
Web Client (Browser):
Javascript
HTML
Mobile Client
Android
iOS
Native Clients
Java
Python
API Servers:
Java
Python
Node
PHP
Ruby
.NET
HTTP Request
JSON Response
[Employee list]
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{ ...
Evolution of Web Server and client
architecture
The Idea behind Mongo DB
Client Server
Web Client (Browser):
Javascript
HTML
Mobile Client
Android
iOS
Native Clients
Java
Python
API Servers:
Java
Python
Node
PHP
Ruby
.NET
HTTP Request
JSON Response
[Employee list]
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{ ...
Store Data in form of JSON Objects
So what is nodejs?
Chrome V8 Engine
• The V8 JavaScript Engine is an open source JavaScript engine
• developed by The Chromium Project for the Google Chrome web
browser
Chrome V8 Engine
Chrome V8 Engine
Javascript Code
Native Machine Code
• V8 compiles JavaScript to native machine code before
executing it.
• instead of more traditional techniques such as interpreting
bytecode or compiling the whole program to machine code
and executing it from a filesystem.
• The compiled code is additionally optimized (and re-optimized)
dynamically at runtime, based on heuristics of the code's
execution profile.
• Optimization techniques used include inlining, elision of
expensive runtime properties, and inline caching, among many
others.
Written in c/c++
So What’s Nodejs?
Node Js runs on Chrome V8 Engine
In Simple words:
“Node.Js is server side javascript framework”
So What’s Nodejs?
Node Js runs on Chrome V8 Engine
In not-so-simple Words :
“Node.js is a high-performance network applications framework,
well optimized for high concurrent environments.”
Highlights on node.js
• Node.js uses an event-driven, non-blocking I/O model, which makes
it lightweight.
• It makes use of event-loops via JavaScript’s callback functionality to
implement the non-blocking I/O.
• Programs for Node.js are written in JavaScript but not in the same
JavaScript we are use to. There is no DOM implementation provided
by Node.js, i.e. you can not do this:
• var element = document.getElementById(“elementId”);
• Everything inside Node.js runs in a single-thread.
Node.js stack
Lets get some hands on.
• Install node.js
• Install Visual Studio Code.
A Simple Hello world example
console.log ("Hello world with node");
Hello.js
Execute the code:
$ node Hello.js
Hello world with node
$ _
Let take some command line arguments
Use process object to access the command line arguments
Example:
process.argv[i] : to access the command line arguments
process.argv[i].length: to get the number of arguments
Print Command line arguments
var argument = "";
for (var i = 0; i < process.argv.length; i++) {
argument = process.argv[i];
console.log(argument);
}
File: comline.js
$node comline.js hello world
node
comline.js
hello
world
$node comline.js
node
comline.js
$node comline.js hello world
node
comline.js
hello
world
Execution:
Lets run a server now
// getting the http module
var http = require('http');
// creating server instance
var server = http.createServer(function(request, response){
response.writeHead(200, {'Content-Type' : 'text/html'});
response.write('Hello world<br/>');
response.end('bye bye');
});
// listening to server at port 9090
server.listen(9090,'127.0.0.1');
Understanding basics
Import node module using require function.
var http = require('http');
Understanding basics
Create a server instance
// creating server instance
var server = http.createServer(function(request, response){
response.writeHead(200, {'Content-Type' : 'text/html'});
response.write('Hello world <br/>');
response.end('bye bye');
});
As per the docs:
http.createServer([requestListener])
Returns a new instance of http.Server.
The requestListener is a function which is automatically added to the 'request' event.
Understanding basics
Listen to port 9090 at localhost
server.listen(9090,'127.0.0.1');
Coming back to Event Loop
Lets have a feel of non blocking IO
var fs = require('fs');
var data = fs.readFileSync("myText.txt");
var fs = require('fs');
fs.readFile('myText.txt',function(err,data){
…
});
Synchronous IO Async IO (Non Blocking)
File Streams
Input Streams
var fs = require('fs');
// creating a reading stream...
var readerStream = fs.createReadStream ("mytext.txt");
var dataRead = "";
readerStream.setEncoding('utf8');
File Streams
Events for Streams
data - This event is fired when there is data is available to read.
end - This event is fired when there is no more data to read.
error - This event is fired when there is any error receiving or writing data.
finish - This event is fired when all data has been flushed to underlying
system
File Streams
Input Streams
readerStream.on ('data', function (buffer){
dataRead += buffer;
}) ;
// when there is end in the stream
readerStream.on ('end', function (){
console.log(dataRead);
}) ;
// if there is error in the stream connection
readerStream.on ('error', function (err){
console.log("There is error:"+err);
}) ;
File Streams
var fs = require("fs");
var data = 'Simply Easy Learning';
// Create a writable stream
var writerStream = fs.createWriteStream('output.txt');
// Write the data to stream with encoding to be utf8
writerStream.write(data,'UTF8');
// Mark the end of file
writerStream.end();
Input Streams
Thank you
Parth Joshi
Entrepreneur | Techno - Consultant | Corporate Trainer
parthjoshi.in | LinkedIN | Twitter | joshiparthin@gmail.com

More Related Content

What's hot

Node Security: The Good, Bad & Ugly
Node Security: The Good, Bad & UglyNode Security: The Good, Bad & Ugly
Node Security: The Good, Bad & UglyBishan Singh
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & ExpressChristian Joudrey
 
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...Fwdays
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseAaron Silverman
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorialKaty Slemon
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service WorkerChang W. Doh
 
Node.js first slide
Node.js first slideNode.js first slide
Node.js first slideSoni Pandey
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisYork Tsai
 
"The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi..."The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi...Fwdays
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
 

What's hot (20)

Node Security: The Good, Bad & Ugly
Node Security: The Good, Bad & UglyNode Security: The Good, Bad & Ugly
Node Security: The Good, Bad & Ugly
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Node intro
Node introNode intro
Node intro
 
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
Alexey Kupriyanenko "The State of Modern JavaScript and Web in 2020 - Real us...
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Node js first look - 2016
Node js first look - 2016Node js first look - 2016
Node js first look - 2016
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorial
 
Analyse Yourself
Analyse YourselfAnalyse Yourself
Analyse Yourself
 
Instant and offline apps with Service Worker
Instant and offline apps with Service WorkerInstant and offline apps with Service Worker
Instant and offline apps with Service Worker
 
Node.js first slide
Node.js first slideNode.js first slide
Node.js first slide
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
 
"The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi..."The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi...
 
JavaScript Web Workers
JavaScript Web WorkersJavaScript Web Workers
JavaScript Web Workers
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
Node azure
Node azureNode azure
Node azure
 

Similar to Node.js introduction

An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.jsAyush Mishra
 
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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSCosmin Mereuta
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js PlatformNaresh Chintalcheru
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 

Similar to Node.js introduction (20)

An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of 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
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Proposal
ProposalProposal
Proposal
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
node js.pptx
node js.pptxnode js.pptx
node js.pptx
 
NodeJS
NodeJSNodeJS
NodeJS
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
08 ajax
08 ajax08 ajax
08 ajax
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
5.node js
5.node js5.node js
5.node js
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
SocketStream
SocketStreamSocketStream
SocketStream
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 

Recently uploaded

一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样AS
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理SS
 
APNIC Updates presented by Paul Wilson at CaribNOG 27
APNIC Updates presented by Paul Wilson at  CaribNOG 27APNIC Updates presented by Paul Wilson at  CaribNOG 27
APNIC Updates presented by Paul Wilson at CaribNOG 27APNIC
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...mikehavy0
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样AS
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理F
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证hfkmxufye
 
一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理F
 
一比一原版贝德福特大学毕业证学位证书
一比一原版贝德福特大学毕业证学位证书一比一原版贝德福特大学毕业证学位证书
一比一原版贝德福特大学毕业证学位证书F
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样AS
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理AS
 
一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理F
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理apekaom
 
Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Dewi Agency
 

Recently uploaded (20)

一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
 
APNIC Updates presented by Paul Wilson at CaribNOG 27
APNIC Updates presented by Paul Wilson at  CaribNOG 27APNIC Updates presented by Paul Wilson at  CaribNOG 27
APNIC Updates presented by Paul Wilson at CaribNOG 27
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
 
一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理
 
一比一原版贝德福特大学毕业证学位证书
一比一原版贝德福特大学毕业证学位证书一比一原版贝德福特大学毕业证学位证书
一比一原版贝德福特大学毕业证学位证书
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
一比一原版(Polytechnic毕业证书)新加坡理工学院毕业证原件一模一样
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理
一比一原版(Dundee毕业证书)英国爱丁堡龙比亚大学毕业证如何办理
 
一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
 
Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303
 

Node.js introduction

  • 1. Node JS Introduction Parth Joshi Entrepreneur | Techno - Consultant | Corporate Trainer parthjoshi.in | LinkedIN | Twitter |
  • 2. The need for node.js like architecture
  • 3. Evolution of Web Server and client architecture Client Server HTTP Request Response (Static Documents) Web Client (Browser): Javascript HTML
  • 4. Evolution of Web Server and client architecture Client Server Web Client (Browser): Javascript HTML Web Servers: Java Python PHP Ruby .NET HTTP Request Response (Static Documents, Dynamic Web Pages)
  • 5. Evolution of Web Server and client architecture Client Server Web Client (Browser): Javascript HTML Mobile Client Android iOS Native Clients Java Python API Servers: Java Python PHP Ruby .NET HTTP Request Response Dynamic Pages Static Documents XML Response
  • 6. Evolution of Web Server and client architecture Client Server Web Client (Browser): Javascript HTML Mobile Client Android iOS Native Clients Java Python API Servers: Java Python Node PHP Ruby .NET HTTP Request JSON Response [Employee list] { "employees": [ { "firstName": "John", "lastName": "Doe" }, { ...
  • 7. Enter JSON JSON VS. XML JSON file XML File
  • 8. Evolution of Web Server and client architecture How is JSON Used Client Server Web Client (Browser): Javascript HTML Mobile Client Android iOS Native Clients Java Python API Servers: Java Python Node PHP Ruby .NET HTTP Request JSON Response [Employee list] { "employees": [ { "firstName": "John", "lastName": "Doe" }, { ...
  • 9. Evolution of Web Server and client architecture The Idea behind Mongo DB Client Server Web Client (Browser): Javascript HTML Mobile Client Android iOS Native Clients Java Python API Servers: Java Python Node PHP Ruby .NET HTTP Request JSON Response [Employee list] { "employees": [ { "firstName": "John", "lastName": "Doe" }, { ... Store Data in form of JSON Objects
  • 10. So what is nodejs?
  • 11. Chrome V8 Engine • The V8 JavaScript Engine is an open source JavaScript engine • developed by The Chromium Project for the Google Chrome web browser
  • 12. Chrome V8 Engine Chrome V8 Engine Javascript Code Native Machine Code • V8 compiles JavaScript to native machine code before executing it. • instead of more traditional techniques such as interpreting bytecode or compiling the whole program to machine code and executing it from a filesystem. • The compiled code is additionally optimized (and re-optimized) dynamically at runtime, based on heuristics of the code's execution profile. • Optimization techniques used include inlining, elision of expensive runtime properties, and inline caching, among many others. Written in c/c++
  • 13. So What’s Nodejs? Node Js runs on Chrome V8 Engine In Simple words: “Node.Js is server side javascript framework”
  • 14. So What’s Nodejs? Node Js runs on Chrome V8 Engine In not-so-simple Words : “Node.js is a high-performance network applications framework, well optimized for high concurrent environments.”
  • 15. Highlights on node.js • Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. • It makes use of event-loops via JavaScript’s callback functionality to implement the non-blocking I/O. • Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. There is no DOM implementation provided by Node.js, i.e. you can not do this: • var element = document.getElementById(“elementId”); • Everything inside Node.js runs in a single-thread.
  • 17. Lets get some hands on. • Install node.js • Install Visual Studio Code.
  • 18. A Simple Hello world example console.log ("Hello world with node"); Hello.js Execute the code: $ node Hello.js Hello world with node $ _
  • 19. Let take some command line arguments Use process object to access the command line arguments Example: process.argv[i] : to access the command line arguments process.argv[i].length: to get the number of arguments
  • 20. Print Command line arguments var argument = ""; for (var i = 0; i < process.argv.length; i++) { argument = process.argv[i]; console.log(argument); } File: comline.js $node comline.js hello world node comline.js hello world $node comline.js node comline.js $node comline.js hello world node comline.js hello world Execution:
  • 21. Lets run a server now // getting the http module var http = require('http'); // creating server instance var server = http.createServer(function(request, response){ response.writeHead(200, {'Content-Type' : 'text/html'}); response.write('Hello world<br/>'); response.end('bye bye'); }); // listening to server at port 9090 server.listen(9090,'127.0.0.1');
  • 22. Understanding basics Import node module using require function. var http = require('http');
  • 23. Understanding basics Create a server instance // creating server instance var server = http.createServer(function(request, response){ response.writeHead(200, {'Content-Type' : 'text/html'}); response.write('Hello world <br/>'); response.end('bye bye'); }); As per the docs: http.createServer([requestListener]) Returns a new instance of http.Server. The requestListener is a function which is automatically added to the 'request' event.
  • 24. Understanding basics Listen to port 9090 at localhost server.listen(9090,'127.0.0.1');
  • 25. Coming back to Event Loop
  • 26. Lets have a feel of non blocking IO var fs = require('fs'); var data = fs.readFileSync("myText.txt"); var fs = require('fs'); fs.readFile('myText.txt',function(err,data){ … }); Synchronous IO Async IO (Non Blocking)
  • 27. File Streams Input Streams var fs = require('fs'); // creating a reading stream... var readerStream = fs.createReadStream ("mytext.txt"); var dataRead = ""; readerStream.setEncoding('utf8');
  • 28. File Streams Events for Streams data - This event is fired when there is data is available to read. end - This event is fired when there is no more data to read. error - This event is fired when there is any error receiving or writing data. finish - This event is fired when all data has been flushed to underlying system
  • 29. File Streams Input Streams readerStream.on ('data', function (buffer){ dataRead += buffer; }) ; // when there is end in the stream readerStream.on ('end', function (){ console.log(dataRead); }) ; // if there is error in the stream connection readerStream.on ('error', function (err){ console.log("There is error:"+err); }) ;
  • 30. File Streams var fs = require("fs"); var data = 'Simply Easy Learning'; // Create a writable stream var writerStream = fs.createWriteStream('output.txt'); // Write the data to stream with encoding to be utf8 writerStream.write(data,'UTF8'); // Mark the end of file writerStream.end(); Input Streams
  • 31. Thank you Parth Joshi Entrepreneur | Techno - Consultant | Corporate Trainer parthjoshi.in | LinkedIN | Twitter | joshiparthin@gmail.com