Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Building web apps with Express
Search
Andy Appleton
February 06, 2013
Technology
540
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
620
Rage against the state machine
appltn
1
650
Modular UI with (Angular || Ember)
appltn
0
160
The Modern JavaScript Application
appltn
5
730
Object Creation Pattern Performance
appltn
1
850
Introducing Mint Source
appltn
1
440
Other Decks in Technology
See All in Technology
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
330
AI コーディングと人間の認知スループット / CTO Night & Day 2026 Morning Session / AI Coding and Human Cognitive Throughput
prog893
4
1k
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
しろおびから始める!ログ活用の第一歩
shumei_ito
0
950
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
120
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
1.1k
会社説明資料
persolserverworks
0
9.8k
『SAR衛星データ解析入門』のご紹介とその応用
syuchimu
0
120
Local CI × GitHub Actions
gogutan
2
190
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
160
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
570
Featured
See All Featured
BBQ
matthewcrist
90
10k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
820
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Code Reviewing Like a Champion
maltzj
529
40k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Technical Leadership for Architectural Decision Making
baasie
3
600
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
Everyday Curiosity
cassininazir
0
350
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