SlideShare une entreprise Scribd logo
1  sur  19
© 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!

Contenu connexe

Tendances

React Native - Getting Started
React Native - Getting StartedReact Native - Getting Started
React Native - Getting StartedTracy 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 SFAmazon Web Services
 
PSE - Epicor ERP & REST
PSE - Epicor ERP & RESTPSE - Epicor ERP & REST
PSE - Epicor ERP & RESTThierry 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 AppSyncAmazon 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 TitaniumAaron Saunders
 
AWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testingAWS serverless infrastructure - Integration testing
AWS serverless infrastructure - Integration testingAWS User Group Bengaluru
 
AWS DOs and DONTs
AWS DOs and DONTsAWS DOs and DONTs
AWS DOs and DONTsCasey 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.pdfAmazon 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 CycleApigee | Google Cloud
 
Serverless Spring - Sabby Anandan
Serverless Spring - Sabby AnandanServerless Spring - Sabby Anandan
Serverless Spring - Sabby AnandanVMware 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 weekRadu Vunvulea
 

Tendances (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
 

Similaire à 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 APIsCA Technologies
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and SlingLokesh BS
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and SlingLo Ki
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE studentsQuhan 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 YadavSri Ambati
 
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
 
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
 
Bangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiBangalore Cloud Foundry meetup - Mani
Bangalore Cloud Foundry meetup - ManiMani 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 AppDynamicsNima 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.pptxpythagorus143
 
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 Setupvmaximiuk
 
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 2014cornelia 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 GeodeJohn 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 GivingDeborah Schalm
 

Similaire à 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 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 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...
 
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
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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!