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
740
Object Creation Pattern Performance
appltn
1
850
Introducing Mint Source
appltn
1
440
Other Decks in Technology
See All in Technology
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
610
[General] 개발자로 해외 기업에서 일하기
skydoves
1
250
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
500
複雑な業務システムを高速でつくるため、チーム全員をつくれる人へ
ayakurabuchi
0
120
1週間、Opus封印でお願いします
kintotechdev
1
430
Systems Manager AgentがインストールされたPCを紛失した時の対策を考えてみた
amarelo_n24
1
110
You Have Agency(サンキュー、Ruby)
snoozer05
PRO
5
650
リアクションエンジニア ― 小さなリアクションから、話しかけやすい組織をつくる ―
ryuguyana
1
110
【Oracle AI SPOTLIGHT ウェビナー】事例から見る!なぜOCIが選ばれたのか ― AI時代のクラウド戦略を紐解く ―
oracle4engineer
PRO
1
150
Don't write the architecture only in the prompt.
neohsu
0
290
eBPF 簡介 2026 版
shunghsiyu
0
150
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
150
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
350
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
340
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
310
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
The World Runs on Bad Software
bkeepers
PRO
72
12k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
Test your architecture with Archunit
thirion
2
2.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
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