SlideShare a Scribd company logo
1 of 20
Objective
 What is Express JS?
 Express JS Installation
 Bootstrap Express in an application with Demo
 Configuration and standard settings
 Object of Express JS
 Routing in Express
 Request and Response Object in Express
 Render Views and Template Engine with Demo
 Middleware in Express
 Demo
What is Express JS?
Express.js is a Node js web application server
framework, which is specifically designed for
building single-page, multi-page, and hybrid web
applications.
Express is the backend part of something known
as the MEAN stack.
1) MongoDB
2) Express.js
3) Angular.js
4) Node.js
Continue
The Express.js framework makes it very easy
to develop an application which can be used to
handle multiple types of requests like the GET,
PUT, and POST and DELETE requests.
Express FrameWork help a developer to quickly
build web sites with a lower the learning
curve.
Installation
Install with NPM
npm install express
This command will create folder in
node_modules and install the latest stable
express module over there. if you want to specify
the version you can pass @versionnumnber.
To load express
var express = require(‘express’);
Usage
Express module is factory for applications
var app = express();
Applications have many methods for
configuring
-- are also functions that can be given to
standard node http and https modules
Invoke app.listen() method after configuring
- or give to http or https modules
app.listen(3000, function(req, res){
console.log('Express JS ready for port
3000');
});
Configuration
app.get() and app.set() methods to read and
write settings:
SYNTAX:
app.set(name, value)
Or
app.set('case sensitive routing', false);
Standard settings used by
Express(with defaults)
1. env – application mode(process.env.NODE_ENV || 'development'
app.engine('html', require('ejs').renderFile);
2. trust proxy – trust headers set by reverse proxies(false)
app.set('trust proxy', '192.168.102.84');
3.jsonp calllback name – query string param name (callback)
4. json replacer – callback for JSON stringification(null)
5. case sensitive routing - /foo and /FOO are different (true)
6.strict routing - /foo and /FOO are different (false)
7. view cache – cache compiled views (true when env is production)
8. view engine – default entension fo views(no default)
9. views – directory containing views (./views)
Object of Express
There are four main object of Express:
1. Application (app)
2 .Request (req)
3 .Response (res)
4 .Router ( express.Router)
Routing in Express
Routing refers to determining how an application responds
to a client request to a particular endpoint, which is a URI
(or path) and a specific HTTP request method (GET,
POST, and so on).
SYNTAX:
app.METHOD(PATH,HANDLER);
METHOD = GET/POST/PUT/DELETE etc
Routing Example
Routes are defined with URL pattern and callback
Functions
app.get('/login', function(req, res){
// render form
});
app.post('/login', function(req, res){
// verify credentials and issue cookie
});
Route Pattern
 Patterns can be strings or regular expressions
 Strings can contain param placeholders
app.get('/api/user/:id', function(req, res){
var userId = req.params.id;
//load user info and return JSON
});
Requests
Request objects expose details of HTTP requests:
req.params – route parameters in URL
 req.query – query string parameters
 req.get() - get header value
 req.cookies() - cookie object( requires middleware)
 req.body() - parsed body (requires middleware)
 req.is() - text content type of request body
 req.accepts() - content nagotiation for response
 req.url – URL that matched current route
 req.originalUrl – original url as sent by client
 req.protocol – http or https
 req.secure – true if protocol is https
 req.host – value in host header
 req.subdomains – subdomains of host
 req.path – path in URL
 req.xhr – true if requested with XMLHttpRequest
Responses
Many ways to respond to requests
 res.set() – set response headers
 res.cookie() and res.clearCookie() – modify response cookies
 res.redirect() - issue 301 or 302 redirect to URL
 red.send() - write status with string/Array/Object/Buffer
 res.json() - stringify JavaScript value
 res.jsonp() - send JavaScript value to callback function
 res.sendfile() - stream contents of file
 res.download() – stream file with content-disposition: attachment
 res.render() – render view with pluggable view engine
Template Engine
1. HTML
2. EJS – Embedded Javascript templates
SYNTAX:
npm install ejs
3. JADE – Template Engine
SYNTAX:
npm install jade
Middleware in Express
MiddleWare performs the process before sending the
request to the router. For Example, Authenticate before
executing admin panel pages.
You can transfer the control to the Next MiddleWare using
the next() function.
Types of MiddleWare:
1. Application level MiddleWare
2. Router level Middleware
3. Error handling Middleware
4. Built In MiddleWare
5. Third Party MiddleWare
Third Party MiddleWare:
In Express JS 4, Middleware is not part of core modules.
So you have to install all middleware when require
List of Third Party MiddleWare.
1. Express-session :
2. request.Object:
3. Body-parser:
SYNTAX:
npm install body-parser
Built In MiddleWare
app.use(express.static('./');
Application Middleware
You can have multiple application level MiddleWare.
Application level middleware is refers app on MiddleWare.
Express framework provides app.METHOD. Here is the list
of Methods:
1. app.get
2. app.post
3. app.put
Router Level MiddleWare
The Route MiddleWare is work as a separate component
in Express4.
Here in Route MiddleWare, express binds instance of
express.router object. This MiddleWare is mainly used for
configuring better routing.
Router Example
var express = require( 'express' );
var router = express.Router ();
router.use( function(req, res, next){
console.log( 'This is test routing');
next();
});
router.get( '/', function( req, res ){
res.send( 'This is GET Route' );
});
module . exports = router ;

More Related Content

What's hot

ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.jsEmanuele DelBono
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react jsdhanushkacnd
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Visual Engineering
 

What's hot (20)

Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Reactjs
Reactjs Reactjs
Reactjs
 
Sequelize
SequelizeSequelize
Sequelize
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
React js
React jsReact js
React js
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Intro to React
Intro to ReactIntro to React
Intro to React
 

Similar to Node.js Express Framework

Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with ExpressAaron Stannard
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
ExpressJS-Introduction.pdf
ExpressJS-Introduction.pdfExpressJS-Introduction.pdf
ExpressJS-Introduction.pdfBareen Shaikh
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express jsAhmed Assaf
 
Express: A Jump-Start
Express: A Jump-StartExpress: A Jump-Start
Express: A Jump-StartNaveen Pete
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.jsdavidchubbs
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
Express Generator.pdf
Express Generator.pdfExpress Generator.pdf
Express Generator.pdfBareen Shaikh
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 

Similar to Node.js Express Framework (20)

ExpressJS and REST API.pptx
ExpressJS and REST API.pptxExpressJS and REST API.pptx
ExpressJS and REST API.pptx
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Express.pdf
Express.pdfExpress.pdf
Express.pdf
 
ExpressJS-Introduction.pdf
ExpressJS-Introduction.pdfExpressJS-Introduction.pdf
ExpressJS-Introduction.pdf
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
Express: A Jump-Start
Express: A Jump-StartExpress: A Jump-Start
Express: A Jump-Start
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Express Generator.pdf
Express Generator.pdfExpress Generator.pdf
Express Generator.pdf
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Mean PPT
Mean PPTMean PPT
Mean PPT
 
23003468463PPT.pptx
23003468463PPT.pptx23003468463PPT.pptx
23003468463PPT.pptx
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
RequireJS
RequireJSRequireJS
RequireJS
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 

More from TheCreativedev Blog

Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event EmittersTheCreativedev Blog
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requireTheCreativedev Blog
 
Network Security Through FIREWALL
Network Security Through FIREWALLNetwork Security Through FIREWALL
Network Security Through FIREWALLTheCreativedev Blog
 
TO ADD NEW URL REWRITE RULE IN WORDPRESS
TO ADD NEW URL REWRITE RULE IN WORDPRESSTO ADD NEW URL REWRITE RULE IN WORDPRESS
TO ADD NEW URL REWRITE RULE IN WORDPRESSTheCreativedev Blog
 

More from TheCreativedev Blog (9)

Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Introduction to PHP Basics
Introduction to PHP BasicsIntroduction to PHP Basics
Introduction to PHP Basics
 
Canvas in html5
Canvas in html5Canvas in html5
Canvas in html5
 
Network Security Through FIREWALL
Network Security Through FIREWALLNetwork Security Through FIREWALL
Network Security Through FIREWALL
 
Post via e mail in word press
Post via e mail in word pressPost via e mail in word press
Post via e mail in word press
 
Post via e mail in WordPress
Post via e mail in WordPressPost via e mail in WordPress
Post via e mail in WordPress
 
TO ADD NEW URL REWRITE RULE IN WORDPRESS
TO ADD NEW URL REWRITE RULE IN WORDPRESSTO ADD NEW URL REWRITE RULE IN WORDPRESS
TO ADD NEW URL REWRITE RULE IN WORDPRESS
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

Node.js Express Framework

  • 1. Objective  What is Express JS?  Express JS Installation  Bootstrap Express in an application with Demo  Configuration and standard settings  Object of Express JS  Routing in Express  Request and Response Object in Express  Render Views and Template Engine with Demo  Middleware in Express  Demo
  • 2. What is Express JS? Express.js is a Node js web application server framework, which is specifically designed for building single-page, multi-page, and hybrid web applications. Express is the backend part of something known as the MEAN stack. 1) MongoDB 2) Express.js 3) Angular.js 4) Node.js
  • 3. Continue The Express.js framework makes it very easy to develop an application which can be used to handle multiple types of requests like the GET, PUT, and POST and DELETE requests. Express FrameWork help a developer to quickly build web sites with a lower the learning curve.
  • 4. Installation Install with NPM npm install express This command will create folder in node_modules and install the latest stable express module over there. if you want to specify the version you can pass @versionnumnber. To load express var express = require(‘express’);
  • 5. Usage Express module is factory for applications var app = express(); Applications have many methods for configuring -- are also functions that can be given to standard node http and https modules Invoke app.listen() method after configuring - or give to http or https modules app.listen(3000, function(req, res){ console.log('Express JS ready for port 3000'); });
  • 6. Configuration app.get() and app.set() methods to read and write settings: SYNTAX: app.set(name, value) Or app.set('case sensitive routing', false);
  • 7. Standard settings used by Express(with defaults) 1. env – application mode(process.env.NODE_ENV || 'development' app.engine('html', require('ejs').renderFile); 2. trust proxy – trust headers set by reverse proxies(false) app.set('trust proxy', '192.168.102.84'); 3.jsonp calllback name – query string param name (callback) 4. json replacer – callback for JSON stringification(null) 5. case sensitive routing - /foo and /FOO are different (true) 6.strict routing - /foo and /FOO are different (false) 7. view cache – cache compiled views (true when env is production) 8. view engine – default entension fo views(no default) 9. views – directory containing views (./views)
  • 8. Object of Express There are four main object of Express: 1. Application (app) 2 .Request (req) 3 .Response (res) 4 .Router ( express.Router)
  • 9. Routing in Express Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on). SYNTAX: app.METHOD(PATH,HANDLER); METHOD = GET/POST/PUT/DELETE etc
  • 10. Routing Example Routes are defined with URL pattern and callback Functions app.get('/login', function(req, res){ // render form }); app.post('/login', function(req, res){ // verify credentials and issue cookie });
  • 11. Route Pattern  Patterns can be strings or regular expressions  Strings can contain param placeholders app.get('/api/user/:id', function(req, res){ var userId = req.params.id; //load user info and return JSON });
  • 12. Requests Request objects expose details of HTTP requests: req.params – route parameters in URL  req.query – query string parameters  req.get() - get header value  req.cookies() - cookie object( requires middleware)  req.body() - parsed body (requires middleware)  req.is() - text content type of request body  req.accepts() - content nagotiation for response  req.url – URL that matched current route  req.originalUrl – original url as sent by client  req.protocol – http or https  req.secure – true if protocol is https  req.host – value in host header  req.subdomains – subdomains of host  req.path – path in URL  req.xhr – true if requested with XMLHttpRequest
  • 13. Responses Many ways to respond to requests  res.set() – set response headers  res.cookie() and res.clearCookie() – modify response cookies  res.redirect() - issue 301 or 302 redirect to URL  red.send() - write status with string/Array/Object/Buffer  res.json() - stringify JavaScript value  res.jsonp() - send JavaScript value to callback function  res.sendfile() - stream contents of file  res.download() – stream file with content-disposition: attachment  res.render() – render view with pluggable view engine
  • 14. Template Engine 1. HTML 2. EJS – Embedded Javascript templates SYNTAX: npm install ejs 3. JADE – Template Engine SYNTAX: npm install jade
  • 15. Middleware in Express MiddleWare performs the process before sending the request to the router. For Example, Authenticate before executing admin panel pages. You can transfer the control to the Next MiddleWare using the next() function. Types of MiddleWare: 1. Application level MiddleWare 2. Router level Middleware 3. Error handling Middleware 4. Built In MiddleWare 5. Third Party MiddleWare
  • 16. Third Party MiddleWare: In Express JS 4, Middleware is not part of core modules. So you have to install all middleware when require List of Third Party MiddleWare. 1. Express-session : 2. request.Object: 3. Body-parser: SYNTAX: npm install body-parser
  • 18. Application Middleware You can have multiple application level MiddleWare. Application level middleware is refers app on MiddleWare. Express framework provides app.METHOD. Here is the list of Methods: 1. app.get 2. app.post 3. app.put
  • 19. Router Level MiddleWare The Route MiddleWare is work as a separate component in Express4. Here in Route MiddleWare, express binds instance of express.router object. This MiddleWare is mainly used for configuring better routing.
  • 20. Router Example var express = require( 'express' ); var router = express.Router (); router.use( function(req, res, next){ console.log( 'This is test routing'); next(); }); router.get( '/', function( req, res ){ res.send( 'This is GET Route' ); }); module . exports = router ;