SlideShare a Scribd company logo
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Express.js labs
Aeshan Wijetunge
06/ 3 / 2015 SST
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Why a Web Framework?
A framework provides the scaffolding for web developers aiming to build an
application in an organized manner.
Express is one of the most popular node.js frameworks and you might find it
handy in your hackathon for the following reasons:
● Lightweight
● Routing support
● Well documented
● Many modular features available (e.g: express-session)
● Very active user community with a great deal of online material
2
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 3
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
Applicatio
n
Request Response
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4
Views: adding a templating engine
Why a templating engine? Static HTML is very restrictive and as we’re
creating a web application we’ll need something more dynamic.
Template engines compile template written in one markup to HTML which is
rendered on the user’s browser.
There are many templating engine options that can be added to express.
● HAML
● jade
● dustJS
● handlebars
● …
For the sake of convenience, we’ll be using dust.js views in this example and
will be relying on a module created by PayPal as the template-engine for the
rendering of the page.
Be sure to read-up on their awesome documentation when using dust.js
http://akdubya.github.io/dustjs/#guide
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5
Views: adding a template engine
var options = {
helpers: [
//NOTE: function has to take dust as an argument.
//The following function defines @myHelper helper
function (dust) { dust.helpers.myHelper = function (a, b, c, d) {} },
'dustjs-helpers' //So do installed modules
]
};
app.engine('dust', adaro.dust(options));
app.set('view engine', 'dust');
app.set('views', __dirname + '/public/views');
npm install adaro --save
<html>
<body>
<div>Hello {name}!</div>
</body>
</html>
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6
Adding Features : module by module
A web-application that just serves HTML pages may not be all that useful.
Thankfully express is easily extensible thanks to npm.
As discussed earlier the node community has populated a massive variety of
modules on npm to suit almost any requirement you might come up with
during your hackathon.
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. 7
Mashups : Using APIs
When developing applications we’d not only want to reuse functionality via
npm modules. We’d also like to access external data which would make our
web apps even more useful.
Many companies & organizations expose their data to developers via APIs.
For our weather app consider this API call to fetch Singapore weather
http://api.openweathermap.org/data/2.5/weather?q=Singapore
You can view the JSON response in your browser.
Not all APIs are open. Other may require client secret keys but a good API
provider would document how to use their API.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8
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=Singapore'
, 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. 9
API Debugging
JSON can be a bit difficult to read at times so we rely on some online tools to better
understand the API response.
http://jsonformatter.curiousconcept.com/
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10
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.
<html>
<body>
<h1>Weather for {country}</h1>
{#weather}
<ul>
<li>{main}</li>
<li>{description}</li>
</ul>
{/weather}
</body>
</html>
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11
Try it yourself
The complete code for the lab is in the github repo:
https://github.com/node-workshop-sst/sst-weather-lab
$ cd ~/node
$ git clone https://github.com/node-workshop-sst/sst-weather-lab.git
$ cd sst-weather-lab
$ npm install
$ node app.js
SST blocks certain ports so we’ll need to override our koding ports
Modify this code in app.js to use port 80.
app.listen(appEnv.port80, function() {
$ sudo service apache2 stop
$ sudo node app.js
visit aeshanw.koding.io/weather
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12
Deploying to Bluemix
You’ll need to git add & commit all your code changes except the node_modules folder.
Then simply git push to your bluemix git repo to deploy the app to staging.
git push origin master
And you should see activity on your bluemix dashboard and once its deployed you can hit your
own url to view the result
http://sst-express-lab.eu-gb.mybluemix.net/weather
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13
Conclusion
● Use frameworks like Express to organize your development
● Add features using node modules via npm
● Extend your web app functionality via external APIs
● use web tools & console.log to better debug and better consume 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

PPTX
Ite express labs
PPTX
Apigee deploy grunt plugin.1.0
PDF
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
PDF
Beyond AngularJS: Best practices and more
PDF
I Love APIs 2015: Continuous Integration the Virtuous Cycle
PPTX
Building Creative Product Extensions with Experience Manager
PDF
Bootiful Development with Spring Boot and Angular - RWX 2018
PDF
Быстрый старт в gDrive API
Ite express labs
Apigee deploy grunt plugin.1.0
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Beyond AngularJS: Best practices and more
I Love APIs 2015: Continuous Integration the Virtuous Cycle
Building Creative Product Extensions with Experience Manager
Bootiful Development with Spring Boot and Angular - RWX 2018
Быстрый старт в gDrive API

What's hot (20)

PDF
Angular Dependency Injection
PDF
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
PPTX
Modern web app with REACT
PDF
Angular coding: from project management to web and mobile deploy
PDF
Microservices for the Masses with Spring Boot and JHipster - RWX 2018
PDF
Bootiful Development with Spring Boot and Vue - RWX 2018
DOCX
Angular2RoutingSetupByShubham
PDF
SocketIOSetupWithAngularJSAppByShubham
PDF
React Native - Getting Started
PDF
Corley cloud angular in cloud
PDF
Learn Angular 9/8 In Easy Steps
PPTX
Angular Ivy- An Overview
PPTX
Angular elements - embed your angular components EVERYWHERE
PDF
Quick Way to work with Models and Alloy in Appcelerator Titanium
PDF
Modern Web Applications with Sightly
PDF
Webpack and angularjs
PDF
Introduction to angular 4
PPTX
PDF
React native.key
PPTX
AEM and Sling
Angular Dependency Injection
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
Modern web app with REACT
Angular coding: from project management to web and mobile deploy
Microservices for the Masses with Spring Boot and JHipster - RWX 2018
Bootiful Development with Spring Boot and Vue - RWX 2018
Angular2RoutingSetupByShubham
SocketIOSetupWithAngularJSAppByShubham
React Native - Getting Started
Corley cloud angular in cloud
Learn Angular 9/8 In Easy Steps
Angular Ivy- An Overview
Angular elements - embed your angular components EVERYWHERE
Quick Way to work with Models and Alloy in Appcelerator Titanium
Modern Web Applications with Sightly
Webpack and angularjs
Introduction to angular 4
React native.key
AEM and Sling

Similar to Sst hackathon express (20)

PPTX
Node.js Web Apps @ ebay scale
PDF
KrakenJS
PPTX
Node.js primer
PDF
Kraken Front-Trends
PDF
Node.js Workshop
KEY
20120306 dublin js
PDF
Professional Node.js Development Services | Node.js Development Company
PPTX
Server side rendering review
PPTX
Node.js primer for ITE students
PPTX
Kraken
PDF
What is Node.js? (ICON UK)
PPT
Node and Azure
PPTX
StrongLoop Overview
PPT
Node js
PDF
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
PDF
Essential Node.js for Web Developers from Developer Week 2013
PPTX
Connect js nodejs_api_shubhra
PDF
Node.js BFFs - our way to the better/micro frontends
Node.js Web Apps @ ebay scale
KrakenJS
Node.js primer
Kraken Front-Trends
Node.js Workshop
20120306 dublin js
Professional Node.js Development Services | Node.js Development Company
Server side rendering review
Node.js primer for ITE students
Kraken
What is Node.js? (ICON UK)
Node and Azure
StrongLoop Overview
Node js
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
Essential Node.js for Web Developers from Developer Week 2013
Connect js nodejs_api_shubhra
Node.js BFFs - our way to the better/micro frontends

Recently uploaded (20)

PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Accuracy of neural networks in brain wave diagnosis of schizophrenia
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
OMC Textile Division Presentation 2021.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TLE Review Electricity (Electricity).pptx
A comparative analysis of optical character recognition models for extracting...
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Univ-Connecticut-ChatGPT-Presentaion.pdf
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm

Sst hackathon express

  • 1. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Express.js labs Aeshan Wijetunge 06/ 3 / 2015 SST
  • 2. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Why a Web Framework? A framework provides the scaffolding for web developers aiming to build an application in an organized manner. Express is one of the most popular node.js frameworks and you might find it handy in your hackathon for the following reasons: ● Lightweight ● Routing support ● Well documented ● Many modular features available (e.g: express-session) ● Very active user community with a great deal of online material 2
  • 3. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 3 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 Applicatio n Request Response
  • 4. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4 Views: adding a templating engine Why a templating engine? Static HTML is very restrictive and as we’re creating a web application we’ll need something more dynamic. Template engines compile template written in one markup to HTML which is rendered on the user’s browser. There are many templating engine options that can be added to express. ● HAML ● jade ● dustJS ● handlebars ● … For the sake of convenience, we’ll be using dust.js views in this example and will be relying on a module created by PayPal as the template-engine for the rendering of the page. Be sure to read-up on their awesome documentation when using dust.js http://akdubya.github.io/dustjs/#guide
  • 5. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5 Views: adding a template engine var options = { helpers: [ //NOTE: function has to take dust as an argument. //The following function defines @myHelper helper function (dust) { dust.helpers.myHelper = function (a, b, c, d) {} }, 'dustjs-helpers' //So do installed modules ] }; app.engine('dust', adaro.dust(options)); app.set('view engine', 'dust'); app.set('views', __dirname + '/public/views'); npm install adaro --save <html> <body> <div>Hello {name}!</div> </body> </html>
  • 6. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6 Adding Features : module by module A web-application that just serves HTML pages may not be all that useful. Thankfully express is easily extensible thanks to npm. As discussed earlier the node community has populated a massive variety of modules on npm to suit almost any requirement you might come up with during your hackathon. 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
  • 7. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 7 Mashups : Using APIs When developing applications we’d not only want to reuse functionality via npm modules. We’d also like to access external data which would make our web apps even more useful. Many companies & organizations expose their data to developers via APIs. For our weather app consider this API call to fetch Singapore weather http://api.openweathermap.org/data/2.5/weather?q=Singapore You can view the JSON response in your browser. Not all APIs are open. Other may require client secret keys but a good API provider would document how to use their API.
  • 8. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8 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=Singapore' , 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
  • 9. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 9 API Debugging JSON can be a bit difficult to read at times so we rely on some online tools to better understand the API response. http://jsonformatter.curiousconcept.com/
  • 10. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10 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. <html> <body> <h1>Weather for {country}</h1> {#weather} <ul> <li>{main}</li> <li>{description}</li> </ul> {/weather} </body> </html>
  • 11. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11 Try it yourself The complete code for the lab is in the github repo: https://github.com/node-workshop-sst/sst-weather-lab $ cd ~/node $ git clone https://github.com/node-workshop-sst/sst-weather-lab.git $ cd sst-weather-lab $ npm install $ node app.js SST blocks certain ports so we’ll need to override our koding ports Modify this code in app.js to use port 80. app.listen(appEnv.port80, function() { $ sudo service apache2 stop $ sudo node app.js visit aeshanw.koding.io/weather
  • 12. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12 Deploying to Bluemix You’ll need to git add & commit all your code changes except the node_modules folder. Then simply git push to your bluemix git repo to deploy the app to staging. git push origin master And you should see activity on your bluemix dashboard and once its deployed you can hit your own url to view the result http://sst-express-lab.eu-gb.mybluemix.net/weather
  • 13. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13 Conclusion ● Use frameworks like Express to organize your development ● Add features using node modules via npm ● Extend your web app functionality via external APIs ● use web tools & console.log to better debug and better consume 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!

Editor's Notes

  • #3: extol the benefits of a simple framework like express