SlideShare a Scribd company logo
1 of 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!

More Related Content

What's hot

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
 

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 APIsCA Technologies
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and SlingLo Ki
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and SlingLokesh BS
 
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 - Data with a Mission by Matt McLarty
apidays LIVE Australia -  Data with a Mission by Matt McLarty apidays LIVE Australia -  Data with a Mission by Matt McLarty
apidays LIVE Australia - 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
 

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 Australia - Data with a Mission by Matt McLarty
apidays LIVE Australia -  Data with a Mission by Matt McLarty apidays LIVE Australia -  Data with a Mission by Matt McLarty
apidays LIVE Australia - 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
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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!