SlideShare a Scribd company logo
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Express.js labs
Aeshan Wijetunge
06/ 11 / 2015 ITE
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 2
Middleware
A function with access to the request object, the response object, and the next
middleware in line in the request-response cycle of an application.
Middleware
Middleware
Application
Request Response
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 3
MVC : Model-View-Controller
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4
Views: Picking a template engine
There are dozens of template engines available online…. But we’ll
settle on
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5
DustJS : adding a template engine
Be sure to read-up on their awesome documentation when using dust.js
http://akdubya.github.io/dustjs/#guide
We’ll be adding dust-support using the adaro node-module. Installing it is as
easy as running...
npm install adaro --save
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6
Update app.js with the dust view-engine
app.engine('dust', adaro.dust());
app.set('view engine', 'dust');
app.set('views', __dirname +'/public/views' );
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 7
Update app.js with a route
app.get('/home',function(req, res) {
req.model = {};
req.model.name = 'ITE';
res.render('index',req.model);
});
This renders a dust-template located :
/views/index.dust
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8
Our 1st dust template
Save it under /public/views/index.dust
Let's get it running :
node --debug app.js
Visit your VM
aeshanw.koding.io:6001/home
<html>
<body>
<div>Hello {name}!</div>
</body>
</html>
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 9
Dustjs: under the hood
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10
Challenge : A Weather App
We’re going to use a weather-api to fetch the latest updates for some cities of
our choice.
With a bit of googling we find a site with some open APIs (not requiring API
secret keys etc) which is great for our example
http://openweathermap.org/current
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11
Mashups : Using APIs
We want to use this API to fetch the latest singapore weather details:
http://api.openweathermap.org/data/2.5/weather?q=Singapore
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12
Weather API : the raw data
We used an online tool to make the API response
readable..
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13
Request: the API client
npm install request --save
Googling for API clients will uncover many though we’ll be using
the request module to consume our weather API.
request('http://api.openweathermap.org/data/2.5/weather?q=Si
ngapore', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Weather Data for Singapore
}
})
Hitting your koding.io url should populate the console.log in your
koding terminal.
http://aeshanw.koding.io:6001/weather
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 14
Populate the view model
To display on the dust template let’s add the following to the app.js
app.get('/weather', function(req, res){
……..
//Populate the view model used to display
req.model = {};
req.model.temp = Math.floor(result.main.temp/10.0),
req.model.country = result.name,
req.model.weather = result.weather;
……...
res.render('weather',req.model);
}
});
});
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 15
View : Presenting the data
With a better understanding of the API’s data response we can
modify our dust template to render it in a more presentable form
to the user.
In public/views/weather.dust
<html>
<body>
<h1>Weather for {country}</h1>
{#weather}
<ul>
<li>{main}</li>
<li>{description}</li>
</ul>
{/weather}
</body>
</html>
/app.js
req.model.country = result.name,
req.model.wind = result.wind,
req.model.weather = result.weather;
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 16
The Finished Result
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 17
Try it yourself
The complete code for the lab is in the github repo:
https://github.com/node-workshop-ite/express-
weather-lab
git clone https://github.com/node-workshop-
ite/express-weather-lab.git
cd express-weather-lab
npm install
npm start
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 18
Troubleshooting ports
Some networks block ports aggressively. So if you
encounter such issues you may need to use
Modify this code in app.js to use port 80.
app.listen(600180, function() {
sudo service apache2 stop
sudo node app.js
visit aeshanw.koding.io/weather
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 19
Conclusion
● Use frameworks like Express to organize your development
● Add features using node modules via npm
● Extend your web app functionality via external APIs
If you liked ExpressJS, and desire more features we strongly suggest
you try Kraken.js. It originated from PayPal and has more advanced
features for more scalable web apps.
http://krakenjs.com/
Thank you & Happy Hacking!

More Related Content

What's hot

React Native - Getting Started
React Native - Getting StartedReact Native - Getting Started
React Native - Getting Started
Tracy Lee
 
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SF
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SFHands-On Lab: Break a Monolith Application into Microservices: Database Week SF
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SF
Amazon Web Services
 
PSE - Epicor ERP & REST
PSE - Epicor ERP & RESTPSE - Epicor ERP & REST
PSE - Epicor ERP & REST
Thierry Cools
 
Building Native Android Apps Using AWS Amplify CLI & AWS AppSync
Building Native Android Apps Using AWS Amplify CLI & AWS AppSyncBuilding Native Android Apps Using AWS Amplify CLI & AWS AppSync
Building Native Android Apps Using AWS Amplify CLI & AWS AppSync
Amazon Web Services
 
Quick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator TitaniumQuick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator Titanium
Aaron Saunders
 
AWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testingAWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testing
AWS User Group Bengaluru
 
AWS DOs and DONTs
AWS DOs and DONTsAWS DOs and DONTs
AWS DOs and DONTs
Casey Lee
 
Nader Dabit - Intro to AWS AppSync.pdf
Nader Dabit - Intro to AWS AppSync.pdfNader Dabit - Intro to AWS AppSync.pdf
Nader Dabit - Intro to AWS AppSync.pdf
Amazon Web Services
 
I Love APIs 2015: Continuous Integration the Virtuous Cycle
I Love APIs 2015: Continuous Integration the Virtuous CycleI Love APIs 2015: Continuous Integration the Virtuous Cycle
I Love APIs 2015: Continuous Integration the Virtuous Cycle
Apigee | Google Cloud
 
Serverless Spring - Sabby Anandan
Serverless Spring - Sabby AnandanServerless Spring - Sabby Anandan
Serverless Spring - Sabby Anandan
VMware Tanzu
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
Edureka!
 
The monster under the bed - overengineering the cloud 2020 am week
The monster under the bed - overengineering the cloud 2020 am weekThe monster under the bed - overengineering the cloud 2020 am week
The monster under the bed - overengineering the cloud 2020 am week
Radu Vunvulea
 

What's hot (12)

React Native - Getting Started
React Native - Getting StartedReact Native - Getting Started
React Native - Getting Started
 
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SF
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SFHands-On Lab: Break a Monolith Application into Microservices: Database Week SF
Hands-On Lab: Break a Monolith Application into Microservices: Database Week SF
 
PSE - Epicor ERP & REST
PSE - Epicor ERP & RESTPSE - Epicor ERP & REST
PSE - Epicor ERP & REST
 
Building Native Android Apps Using AWS Amplify CLI & AWS AppSync
Building Native Android Apps Using AWS Amplify CLI & AWS AppSyncBuilding Native Android Apps Using AWS Amplify CLI & AWS AppSync
Building Native Android Apps Using AWS Amplify CLI & AWS AppSync
 
Quick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator TitaniumQuick Way to work with Models and Alloy in Appcelerator Titanium
Quick Way to work with Models and Alloy in Appcelerator Titanium
 
AWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testingAWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testing
 
AWS DOs and DONTs
AWS DOs and DONTsAWS DOs and DONTs
AWS DOs and DONTs
 
Nader Dabit - Intro to AWS AppSync.pdf
Nader Dabit - Intro to AWS AppSync.pdfNader Dabit - Intro to AWS AppSync.pdf
Nader Dabit - Intro to AWS AppSync.pdf
 
I Love APIs 2015: Continuous Integration the Virtuous Cycle
I Love APIs 2015: Continuous Integration the Virtuous CycleI Love APIs 2015: Continuous Integration the Virtuous Cycle
I Love APIs 2015: Continuous Integration the Virtuous Cycle
 
Serverless Spring - Sabby Anandan
Serverless Spring - Sabby AnandanServerless Spring - Sabby Anandan
Serverless Spring - Sabby Anandan
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
 
The monster under the bed - overengineering the cloud 2020 am week
The monster under the bed - overengineering the cloud 2020 am weekThe monster under the bed - overengineering the cloud 2020 am week
The monster under the bed - overengineering the cloud 2020 am week
 

Similar to Ite express labs

Hands-On Lab: Using CA Mobile Application Analytics REST APIs
Hands-On Lab: Using CA Mobile Application Analytics REST APIsHands-On Lab: Using CA Mobile Application Analytics REST APIs
Hands-On Lab: Using CA Mobile Application Analytics REST APIs
CA Technologies
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
Lokesh BS
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
Lo Ki
 
Oracle mcs overview 1029
Oracle mcs overview 1029Oracle mcs overview 1029
Oracle mcs overview 1029
Oracle Corporation
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
Quhan Arunasalam
 
H2O World - Self Guiding Applications with Venkatesh Yadav
H2O World - Self Guiding Applications with Venkatesh YadavH2O World - Self Guiding Applications with Venkatesh Yadav
H2O World - Self Guiding Applications with Venkatesh Yadav
Sri Ambati
 
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays
 
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
apidays
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
Quhan Arunasalam
 
Bangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiBangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - Mani
Mani Chandrasekaran
 
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamicsMonitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Nima Badiey
 
Azure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptxAzure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptx
pythagorus143
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
Aeshan Wijetunge
 
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure SetupSharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
vmaximiuk
 
Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014
cornelia davis
 
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
PROIDEA
 
Getting Started with Apache Geode
Getting Started with Apache GeodeGetting Started with Apache Geode
Getting Started with Apache Geode
John Blum
 
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
CA Technologies
 
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
Amazon Web Services
 
Application Discovery! The Gift That Keeps on Giving
Application Discovery! The Gift That Keeps on GivingApplication Discovery! The Gift That Keeps on Giving
Application Discovery! The Gift That Keeps on Giving
Deborah Schalm
 

Similar to Ite express labs (20)

Hands-On Lab: Using CA Mobile Application Analytics REST APIs
Hands-On Lab: Using CA Mobile Application Analytics REST APIsHands-On Lab: Using CA Mobile Application Analytics REST APIs
Hands-On Lab: Using CA Mobile Application Analytics REST APIs
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
 
Oracle mcs overview 1029
Oracle mcs overview 1029Oracle mcs overview 1029
Oracle mcs overview 1029
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
 
H2O World - Self Guiding Applications with Venkatesh Yadav
H2O World - Self Guiding Applications with Venkatesh YadavH2O World - Self Guiding Applications with Venkatesh Yadav
H2O World - Self Guiding Applications with Venkatesh Yadav
 
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
 
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
Bangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiBangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - Mani
 
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamicsMonitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
Monitoring Cloud Native Apps on Pivotal Cloud Foundry with AppDynamics
 
Azure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptxAzure APIM Presentation to understand about.pptx
Azure APIM Presentation to understand about.pptx
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
 
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure SetupSharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
SharePoint 2013 Hosted-Apps (On-Premises) - Infrastructure Setup
 
Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014Running your Spring Apps in the Cloud Javaone 2014
Running your Spring Apps in the Cloud Javaone 2014
 
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
PLNOG15: The Power of the Open Standards SDN API’s - Mikael Holmberg
 
Getting Started with Apache Geode
Getting Started with Apache GeodeGetting Started with Apache Geode
Getting Started with Apache Geode
 
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
Hands-On Lab: Increase Velocity with the CA Performance Management OpenAPI ...
 
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
Build secure, offline, real-time-enabled mobile apps - MAD304 - Atlanta AWS S...
 
Application Discovery! The Gift That Keeps on Giving
Application Discovery! The Gift That Keeps on GivingApplication Discovery! The Gift That Keeps on Giving
Application Discovery! The Gift That Keeps on Giving
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

Ite express labs

  • 1. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Express.js labs Aeshan Wijetunge 06/ 11 / 2015 ITE
  • 2. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 2 Middleware A function with access to the request object, the response object, and the next middleware in line in the request-response cycle of an application. Middleware Middleware Application Request Response
  • 3. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 3 MVC : Model-View-Controller
  • 4. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4 Views: Picking a template engine There are dozens of template engines available online…. But we’ll settle on
  • 5. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5 DustJS : adding a template engine Be sure to read-up on their awesome documentation when using dust.js http://akdubya.github.io/dustjs/#guide We’ll be adding dust-support using the adaro node-module. Installing it is as easy as running... npm install adaro --save
  • 6. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6 Update app.js with the dust view-engine app.engine('dust', adaro.dust()); app.set('view engine', 'dust'); app.set('views', __dirname +'/public/views' );
  • 7. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 7 Update app.js with a route app.get('/home',function(req, res) { req.model = {}; req.model.name = 'ITE'; res.render('index',req.model); }); This renders a dust-template located : /views/index.dust
  • 8. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8 Our 1st dust template Save it under /public/views/index.dust Let's get it running : node --debug app.js Visit your VM aeshanw.koding.io:6001/home <html> <body> <div>Hello {name}!</div> </body> </html>
  • 9. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 9 Dustjs: under the hood
  • 10. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10 Challenge : A Weather App We’re going to use a weather-api to fetch the latest updates for some cities of our choice. With a bit of googling we find a site with some open APIs (not requiring API secret keys etc) which is great for our example http://openweathermap.org/current
  • 11. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11 Mashups : Using APIs We want to use this API to fetch the latest singapore weather details: http://api.openweathermap.org/data/2.5/weather?q=Singapore
  • 12. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12 Weather API : the raw data We used an online tool to make the API response readable..
  • 13. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13 Request: the API client npm install request --save Googling for API clients will uncover many though we’ll be using the request module to consume our weather API. request('http://api.openweathermap.org/data/2.5/weather?q=Si ngapore', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) // Weather Data for Singapore } }) Hitting your koding.io url should populate the console.log in your koding terminal. http://aeshanw.koding.io:6001/weather
  • 14. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 14 Populate the view model To display on the dust template let’s add the following to the app.js app.get('/weather', function(req, res){ …….. //Populate the view model used to display req.model = {}; req.model.temp = Math.floor(result.main.temp/10.0), req.model.country = result.name, req.model.weather = result.weather; ……... res.render('weather',req.model); } }); });
  • 15. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 15 View : Presenting the data With a better understanding of the API’s data response we can modify our dust template to render it in a more presentable form to the user. In public/views/weather.dust <html> <body> <h1>Weather for {country}</h1> {#weather} <ul> <li>{main}</li> <li>{description}</li> </ul> {/weather} </body> </html> /app.js req.model.country = result.name, req.model.wind = result.wind, req.model.weather = result.weather;
  • 16. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 16 The Finished Result
  • 17. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 17 Try it yourself The complete code for the lab is in the github repo: https://github.com/node-workshop-ite/express- weather-lab git clone https://github.com/node-workshop- ite/express-weather-lab.git cd express-weather-lab npm install npm start
  • 18. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 18 Troubleshooting ports Some networks block ports aggressively. So if you encounter such issues you may need to use Modify this code in app.js to use port 80. app.listen(600180, function() { sudo service apache2 stop sudo node app.js visit aeshanw.koding.io/weather
  • 19. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 19 Conclusion ● Use frameworks like Express to organize your development ● Add features using node modules via npm ● Extend your web app functionality via external APIs If you liked ExpressJS, and desire more features we strongly suggest you try Kraken.js. It originated from PayPal and has more advanced features for more scalable web apps. http://krakenjs.com/ Thank you & Happy Hacking!