SlideShare a Scribd company logo
1 of 19
ExpressJS
Web development with ExpressJS
Learning & Development
Table of Contents
1. Connect for NodeJS
2. ExpressJS
3. Views and layout
4. Working with Data
5. Common and Advanced Scenarios
2
node.js
• Event-Driven, Asynchronous IO, Server-Side JavaScript library in C
• Open Source
• Available on
• Windows
• Service
• Under IIS (iisnode)
• *nix systems
• As a service
• Azure
• Heroku
3
NodeJS Web Server
• Basic server implementation
4
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
}); //return success header
res.write('My server is running! ^_^'); //response
res.end(); //finish processing current request
}).listen(1234);
Connect for NodeJS
• Connect is a middleware framework for node
• Built on top of node’s Http Server
• http://www.senchalabs.org/connect/
5
var connect = require('connect');
var app = connect()
.use(connect.logger('dev'))
.use(connect.static('public'))
.use(function(req, res){
res.end('hello worldn');
})
http.createServer(app).listen(3000);
$ npm install connect
Connect Middleware
• Request Processing Pipeline
6
ResponseRequest
Middleware (logging, authentication, etc.)
Connect for NodeJS – Example
• Custom middleware function for connect
7
var connect = require('connect'),
util = require('util');
var interceptorFunction = function(request, response, next) {
console.log(util.format('Request for %s with method %s',
request.url, request.method));
next();
};
var app = connect()
// .use('/log', interceptorFunction)
.use(interceptorFunction)
.use(function onRequest(request, response) {
response.end('Hello from Connect!');
}).listen(3001);
Express.js
• Adds functionality to Connect
• Built on top of Connect Middleware
• Request / Response enhancements
• Routing
• View Support
• HTML Helpers
• Content Negotiation
• Exposes Connect Middleware
8
Basic Architecture
9
Request
View
File
XML
JSON
etc. Function
Routing
First Express App
10
var express = require('express');
var app = express();
app.get('/', function (request, response) {
response.send('Welcome to Express!');
});
app.get('/customer/:id', function (req, res) {
res.send('Customer requested is ' + req.params['id']);
});
app.listen(3000);
Demo: Creating Express
Applications
• Simple ExpressJS application and "nodemon"
• Create routes and require() them
• Pass parameters
• Configure and middleware
Views in ExpressJS
• User Interface
• Based on Templates
• Support for multiple View Engines
• Jade, EJS, JSHtml, . . .
• Default is Jade
• http://jade-lang.com
12
app.get('/', function (req, res) {
res.render('index');
});
Views in ExpressJS – Example
13
var express = require('express'),
path = require('path');
var app = express();
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
});
app.get('/', function (req, res) {
res.render('empty');
});
app.listen(3000);
doctype
html(lang="en")
head
title Welcome to this emtpy page
body
Demo: Views in ExpressJS
• Show simple views in ExpressJS
• Jade syntax examples
• Layouts and blocks
• Stylus
Working with Data
• Pass data to the views
• Read data from the views (bodyParser)
• Read and send files
• Data for all views
15
res.render('index', { title: 'Customer List' });
res.render('index', { title: 'Customer List' });
var filePath = req.files.picture.path;
// ...
res.download(filePath);
res.sendfile(filePath);
app.locals.clock = { datetime: new Date().toUTCString()};
Demo: Working with data
• Pass data to views (customer.index)
• Submit data from views (customer.create)
• Content negotiation (customer.details)
• Upload files (customer.create)
• Helpers (app.locals)
Demo: Advanced Scenarios
• Cookies
• Sessions
• Custom middleware
• Authentication and authorization
17
Next Steps
• Express.js Samples
• https://github.com/visionmedia/express
• Database Support
• MS SQL
• CouchDB
• PostgreSQL
• Redis
• Socket.io
• Real-time support
18
Next Steps (2)
• Search on npm.org before you re-invent the wheel
• Express is Lightweight Framework and Fast to work with
• Testing is not optional
• Mocha
• JavaScript can get messy
19

More Related Content

What's hot

Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITnamespaceit
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 

What's hot (20)

Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Expressjs
ExpressjsExpressjs
Expressjs
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Express JS
Express JSExpress JS
Express JS
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 

Viewers also liked

Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with ExpressAaron Stannard
 
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
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkEdureka!
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Expressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsExpressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsCaesar Chi
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Diving into Node with Express and Mongo
Diving into Node with Express and MongoDiving into Node with Express and Mongo
Diving into Node with Express and MongoAxilis
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sailsBrian Shannon
 
Chinese new year- Aoife & Sarah
Chinese new year- Aoife & SarahChinese new year- Aoife & Sarah
Chinese new year- Aoife & SarahMs Bergin
 
Jade & Javascript templating
Jade & Javascript templatingJade & Javascript templating
Jade & Javascript templatingwearefractal
 
Express js clean-controller
Express js clean-controllerExpress js clean-controller
Express js clean-controllerAsia Tyshchenko
 
The Business Case for Node.js
The Business Case for Node.jsThe Business Case for Node.js
The Business Case for Node.jsJoe McCann
 
Postroenie sechenij mnogogrannikov
Postroenie sechenij mnogogrannikovPostroenie sechenij mnogogrannikov
Postroenie sechenij mnogogrannikovDimon4
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypalLenny Markus
 
Вячеслав Бирюков - Как Linux работает с памятью
Вячеслав Бирюков - Как Linux работает с памятьюВячеслав Бирюков - Как Linux работает с памятью
Вячеслав Бирюков - Как Linux работает с памятьюYandex
 
Сечения призмы и пирамиды
Сечения призмы и пирамидыСечения призмы и пирамиды
Сечения призмы и пирамидыDmitry Bulgakov
 
Node-IL Meetup 12/2
Node-IL Meetup 12/2Node-IL Meetup 12/2
Node-IL Meetup 12/2Ynon Perek
 

Viewers also liked (20)

Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
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
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Expressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsExpressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.js
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Diving into Node with Express and Mongo
Diving into Node with Express and MongoDiving into Node with Express and Mongo
Diving into Node with Express and Mongo
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
Chinese new year- Aoife & Sarah
Chinese new year- Aoife & SarahChinese new year- Aoife & Sarah
Chinese new year- Aoife & Sarah
 
Jade & Javascript templating
Jade & Javascript templatingJade & Javascript templating
Jade & Javascript templating
 
Express js clean-controller
Express js clean-controllerExpress js clean-controller
Express js clean-controller
 
The Business Case for Node.js
The Business Case for Node.jsThe Business Case for Node.js
The Business Case for Node.js
 
Rest api with node js and express
Rest api with node js and expressRest api with node js and express
Rest api with node js and express
 
Postroenie sechenij mnogogrannikov
Postroenie sechenij mnogogrannikovPostroenie sechenij mnogogrannikov
Postroenie sechenij mnogogrannikov
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypal
 
Вячеслав Бирюков - Как Linux работает с памятью
Вячеслав Бирюков - Как Linux работает с памятьюВячеслав Бирюков - Как Linux работает с памятью
Вячеслав Бирюков - Как Linux работает с памятью
 
Express yourself
Express yourselfExpress yourself
Express yourself
 
React js
React jsReact js
React js
 
Сечения призмы и пирамиды
Сечения призмы и пирамидыСечения призмы и пирамиды
Сечения призмы и пирамиды
 
Node-IL Meetup 12/2
Node-IL Meetup 12/2Node-IL Meetup 12/2
Node-IL Meetup 12/2
 

Similar to Express js

nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first classFin Chen
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js PlatformNaresh Chintalcheru
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsOhad Kravchick
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.jsdavidchubbs
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
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 azureColin Mackay
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Node JS Core Module PowerPoint Presentation
Node JS Core Module PowerPoint PresentationNode JS Core Module PowerPoint Presentation
Node JS Core Module PowerPoint Presentationrajeshkannan750222
 

Similar to Express js (20)

nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Nodejs first class
Nodejs first classNodejs first class
Nodejs first class
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Node.js on Azure
Node.js on AzureNode.js on Azure
Node.js on Azure
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
NodeJS
NodeJSNodeJS
NodeJS
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Node.js Introduction
Node.js IntroductionNode.js Introduction
Node.js Introduction
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
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
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Node JS Core Module PowerPoint Presentation
Node JS Core Module PowerPoint PresentationNode JS Core Module PowerPoint Presentation
Node JS Core Module PowerPoint Presentation
 

More from Manav Prasad (20)

Experience with mulesoft
Experience with mulesoftExperience with mulesoft
Experience with mulesoft
 
Mulesoftconnectors
MulesoftconnectorsMulesoftconnectors
Mulesoftconnectors
 
Mule and web services
Mule and web servicesMule and web services
Mule and web services
 
Mulesoft cloudhub
Mulesoft cloudhubMulesoft cloudhub
Mulesoft cloudhub
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Jpa
JpaJpa
Jpa
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Json
Json Json
Json
 
The spring framework
The spring frameworkThe spring framework
The spring framework
 
Rest introduction
Rest introductionRest introduction
Rest introduction
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
Junit
JunitJunit
Junit
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Xpath
XpathXpath
Xpath
 
Xslt
XsltXslt
Xslt
 
Xhtml
XhtmlXhtml
Xhtml
 
Css
CssCss
Css
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
 
Ajax
AjaxAjax
Ajax
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 

Recently uploaded (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 

Express js

  • 1. ExpressJS Web development with ExpressJS Learning & Development
  • 2. Table of Contents 1. Connect for NodeJS 2. ExpressJS 3. Views and layout 4. Working with Data 5. Common and Advanced Scenarios 2
  • 3. node.js • Event-Driven, Asynchronous IO, Server-Side JavaScript library in C • Open Source • Available on • Windows • Service • Under IIS (iisnode) • *nix systems • As a service • Azure • Heroku 3
  • 4. NodeJS Web Server • Basic server implementation 4 var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); //return success header res.write('My server is running! ^_^'); //response res.end(); //finish processing current request }).listen(1234);
  • 5. Connect for NodeJS • Connect is a middleware framework for node • Built on top of node’s Http Server • http://www.senchalabs.org/connect/ 5 var connect = require('connect'); var app = connect() .use(connect.logger('dev')) .use(connect.static('public')) .use(function(req, res){ res.end('hello worldn'); }) http.createServer(app).listen(3000); $ npm install connect
  • 6. Connect Middleware • Request Processing Pipeline 6 ResponseRequest Middleware (logging, authentication, etc.)
  • 7. Connect for NodeJS – Example • Custom middleware function for connect 7 var connect = require('connect'), util = require('util'); var interceptorFunction = function(request, response, next) { console.log(util.format('Request for %s with method %s', request.url, request.method)); next(); }; var app = connect() // .use('/log', interceptorFunction) .use(interceptorFunction) .use(function onRequest(request, response) { response.end('Hello from Connect!'); }).listen(3001);
  • 8. Express.js • Adds functionality to Connect • Built on top of Connect Middleware • Request / Response enhancements • Routing • View Support • HTML Helpers • Content Negotiation • Exposes Connect Middleware 8
  • 10. First Express App 10 var express = require('express'); var app = express(); app.get('/', function (request, response) { response.send('Welcome to Express!'); }); app.get('/customer/:id', function (req, res) { res.send('Customer requested is ' + req.params['id']); }); app.listen(3000);
  • 11. Demo: Creating Express Applications • Simple ExpressJS application and "nodemon" • Create routes and require() them • Pass parameters • Configure and middleware
  • 12. Views in ExpressJS • User Interface • Based on Templates • Support for multiple View Engines • Jade, EJS, JSHtml, . . . • Default is Jade • http://jade-lang.com 12 app.get('/', function (req, res) { res.render('index'); });
  • 13. Views in ExpressJS – Example 13 var express = require('express'), path = require('path'); var app = express(); app.configure(function () { app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.static(path.join(__dirname, 'public'))); }); app.get('/', function (req, res) { res.render('empty'); }); app.listen(3000); doctype html(lang="en") head title Welcome to this emtpy page body
  • 14. Demo: Views in ExpressJS • Show simple views in ExpressJS • Jade syntax examples • Layouts and blocks • Stylus
  • 15. Working with Data • Pass data to the views • Read data from the views (bodyParser) • Read and send files • Data for all views 15 res.render('index', { title: 'Customer List' }); res.render('index', { title: 'Customer List' }); var filePath = req.files.picture.path; // ... res.download(filePath); res.sendfile(filePath); app.locals.clock = { datetime: new Date().toUTCString()};
  • 16. Demo: Working with data • Pass data to views (customer.index) • Submit data from views (customer.create) • Content negotiation (customer.details) • Upload files (customer.create) • Helpers (app.locals)
  • 17. Demo: Advanced Scenarios • Cookies • Sessions • Custom middleware • Authentication and authorization 17
  • 18. Next Steps • Express.js Samples • https://github.com/visionmedia/express • Database Support • MS SQL • CouchDB • PostgreSQL • Redis • Socket.io • Real-time support 18
  • 19. Next Steps (2) • Search on npm.org before you re-invent the wheel • Express is Lightweight Framework and Fast to work with • Testing is not optional • Mocha • JavaScript can get messy 19

Editor's Notes

  1. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*