SlideShare une entreprise Scribd logo
1  sur  32
Introduction to
Web Applications
Budhram Gurung
By -
Code used for this session can be found : https://github.com/budh-ram/express_demo_app
node.js
Created by
Ryan Dahl
in 2009
Background
node.js runs on V8. It is a set of bindings to the V8
JavaScript VM.
V8 is an open source JavaScript engine developed by
Google. Its written in C++ and is used in Google Chrome
Browser.
Latest version is v0.10.18
Is Open Source. It runs well on Linux/Unix systems, can also
run on Windows systems.
Installation
node.js official site:
http://nodejs.org/download/
Url: https://github.com/joyent/node/wiki
/Installing-Node.js-via-package-manager
sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs=0.10.18-1chl1~precise1
On winodws, you can use node.js installer.
node.js can be used to build
Network applications.
HTTP Request
Using http.request(options, callback)
Otions: host, hostname, port, method, path etc
var options = {
hostname: 'www.google.co.in',
path: '/',
method: 'GET'
};
var req = http.request(options, function(res) {
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.end();
Example:
How to GET
?
Using http.get(options, callback)
Example:
http.get("http://www.google.com/index.html", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Simple http Server
http.createServer(function(request, response){ ... });
http.createServer([requestListener])
Returns a new web server object.
The requestListener is a function which is automatically
added to the 'request' event.
Class: http.Server
This is an EventEmitter with the following events:
Event: 'request'
function (request, response) { }
Emitted each time there is a request.
Alternate Syntax
var server = http.createServer();
server.on('request', function(request, response){ ... });
Event: 'close'
server.on('close', function(){ ... });
Simple server example...
node.js also has frameworks...
Express
Sinatra inspired web development framework
for Node.js
It is insanely fast, flexible, and simple.
Easy route URLs to callbacks
Environment based configuration
Middleware via connect – bodyParser, cookieparser etc
Install as:
npm install express
Or
sudo npm install -g express
REST url in Express
Let assumes there is 'user' resource.
// List
app.get('/users', function(req, res) {
});
// Create
app.post('/users', function(req, res) {
});
// Read
app.get('/users/:id', function(req, res) {
});
// Update
app.put('/users/:id', function(req, res) {
});
// Delete
app.del('/users/:id', function(req, res) {
});
Express simple example
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3000);
Express App
Simple express App
Express App
Simple express App
REST urls
Express App
Simple express App
REST urls
Organize your App
Express App
Simple express App
REST urls
Organize your App
Error handling using Error Handler
Middlewares
Express App
Simple express App
REST urls
Organize your App
Error handling using Error Handler
Middlewares
Logger
Express App
Simple express App
REST urls
Organize your App
Error handling using Error Handler
Middlewares
Logger
Template Engine - EJS
Express App
Simple express App
REST urls
Organize your App
Error handling using Error Handler
Middlewares
Logger
Template Engine – EJS
Adding Twitter Bootstrap
Express Middleware
Express Middleware
bodyParser():
Request body parsing middleware supporting
JSON,
urlencoded, and
multipart requests.
Usage:
app.use(express.bodyParser());
Express Middleware
cookieParser():
Parses the Cookie header field and populates
'req.cookies' with an object keyed by the
cookie names.
Usage:
app.use(express.cookieParser());
or
app.use(express.cookieParser('some secret'));
Express Middleware
errorHandler():
Development error handler, providing stack traces
and error message responses for requests
accepting text, html, or json.
Usage:
app.use(express.errorHandler());
Express Middleware
methodOverride():
To simulate DELETE and PUT.
Use when _method post parameter set to 'delete' or
'put'.
Usage:
app.use(express.methodOverride());
Client side code:
<form> ...
<input type="hidden" name="_method"
value="put" />
</form>
Express Middleware
session():
Setup session store with the given options.
Usage:
app.use(express.session());
Example:
app.use(express.cookieParser());
app.use(express.session({ secret: 'keyboard cat', key:
'sid', cookie: { secure: true }})
Express App Generation
Command to generate express app:
express --sessions --css stylus --ejs myapp
It generates an application with EJS, Stylus,
and session.
EJS: Embedded JavaScript template engine
- EJS cleans the HTML out of
your JavaScript with client side templates.
- Similar to ERB in ruby.
Express generation
Demo...
 Yahoo! : iPad App Livestand uses Yahoo! Manhattan
framework which is based on Node.js.
 LinkedIn : LinkedIn uses a combination of Node.js and
MongoDB for its mobile platform. iOS and Android apps
are based on it.
 eBay : Uses Node.js along with ql.io to help application
developers in improving eBay’s end user experience.
 Dow Jones : The WSJ Social front-end is written
completely in Node.js, using Express.js, and many other
modules.
Complete list can be found at:
https://github.com/joyent/node/wiki/Projects,-
Applications,-and-Companies-Using-Node
Who is using Node.js?
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications

Contenu connexe

Tendances

Create your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and PackerCreate your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and Packerfrastel
 
Multi-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and moreMulti-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and moreChef Software, Inc.
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginxroskakori
 
Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIDevoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIHendrik Ebbers
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with AnsibleAhmed AbouZaid
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)Soshi Nemoto
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonYurii Vasylenko
 
Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and GroovyKiyotaka Oku
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Hervé Vũ Roussel
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environmentSoshi Nemoto
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 
Site Testing with CasperJS
Site Testing with CasperJSSite Testing with CasperJS
Site Testing with CasperJSJoseph Scott
 
VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environmentVCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environmentTakayuki Miyauchi
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 

Tendances (20)

Create your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and PackerCreate your very own Development Environment with Vagrant and Packer
Create your very own Development Environment with Vagrant and Packer
 
Angular2 ecosystem
Angular2 ecosystemAngular2 ecosystem
Angular2 ecosystem
 
Multi-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and moreMulti-provider Vagrant and Chef: AWS, VMware, and more
Multi-provider Vagrant and Chef: AWS, VMware, and more
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginx
 
Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIDevoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
 
Node.js debugging
Node.js debuggingNode.js debugging
Node.js debugging
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
 
Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
 
Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS Superfast Automated Web Testing with CasperJS & PhantomJS
Superfast Automated Web Testing with CasperJS & PhantomJS
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environment
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 
Site Testing with CasperJS
Site Testing with CasperJSSite Testing with CasperJS
Site Testing with CasperJS
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
GlassFish Embedded API
GlassFish Embedded APIGlassFish Embedded API
GlassFish Embedded API
 
VCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environmentVCCW - Vagrant based WordPress development environment
VCCW - Vagrant based WordPress development environment
 
hacking with node.JS
hacking with node.JShacking with node.JS
hacking with node.JS
 
Node.js in a heterogeneous system
Node.js in a heterogeneous systemNode.js in a heterogeneous system
Node.js in a heterogeneous system
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 

En vedette

Small Art Promotion Update
Small Art Promotion Update Small Art Promotion Update
Small Art Promotion Update sdtwite
 
Slide presentation cream 30june2014-3
Slide presentation cream 30june2014-3Slide presentation cream 30june2014-3
Slide presentation cream 30june2014-3arnesjogren
 
Monolithic domes
Monolithic domesMonolithic domes
Monolithic domesRahul Bajaj
 
Khmer translation about lao pdr
Khmer translation about lao pdrKhmer translation about lao pdr
Khmer translation about lao pdrPheng Chandara
 
Tahapan Penelitian Tindakan Kelas
Tahapan Penelitian Tindakan KelasTahapan Penelitian Tindakan Kelas
Tahapan Penelitian Tindakan KelasSparisoma Viridi
 
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...Council of Manufacturing Associations
 
3.1.2.3 perindustrian di jepun pada abad ke 19 20
3.1.2.3 perindustrian di jepun  pada abad ke 19 203.1.2.3 perindustrian di jepun  pada abad ke 19 20
3.1.2.3 perindustrian di jepun pada abad ke 19 20Karsodikromo Yatiman
 
Рула Раим. Кейс "Охана"
Рула Раим. Кейс "Охана"Рула Раим. Кейс "Охана"
Рула Раим. Кейс "Охана"SocialMediaClubCA
 
pendidikan jasmani purba & renaisance
pendidikan jasmani purba & renaisancependidikan jasmani purba & renaisance
pendidikan jasmani purba & renaisanceIsmi Ishak
 
Workbook understanding and using eng grammar 4th edition
Workbook understanding and using eng grammar 4th editionWorkbook understanding and using eng grammar 4th edition
Workbook understanding and using eng grammar 4th editionNguyễn Hoàn
 
Ppt ucc article 9 update
Ppt   ucc article 9 updatePpt   ucc article 9 update
Ppt ucc article 9 updatemaggiecromley
 
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado Gloria María Ortiz Manotas
 
Hakaworks proposal russia jul13
Hakaworks proposal russia jul13Hakaworks proposal russia jul13
Hakaworks proposal russia jul13Kirill Ustinov
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project ManagementClaire Owen
 
Econemp 2-140305160859-phpapp02
Econemp 2-140305160859-phpapp02Econemp 2-140305160859-phpapp02
Econemp 2-140305160859-phpapp02jose bravo
 

En vedette (20)

Small Art Promotion Update
Small Art Promotion Update Small Art Promotion Update
Small Art Promotion Update
 
Social media book
Social media bookSocial media book
Social media book
 
Slide presentation cream 30june2014-3
Slide presentation cream 30june2014-3Slide presentation cream 30june2014-3
Slide presentation cream 30june2014-3
 
Monolithic domes
Monolithic domesMonolithic domes
Monolithic domes
 
Khmer translation about lao pdr
Khmer translation about lao pdrKhmer translation about lao pdr
Khmer translation about lao pdr
 
Photo project
Photo projectPhoto project
Photo project
 
Tahapan Penelitian Tindakan Kelas
Tahapan Penelitian Tindakan KelasTahapan Penelitian Tindakan Kelas
Tahapan Penelitian Tindakan Kelas
 
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...
CMA Webinar - Countdown to the 2012 Elections and How Manufacturers Can Make ...
 
3.1.2.3 perindustrian di jepun pada abad ke 19 20
3.1.2.3 perindustrian di jepun  pada abad ke 19 203.1.2.3 perindustrian di jepun  pada abad ke 19 20
3.1.2.3 perindustrian di jepun pada abad ke 19 20
 
Cover letter
Cover letterCover letter
Cover letter
 
Рула Раим. Кейс "Охана"
Рула Раим. Кейс "Охана"Рула Раим. Кейс "Охана"
Рула Раим. Кейс "Охана"
 
pendidikan jasmani purba & renaisance
pendidikan jasmani purba & renaisancependidikan jasmani purba & renaisance
pendidikan jasmani purba & renaisance
 
Workbook understanding and using eng grammar 4th edition
Workbook understanding and using eng grammar 4th editionWorkbook understanding and using eng grammar 4th edition
Workbook understanding and using eng grammar 4th edition
 
CMA2013WLC Sponsor PRG
CMA2013WLC Sponsor PRGCMA2013WLC Sponsor PRG
CMA2013WLC Sponsor PRG
 
Ppt ucc article 9 update
Ppt   ucc article 9 updatePpt   ucc article 9 update
Ppt ucc article 9 update
 
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado
Putas Educativas Básicas y de Apoyo en el Estudio Primer Grado
 
Hakaworks proposal russia jul13
Hakaworks proposal russia jul13Hakaworks proposal russia jul13
Hakaworks proposal russia jul13
 
Software Project Management
Software Project ManagementSoftware Project Management
Software Project Management
 
Econemp 2-140305160859-phpapp02
Econemp 2-140305160859-phpapp02Econemp 2-140305160859-phpapp02
Econemp 2-140305160859-phpapp02
 
"Going Mobile - Not the 'WHO', the How"
"Going Mobile - Not the 'WHO', the How""Going Mobile - Not the 'WHO', the How"
"Going Mobile - Not the 'WHO', the How"
 

Similaire à Nodejs Intro - Part2 Introduction to Web Applications

Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material designSrinadh Kanugala
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.jsAyush Mishra
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyUlrich Krause
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
GWT training session 1
GWT training session 1GWT training session 1
GWT training session 1SNEHAL MASNE
 
WP REST API - Building a simple Web Application
WP REST API - Building a simple Web ApplicationWP REST API - Building a simple Web Application
WP REST API - Building a simple Web ApplicationEdmund Chan
 
Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Andrew Rota
 
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...MUG-Lyon Microsoft User Group
 
Playing with php_on_azure
Playing with php_on_azurePlaying with php_on_azure
Playing with php_on_azureCEDRIC DERUE
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetesBen Hall
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 
Running Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic BeanstalkRunning Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic BeanstalkAmazon Web Services
 

Similaire à Nodejs Intro - Part2 Introduction to Web Applications (20)

Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material design
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Nodejs
NodejsNodejs
Nodejs
 
GWT training session 1
GWT training session 1GWT training session 1
GWT training session 1
 
WP REST API - Building a simple Web Application
WP REST API - Building a simple Web ApplicationWP REST API - Building a simple Web Application
WP REST API - Building a simple Web Application
 
Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019
 
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (spon...
 
Playing with php_on_azure
Playing with php_on_azurePlaying with php_on_azure
Playing with php_on_azure
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 
Proposal
ProposalProposal
Proposal
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Running Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic BeanstalkRunning Microservices on AWS Elastic Beanstalk
Running Microservices on AWS Elastic Beanstalk
 

Dernier

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Dernier (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Nodejs Intro - Part2 Introduction to Web Applications

  • 1. Introduction to Web Applications Budhram Gurung By - Code used for this session can be found : https://github.com/budh-ram/express_demo_app
  • 3. Background node.js runs on V8. It is a set of bindings to the V8 JavaScript VM. V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser. Latest version is v0.10.18 Is Open Source. It runs well on Linux/Unix systems, can also run on Windows systems.
  • 4. Installation node.js official site: http://nodejs.org/download/ Url: https://github.com/joyent/node/wiki /Installing-Node.js-via-package-manager sudo apt-get update sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs=0.10.18-1chl1~precise1 On winodws, you can use node.js installer.
  • 5. node.js can be used to build Network applications.
  • 6. HTTP Request Using http.request(options, callback) Otions: host, hostname, port, method, path etc var options = { hostname: 'www.google.co.in', path: '/', method: 'GET' }; var req = http.request(options, function(res) { res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); req.end(); Example:
  • 7. How to GET ? Using http.get(options, callback) Example: http.get("http://www.google.com/index.html", function(res) { console.log("Got response: " + res.statusCode); }).on('error', function(e) { console.log("Got error: " + e.message); });
  • 8. Simple http Server http.createServer(function(request, response){ ... }); http.createServer([requestListener]) Returns a new web server object. The requestListener is a function which is automatically added to the 'request' event. Class: http.Server This is an EventEmitter with the following events: Event: 'request' function (request, response) { } Emitted each time there is a request.
  • 9. Alternate Syntax var server = http.createServer(); server.on('request', function(request, response){ ... }); Event: 'close' server.on('close', function(){ ... });
  • 11. node.js also has frameworks...
  • 12. Express Sinatra inspired web development framework for Node.js It is insanely fast, flexible, and simple. Easy route URLs to callbacks Environment based configuration Middleware via connect – bodyParser, cookieparser etc Install as: npm install express Or sudo npm install -g express
  • 13. REST url in Express Let assumes there is 'user' resource. // List app.get('/users', function(req, res) { }); // Create app.post('/users', function(req, res) { }); // Read app.get('/users/:id', function(req, res) { }); // Update app.put('/users/:id', function(req, res) { }); // Delete app.del('/users/:id', function(req, res) { });
  • 14. Express simple example var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('hello world'); }); app.listen(3000);
  • 16. Express App Simple express App REST urls
  • 17. Express App Simple express App REST urls Organize your App
  • 18. Express App Simple express App REST urls Organize your App Error handling using Error Handler Middlewares
  • 19. Express App Simple express App REST urls Organize your App Error handling using Error Handler Middlewares Logger
  • 20. Express App Simple express App REST urls Organize your App Error handling using Error Handler Middlewares Logger Template Engine - EJS
  • 21. Express App Simple express App REST urls Organize your App Error handling using Error Handler Middlewares Logger Template Engine – EJS Adding Twitter Bootstrap
  • 23. Express Middleware bodyParser(): Request body parsing middleware supporting JSON, urlencoded, and multipart requests. Usage: app.use(express.bodyParser());
  • 24. Express Middleware cookieParser(): Parses the Cookie header field and populates 'req.cookies' with an object keyed by the cookie names. Usage: app.use(express.cookieParser()); or app.use(express.cookieParser('some secret'));
  • 25. Express Middleware errorHandler(): Development error handler, providing stack traces and error message responses for requests accepting text, html, or json. Usage: app.use(express.errorHandler());
  • 26. Express Middleware methodOverride(): To simulate DELETE and PUT. Use when _method post parameter set to 'delete' or 'put'. Usage: app.use(express.methodOverride()); Client side code: <form> ... <input type="hidden" name="_method" value="put" /> </form>
  • 27. Express Middleware session(): Setup session store with the given options. Usage: app.use(express.session()); Example: app.use(express.cookieParser()); app.use(express.session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }})
  • 28. Express App Generation Command to generate express app: express --sessions --css stylus --ejs myapp It generates an application with EJS, Stylus, and session. EJS: Embedded JavaScript template engine - EJS cleans the HTML out of your JavaScript with client side templates. - Similar to ERB in ruby.
  • 30.  Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js.  LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it.  eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience.  Dow Jones : The WSJ Social front-end is written completely in Node.js, using Express.js, and many other modules. Complete list can be found at: https://github.com/joyent/node/wiki/Projects,- Applications,-and-Companies-Using-Node Who is using Node.js?