Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building web apps with Express
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Andy Appleton
February 06, 2013
Technology
510
4
Share
Building web apps with Express
An introduction to the Express web framework for Node.js
Andy Appleton
February 06, 2013
More Decks by Andy Appleton
See All by Andy Appleton
Done is better than perfect
appltn
0
600
Rage against the state machine
appltn
1
550
Modular UI with (Angular || Ember)
appltn
0
130
The Modern JavaScript Application
appltn
5
680
Object Creation Pattern Performance
appltn
1
830
Introducing Mint Source
appltn
1
410
Other Decks in Technology
See All in Technology
ぼくがかんがえたさいきょうのあうとぷっと
yama3133
0
190
レビューしきれない?それは「全て人力でのレビュー」だからではないでしょうか
amixedcolor
0
330
扱える不確実性を増やしていく - スタートアップEMが考える「任せ方」
kadoppe
0
300
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
16k
AI時代のガードレールとしてのAPIガバナンス
nagix
0
280
EBS暗号化に失敗してEC2が動かなくなった話
hamaguchimmm
2
200
最初の一歩を踏み出せなかった私が、誰かの背中を押したいと思うようになるまで / give someone a push
mii3king
0
160
AI와 협업하는 조직으로의 여정
arawn
0
430
みんなで作るAWS Tips 100連発 (FinOps編)
schwrzktz
1
300
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
0
1.2k
最近の技術系の話題で気になったもの色々(IoT系以外も) / IoTLT 花見予定会(たぶんBBQ) @都立潮風公園バーベキュー広場
you
PRO
1
240
AgentCore×VPCでの設計パターンn選と勘所
har1101
3
280
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
340
Tell your own story through comics
letsgokoyo
1
900
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
220
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
230
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
200
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
320
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Mobile First: as difficult as doing things right
swwweet
225
10k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
160
Transcript
Building web apps with Express Andy Appleton @appltn http://appleton.me
Express is a simple web application framework http://expressjs.com/
...built on Connect, the middleware framework http://www.senchalabs.org/connect/
Connect provides a bunch of handy utilities for dealing with
HTTP requests
var app = connect() .use(connect.logger('dev')) .use(connect.static('public')) .use(function(req, res){ res.end('hello world\n');
}) .listen(3000);
But anyway, Express
$ npm install -g express Install express globally
$ npm install -g express Init a new express app
in ./awesome-demo $ express awesome-demo
$ npm install -g express Install the app’s dependencies with
npm $ express awesome-demo $ cd awesome-demo && npm install
$ npm install -g express Run it! $ express awesome-demo
$ cd awesome-demo && npm install $ node app.js >> Express server listening on port 3000
None
None
var express = require('express'); ... var app = express();
// Get & set an app property app.set('name', 'value'); //
Use a middleware function app.use(myMiddlewareFunction()); // Respond to an HTTP request app.get('/path', callbackFn); app.post('/path', callbackFn); app.put('/path', callbackFn); // ...etc
Routing
app.get('/', routes.index); app.get('/users', routes.users.index); app.get('/users/:id', routes.users.show); app.post('/users/:id', routes.users.create); app.put('/users/:id', routes.users.update);
Handling a route // /users routes.index = function(req, res) {
res.send('Hello Bath'); }; // /users/:id routes.users.show = function(req, res) { var userId = req.params.id; res.send('Your userId is ' + userId); };
Rendering HTML templates
Rendering HTML templates routes.index = function(req, res) { res.render('index'); };
routes.users.show = function(req, res) { var userId = req.params.id; res.render('users/show', { id: userId }); };
doctype 5 html head ... body block content extends layout
block content h1= title p Welcome to #{title} ./views/layout.jade ./views/index.jade
"dependencies": { ... "hbs": "*" } ./package.json $ npm install
./app.js app.configure(function(){ ... app.set('view engine', 'hbs'); ... }); app.configure(function(){ ... app.set('view engine', 'jade'); ... });
<!DOCTYPE html> <html> <head>...</head> <body> {{{body}}} </body> </html> ./views/layout.hbs ./views/index.hbs
<h1>{{title}}</h1> <p>Welcome to {{title}}</p>
routes.index = function(req, res) { res.render('index'); }; routes.users.show = function(req,
res) { var userId = req.params.id; res.render('users/show', { id: userId }); };
Sessions
// must come before router app.use(express.cookieParser('secret')); app.use(express.session()); app.use(app.router); Session support
is middleware
routes.users.show = function(req, res) { req.session.id || (req.session.id = 1);
res.render('users/show', { id: req.session.id }); };
Andy Appleton @appltn http://appleton.me