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
4
500
Building web apps with Express
An introduction to the Express web framework for Node.js
Andy Appleton
February 06, 2013
Tweet
Share
More Decks by Andy Appleton
See All by Andy Appleton
Done is better than perfect
appltn
0
590
Rage against the state machine
appltn
1
530
Modular UI with (Angular || Ember)
appltn
0
120
The Modern JavaScript Application
appltn
5
670
Object Creation Pattern Performance
appltn
1
830
Introducing Mint Source
appltn
1
410
Other Decks in Technology
See All in Technology
開発組織の課題解決を加速するための権限委譲 -する側、される側としての向き合い方-
daitasu
5
290
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4k
JAWS Days 2026 楽しく学ぼう! 認証認可 入門/20260307-jaws-days-novice-lane-auth
opelab
9
1.5k
JAWSDAYS2026_A-6_現場SEが語る 回せるセキュリティ運用~設計で可視化、AIで加速する「楽に回る」運用設計のコツ~
shoki_hata
0
830
作りっぱなしで終わらせない! 価値を出し続ける AI エージェントのための「信頼性」設計 / Designing Reliability for AI Agents that Deliver Continuous Value
aoto
PRO
1
190
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
Ultra Ethernet (UEC) v1.0 仕様概説
markunet
3
220
管理者向けGitHub Enterpriseの運用Tips紹介: 人にもAIにも優しいプラットフォームづくり
yuriemori
0
160
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
AWS DevOps Agent vs SRE俺 / AWS DevOps Agent vs me, the SRE
sms_tech
2
300
類似画像検索モデルの開発ノウハウ
lycorptech_jp
PRO
4
1k
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
22k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Designing Powerful Visuals for Engaging Learning
tmiket
0
260
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
66
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Curse of the Amulet
leimatthew05
1
9.6k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
340
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
Test your architecture with Archunit
thirion
1
2.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
How GitHub (no longer) Works
holman
316
140k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
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