SlideShare una empresa de Scribd logo
1 de 38
Introduction to Node.js®
Jitendra Kumar Patel
Saturday, January 31, 2015
Why node.js ?
“Node's goal is to
provide an easy
way to build
scalable Network
programs”
• Created by Ryan Dahl in 2009
• Development && maintenance sponsored by Joyent
• Licence MIT
• Last release : 0.10.31
• Based on Google V8 Engine
• +99 000 packages
About Node.js……
Success Stories…..
● Vert.x => Polygot programming
● Akka => Scala and Java
● Tornado => Python
● Libevent => C
● EventMachine => Ruby
Another project like Node.js….
● Another Web framework
● For beginner
● Multi-thread
Node.js not……
• Traditional desktop applications have a user interface wired up with
background logic
– user interfaces are based on Windows Forms, Jswing, WPF, Gtk, Qt, etc. and
dependant on operating system
• On the web user interfaces are standardized
– HTML for markup
– CSS for style
– JavaScript for dynamic content
• In the past proprietary technologies existed on the web, e.g. Adobe Flash,
ActiveX
– They are slowly dying
• Data is generated on the server, transferred to the client and displayed by
the browser
• Server Side technologies include PHP, JSP, ASP.net, Rails, Djanog, and
yes, also node.js
Development forthe Web….
● REST = REpresentational State Transfer
● Not new technology
● Architectural style for client-server
REST……
● General interface
● Scalability of component interface
● Reduce latency
● Encapsulate legacy system
Goals of REST……..
● GET
● POST
● PUT
● DELETE
HTTP Method……
● POST => Create
● GET => Read
● PUT => Update
● DELETE => Delete
HTTP Method with CRUD…..
● Non Blocking I/O
● V8 Javascript Engine
● Single Thread with Event Loop
● 40,025 modules
● Windows, Linux, Mac
● 1 Language for Frontend and Backend
● Active community
Why node.js ?
• Asynchronous i/o framework
• Core in c++ on top of v8
• Rest of it in javascript
• Swiss army knife for network Related stuffs
• Can handle thousands of Concurrent connections with Minimal
overhead (cpu/memory) on a single process
• It’s NOT a web framework, and it’s also NOT a language
What is node.js?
« A platform built on
Chrome's JavaScript runtime
for easily building fast,
scalable network
applications. »
http://nodejs.org/
• Friendly callbacks
• Ubiquitous
• No I/o Primitives
• One language to RULE them all
JavaScript is well known for client-side scripts running inside the browser
node.js is JavaScript running on the server-side
SSJS -> Server-Side JavaScript
Use a language you know
Use the same language for client side and server side
Why javascript ?!!!
JavaScript Engines……
• Perform asynchronous processing on single thread instead of classical multithread
processing, minimize overhead & latency, maximize scalability
• Scale horizontally instead of vertically
• Ideal for applications that serve a lot of requests but dont use/need lots of
computational power per request
• Not so ideal for heavy calculations, e.g. massive parallel computing
• Also: Less problems with concurrency
The idea behind node.js….
Node.js Event Loop
There are a couple of implications of this apparently very simple and basic model
• Avoid synchronous code at all costs because it blocks the event loop
• Which means: callbacks, callbacks, and more callbacks
Example :: Read data from file and show data
Blocking vs Non-Blocking……
● Read data from file
● Show data
● Do other tasks
var data = fs.readFileSync( “test.txt” );
console.log( data );
console.log( “Do other tasks” );
Blocking…..
● Read data from file
When read data completed, show data
● Do other tasks
fs.readFile( “test.txt”, function( err, data ) {
console.log(data);
});
Non-Blocking…… CallbackCallback
• Chat/Messaging
• Real-time Applications
• Intelligent Proxies
• High Concurrency Applications
• Communication Hubs
• Coordinators
When to use it ?
● Web application
● Websocket server
● Ad server
● Proxy server
● Streaming server
● Fast file upload client
● Any Real-time data apps
● Anything with high I/O
Node.js for….
• http://nodejs.org/ and Download tar.gz
• Extract to any directory
• $ ./configure && make install
Getting Started…..
Project informations
• Name
• Version
• Dependencies
• Licence
• Main file
Etc...
File package.json…..
● https://npmjs.org/
● # of modules = 1,21,943
Node.js Modules…..
$npm install <module name>
Install module…..
• var http = require(‘http’);
• var fs = require(‘fs’);
• var express = require(‘express’);
Using module…..
In NodeJS
Others modules…..
● express
● underscore
● request
● async
● mysql
Find more in npmjs.org…..
Favorite Modules…..
• IDEs for node.js
– online IDE like cloud9
– Eclipse with node.js plugins
– Visual Studio node.js Toolkit
– Jetbrains Webstorm
– lots of other IDEs: webmatrix, coderunner, Expresso, Atom, etc.
• Preferred : Jetbrains Webstorm & Visual Studio with node.js
Tools of the trade…..
http://expressjs.com
Express…
Middleware can:
• Execute any code.
• Make changes to the request and the response
objects.
• End the request-response cycle.
• Call the next middleware in the stack.
Express As Middleware
Express Middleware Modules….
● Inspire from Sinatra
● Fast
● Flexible
● Simple
Working with Express…..
• Release stable 0.10.36 (young)
• Lots of stuffs to look at
• Lots of half backed stuffs
• Retro compatibility???
• Bad at handling staticcontents
• Bad at handling binarycontents
• Hard to find organized and authoritative informations
Some Warnings…
Jitendra Kumar Patel
www.jitendrapatel.in
jitendra.patel@iiitb.org
@bewithjitendra
facebook.com/bewithjitendrapatel
Saturday, January 31, 2015
Introduction to node.js aka NodeJS

Más contenido relacionado

La actualidad más candente

OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
Amit Thakkar
 

La actualidad más candente (20)

Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
Understanding the Single Thread Event Loop
Understanding the Single Thread Event LoopUnderstanding the Single Thread Event Loop
Understanding the Single Thread Event Loop
 
Node.js concurrency
Node.js concurrencyNode.js concurrency
Node.js concurrency
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
Node.js, for architects - OpenSlava 2013
Node.js, for architects - OpenSlava 2013Node.js, for architects - OpenSlava 2013
Node.js, for architects - OpenSlava 2013
 
Java script at backend nodejs
Java script at backend   nodejsJava script at backend   nodejs
Java script at backend nodejs
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 

Destacado

Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
SEONGTAEK OH
 
Django best practices
Django best practicesDjango best practices
Django best practices
Adam Haney
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
Ganga Ram
 
AAPG POSTERS - Evolution of the Mardin Uplift
AAPG POSTERS - Evolution of the Mardin UpliftAAPG POSTERS - Evolution of the Mardin Uplift
AAPG POSTERS - Evolution of the Mardin Uplift
Joshua Doubek
 
Extrait benchmark pratiques agiles dans les organisations
Extrait benchmark pratiques agiles dans les organisationsExtrait benchmark pratiques agiles dans les organisations
Extrait benchmark pratiques agiles dans les organisations
Francois Salazar
 

Destacado (20)

Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
Building Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoBuilding Pluggable Web Applications using Django
Building Pluggable Web Applications using Django
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Django best practices
Django best practicesDjango best practices
Django best practices
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django
DjangoDjango
Django
 
2017 LSC Women's Basketball Championship Bracket
2017 LSC Women's Basketball Championship Bracket2017 LSC Women's Basketball Championship Bracket
2017 LSC Women's Basketball Championship Bracket
 
Django
DjangoDjango
Django
 
Continuous delivery with ant and salesfroce
Continuous delivery with ant and salesfroceContinuous delivery with ant and salesfroce
Continuous delivery with ant and salesfroce
 
2017 LSC Men's Basketball Championship Bracket
2017 LSC Men's Basketball Championship Bracket2017 LSC Men's Basketball Championship Bracket
2017 LSC Men's Basketball Championship Bracket
 
AAPG POSTERS - Evolution of the Mardin Uplift
AAPG POSTERS - Evolution of the Mardin UpliftAAPG POSTERS - Evolution of the Mardin Uplift
AAPG POSTERS - Evolution of the Mardin Uplift
 
Apex and design pattern
Apex and design patternApex and design pattern
Apex and design pattern
 
How to Start a Movement with Your Blog - with Gideon Shalwick
How to Start a Movement with Your Blog - with Gideon ShalwickHow to Start a Movement with Your Blog - with Gideon Shalwick
How to Start a Movement with Your Blog - with Gideon Shalwick
 
Sejarah perkembangan komputer
Sejarah perkembangan komputerSejarah perkembangan komputer
Sejarah perkembangan komputer
 
Extrait benchmark pratiques agiles dans les organisations
Extrait benchmark pratiques agiles dans les organisationsExtrait benchmark pratiques agiles dans les organisations
Extrait benchmark pratiques agiles dans les organisations
 
How to Become a Better Writer
How to Become a Better WriterHow to Become a Better Writer
How to Become a Better Writer
 
What is the most popular activity in the UK? The answer may surprise you.
What is the most popular activity in the UK? The answer may surprise you. What is the most popular activity in the UK? The answer may surprise you.
What is the most popular activity in the UK? The answer may surprise you.
 

Similar a Introduction to node.js aka NodeJS

Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
Andrew Ferrier
 

Similar a Introduction to node.js aka NodeJS (20)

18_Node.js.ppt
18_Node.js.ppt18_Node.js.ppt
18_Node.js.ppt
 
18_Node.js.ppt
18_Node.js.ppt18_Node.js.ppt
18_Node.js.ppt
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
An Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows AzureAn Introduction to Node.js Development with Windows Azure
An Introduction to Node.js Development with Windows Azure
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
NodeJS Presentation
NodeJS PresentationNodeJS Presentation
NodeJS Presentation
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Node.js
Node.jsNode.js
Node.js
 
20120802 timisoara
20120802 timisoara20120802 timisoara
20120802 timisoara
 
Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
A brief intro to nodejs
A brief intro to nodejsA brief intro to nodejs
A brief intro to nodejs
 
Scalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJSScalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJS
 
Node
NodeNode
Node
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 
Node.js In The Enterprise - A Primer
Node.js In The Enterprise - A PrimerNode.js In The Enterprise - A Primer
Node.js In The Enterprise - A Primer
 
Node and Azure
Node and AzureNode and Azure
Node and Azure
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Node.js 101 with Rami Sayar
Node.js 101 with Rami SayarNode.js 101 with Rami Sayar
Node.js 101 with Rami Sayar
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 

Más de JITENDRA KUMAR PATEL

Más de JITENDRA KUMAR PATEL (7)

Introduction-To-SMPC-Philips-Innovation-Campus-SecurityExploded
Introduction-To-SMPC-Philips-Innovation-Campus-SecurityExplodedIntroduction-To-SMPC-Philips-Innovation-Campus-SecurityExploded
Introduction-To-SMPC-Philips-Innovation-Campus-SecurityExploded
 
Improving-The-Round-Complexity-of-VSS-in-Point-To-Point-Networks
Improving-The-Round-Complexity-of-VSS-in-Point-To-Point-NetworksImproving-The-Round-Complexity-of-VSS-in-Point-To-Point-Networks
Improving-The-Round-Complexity-of-VSS-in-Point-To-Point-Networks
 
Glyph-Placement-Strategy
Glyph-Placement-StrategyGlyph-Placement-Strategy
Glyph-Placement-Strategy
 
Manufacturing Compromise The Emergence of Exploit-as-a-Service
Manufacturing Compromise The Emergence of Exploit-as-a-ServiceManufacturing Compromise The Emergence of Exploit-as-a-Service
Manufacturing Compromise The Emergence of Exploit-as-a-Service
 
Introduction to Web Server Security
Introduction to Web Server SecurityIntroduction to Web Server Security
Introduction to Web Server Security
 
Secure 2 Party AES
Secure 2 Party AESSecure 2 Party AES
Secure 2 Party AES
 
Docker meetup-jan-2015
Docker meetup-jan-2015Docker meetup-jan-2015
Docker meetup-jan-2015
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 

Último (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Introduction to node.js aka NodeJS

  • 1. Introduction to Node.js® Jitendra Kumar Patel Saturday, January 31, 2015
  • 2. Why node.js ? “Node's goal is to provide an easy way to build scalable Network programs”
  • 3. • Created by Ryan Dahl in 2009 • Development && maintenance sponsored by Joyent • Licence MIT • Last release : 0.10.31 • Based on Google V8 Engine • +99 000 packages About Node.js……
  • 5. ● Vert.x => Polygot programming ● Akka => Scala and Java ● Tornado => Python ● Libevent => C ● EventMachine => Ruby Another project like Node.js….
  • 6. ● Another Web framework ● For beginner ● Multi-thread Node.js not……
  • 7. • Traditional desktop applications have a user interface wired up with background logic – user interfaces are based on Windows Forms, Jswing, WPF, Gtk, Qt, etc. and dependant on operating system • On the web user interfaces are standardized – HTML for markup – CSS for style – JavaScript for dynamic content • In the past proprietary technologies existed on the web, e.g. Adobe Flash, ActiveX – They are slowly dying • Data is generated on the server, transferred to the client and displayed by the browser • Server Side technologies include PHP, JSP, ASP.net, Rails, Djanog, and yes, also node.js Development forthe Web….
  • 8. ● REST = REpresentational State Transfer ● Not new technology ● Architectural style for client-server REST……
  • 9. ● General interface ● Scalability of component interface ● Reduce latency ● Encapsulate legacy system Goals of REST……..
  • 10. ● GET ● POST ● PUT ● DELETE HTTP Method……
  • 11. ● POST => Create ● GET => Read ● PUT => Update ● DELETE => Delete HTTP Method with CRUD…..
  • 12. ● Non Blocking I/O ● V8 Javascript Engine ● Single Thread with Event Loop ● 40,025 modules ● Windows, Linux, Mac ● 1 Language for Frontend and Backend ● Active community Why node.js ?
  • 13. • Asynchronous i/o framework • Core in c++ on top of v8 • Rest of it in javascript • Swiss army knife for network Related stuffs • Can handle thousands of Concurrent connections with Minimal overhead (cpu/memory) on a single process • It’s NOT a web framework, and it’s also NOT a language What is node.js? « A platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. » http://nodejs.org/
  • 14. • Friendly callbacks • Ubiquitous • No I/o Primitives • One language to RULE them all JavaScript is well known for client-side scripts running inside the browser node.js is JavaScript running on the server-side SSJS -> Server-Side JavaScript Use a language you know Use the same language for client side and server side Why javascript ?!!!
  • 16. • Perform asynchronous processing on single thread instead of classical multithread processing, minimize overhead & latency, maximize scalability • Scale horizontally instead of vertically • Ideal for applications that serve a lot of requests but dont use/need lots of computational power per request • Not so ideal for heavy calculations, e.g. massive parallel computing • Also: Less problems with concurrency The idea behind node.js….
  • 17. Node.js Event Loop There are a couple of implications of this apparently very simple and basic model • Avoid synchronous code at all costs because it blocks the event loop • Which means: callbacks, callbacks, and more callbacks
  • 18. Example :: Read data from file and show data Blocking vs Non-Blocking……
  • 19. ● Read data from file ● Show data ● Do other tasks var data = fs.readFileSync( “test.txt” ); console.log( data ); console.log( “Do other tasks” ); Blocking…..
  • 20. ● Read data from file When read data completed, show data ● Do other tasks fs.readFile( “test.txt”, function( err, data ) { console.log(data); }); Non-Blocking…… CallbackCallback
  • 21. • Chat/Messaging • Real-time Applications • Intelligent Proxies • High Concurrency Applications • Communication Hubs • Coordinators When to use it ?
  • 22. ● Web application ● Websocket server ● Ad server ● Proxy server ● Streaming server ● Fast file upload client ● Any Real-time data apps ● Anything with high I/O Node.js for….
  • 23. • http://nodejs.org/ and Download tar.gz • Extract to any directory • $ ./configure && make install Getting Started…..
  • 24. Project informations • Name • Version • Dependencies • Licence • Main file Etc... File package.json…..
  • 25. ● https://npmjs.org/ ● # of modules = 1,21,943 Node.js Modules…..
  • 26. $npm install <module name> Install module…..
  • 27. • var http = require(‘http’); • var fs = require(‘fs’); • var express = require(‘express’); Using module…..
  • 30. ● express ● underscore ● request ● async ● mysql Find more in npmjs.org….. Favorite Modules…..
  • 31. • IDEs for node.js – online IDE like cloud9 – Eclipse with node.js plugins – Visual Studio node.js Toolkit – Jetbrains Webstorm – lots of other IDEs: webmatrix, coderunner, Expresso, Atom, etc. • Preferred : Jetbrains Webstorm & Visual Studio with node.js Tools of the trade…..
  • 33. Middleware can: • Execute any code. • Make changes to the request and the response objects. • End the request-response cycle. • Call the next middleware in the stack. Express As Middleware
  • 35. ● Inspire from Sinatra ● Fast ● Flexible ● Simple Working with Express…..
  • 36. • Release stable 0.10.36 (young) • Lots of stuffs to look at • Lots of half backed stuffs • Retro compatibility??? • Bad at handling staticcontents • Bad at handling binarycontents • Hard to find organized and authoritative informations Some Warnings…