Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

365 lines · 9.8 KiB · HTML

Last changed by

Fixed bannerTj Holowaychukbefore adoption2fda5c7

History of this file

Take it

Started new docsTj Holowaychukbefore adoption29641ae

lines 1–5why, one step back
1<html>
2 <head>3 <title>Express - node web framework</title>4 <style>5 #header {

Absolute labs bannerTj Holowaychukbefore adoption2b2fa7e

line 6why, one step back
6 position: absolute;

More docsTj Holowaychukbefore adoption900c5ed

line 7why, one step back
7 top: 10px;

More doc stylingTj Holowaychukbefore adoption87b7524

line 8why, one step back
8 left: 0;

Fixed bannerTj Holowaychukbefore adoption2fda5c7

lines 9–10why, one step back
9 padding: 12px 0;
10 text-indent: 40px;

More doc stylingTj Holowaychukbefore adoption87b7524

line 11why, one step back
11 width: 100%;

More docsTj Holowaychukbefore adoption900c5ed

lines 12–13why, one step back
12 border-top: 1px solid rgba(0,0,0,0.7);
13 border-bottom: 1px solid rgba(0,0,0,0.7);

More doc stylingTj Holowaychukbefore adoption87b7524

line 14why, one step back
14 background: rgba(255,255,255,0.1) url(http://www.sencha.com/favicon.ico) no-repeat 15px 50%;

Started new docsTj Holowaychukbefore adoption29641ae

line 15why, one step back
15 text-align: left;

More doc stylingTj Holowaychukbefore adoption87b7524

line 16why, one step back
16 color: #fff;

Started new docsTj Holowaychukbefore adoption29641ae

line 17why, one step back
17 }

More stylingTj Holowaychukbefore adoption7c651e6

lines 18–21why, one step back
18 #tagline {
19 margin-left: 75px;20 margin-bottom: 30px;21 color: rgba(255,255,255,0.7); }

More doc stylingTj Holowaychukbefore adoption87b7524

lines 22–54why, one step back
22 html {
23 background: #1c1c1c url(images/bg.tile.jpg); }2425 body {26 margin: 0;27 padding-bottom: 30px;28 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";29 font-size: 14px;30 line-height: 1.5;31 -webkit-text-stroke: 1px rgba(0, 0, 0, 0.1);32 -moz-text-stroke: 1px rgba(0, 0, 0, 0.1);33 background: url(images/bg.jpg) 50% 0 no-repeat;34 color: #8b8b8b; }3536 * {37 outline: none; }3839 em {40 color: white; }4142 a img {43 border: none !important; }4445 a {46 font-weight: bold;47 color: white;48 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;49 -webkit-transition-duration: 0.15s;50 -webkit-transition-timing-function: ease-out; }51 a:hover {52 opacity: 0.8; }5354 h1, h2, h3 {

Added contributors back to docsTj Holowaychukbefore adoption195c8a9

line 55why, one step back
55 margin: 45px 0 0 0;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 56–62why, one step back
56 color: white;
57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 margin-left: 20px;61 font-size: 18px; }62

Started new docsTj Holowaychukbefore adoption29641ae

line 63why, one step back
63 pre {

More doc stylingTj Holowaychukbefore adoption87b7524

line 64why, one step back
64 margin: 20px 10px;

More stylingTj Holowaychukbefore adoption7c651e6

line 65why, one step back
65 padding: 25px 20px;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 66–100why, one step back
66 background: rgba(0,0,0,0.5);
67 border: 1px solid #323232;68 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);69 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);70 -webkit-border-radius: 5px;71 -moz-border-radius: 5px; }7273 code {74 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }7576 ul {77 margin: 15px 0;78 padding: 0 0 0 35px; }79 ul li {80 margin: 0;81 padding: 2px 0;82 list-style: square; }8384 .sect {85 margin-left: 40px; }8687 #logo {88 display: block;89 margin-left: 30%;90 margin-bottom: 30px;91 width: 194px;92 height: 51px;93 background: url(images/logo.png) 0 0 no-repeat;94 text-indent: -99999px; }95 #logo:hover {96 opacity: 0.7; }97 #logo:active {98 opacity: 0.3; }99100 #ribbon {

Added contributors back to docsTj Holowaychukbefore adoption195c8a9

line 101why, one step back
101 position: fixed;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 102–112why, one step back
102 top: 0;
103 right: 0;104 z-index: 2; }105106 #wrapper {107 width: 100%;108 min-height: 800px;109 background: url(images/top.png) 0 0 repeat-x; }110111 #container {112 margin: 0 auto;

More stylingTj Holowaychukbefore adoption7c651e6

line 113why, one step back
113 padding-top: 110px;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 114–116why, one step back
114 width: 550px; }
115116 #menu {

Fixed bannerTj Holowaychukbefore adoption2fda5c7

line 117why, one step back
117 margin-left: 130px;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 118–143why, one step back
118 padding: 0;
119 padding-bottom: 30px; }120 #menu li {121 display: inline;122 list-style: none; }123 #menu li a {124 display: block;125 float: left;126 margin: 0 2px;127 padding: 3px 15px;128 background: rgba(0,0,0,0.2);129 -webkit-border-radius: 8px;130 -moz-border-radius: 8px;131 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);132 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);133 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;134 -webkit-transition-duration: 0.15s;135 -webkit-transition-timing-function: ease-out; }136 #menu li a:hover,137 #menu li a.active {138 padding: 3px 20px;139 background: rgba(0,0,0,0.5); }140 #menu li a:active {141 background: rgba(0,0,0,0.1);142 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);143 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }

Started new docsTj Holowaychukbefore adoption29641ae

lines 144–146why, one step back
144 </style>
145 </head>146 <body>

More doc stylingTj Holowaychukbefore adoption87b7524

lines 147–149why, one step back
147 <a href='http://github.com/visionmedia/express'>
148 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 149 </a>

Started new docsTj Holowaychukbefore adoption29641ae

line 150why, one step back
150 <div id="header"><strong>Sencha</strong> labs</div>

Added images back to docsTj Holowaychukbefore adoption860b899

lines 151–153why, one step back
151 <div id="wrapper">
152 <div id="container">153 <a href='http://github.com/visionmedia/express' id='logo'>Express</a>

Fixed bannerTj Holowaychukbefore adoption2fda5c7

lines 154–157why, one step back
154 <p id="tagline">
155 High performance, high class web development for156 <a href="http://nodejs.org">Node.js</a>157 </p>

Added menu to docsTj Holowaychukbefore adoptionac560be

lines 158–162why, one step back
158 <ul id="menu">
159 <li><a href="index.html">Home</a></li>160 <li><a href="guide.html">Guide</a></li>161 <li><a href="migrate.html">1.x Migration</a></li>162 </ul>

Added images back to docsTj Holowaychukbefore adoption860b899

line 163why, one step back
163<div class='mp'>

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

lines 164–165why, one step back
164<h2 id="Migration-Guide">Migration Guide</h2>
165

Started migration docsTj Holowaychukbefore adoption9e68a5b

line 166why, one step back
166<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 167why, one step back
167framework, thus the <em>Plugin</em> has been replaced by Connect's middleware.</p>

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 168–186why, one step back
168
169<h3 id="Creating-Applications">Creating Applications</h3>170171<p>Previously due to legacy code implemented in the early days of node,172Express unfortunately had some globals. The DSL would previously be173accessed as shown below:</p>174175<pre><code>require('express');176177configure(function(){178 // app configuration179});180181get('/', function(){182 return 'hello world';183});184</code></pre>185186<p>Now we utilize the CommonJS module system appropriately, and

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

lines 187–188why, one step back
187introduce <em>express.createServer()</em> which accepts the same arguments
188as <em>http.createServer()</em>:</p>

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 189–201why, one step back
189
190<pre><code>var express = require('express'),191 app = express.createServer();192193app.configure(function(){194 // app configuration195});196197app.get('/', function(req, res){198 res.send('hello world');199});200</code></pre>201

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 202–214why, one step back
202<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>
203204<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>205206<p>Previously Express was bundled with plugins, which were essentially what207are now Connect middleware. Previously plugins would be utilized in a manor208similar to below:</p>209210<pre><code>use(Logger);211use(MethodOverride);212use(Cookie);213</code></pre>214

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 215why, one step back
215<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 216–236why, one step back
216
217<pre><code>var connect = require('connect');218219var app = express.createServer(220 connect.logger(),221 connect.methodOverride(),222 connect.cookie()223);224</code></pre>225226<p>or:</p>227228<pre><code>var connect = require('connect');229var app = express.createServer();230231app.use('/', connect.logger());232app.use('/', connect.methodOverride());233app.use('/', connect.cookie());234</code></pre>235236<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

line 237why, one step back
237

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 238–239why, one step back
238<h3 id="Running-Applications">Running Applications</h3>
239

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 240why, one step back
240<p>Previously a global function <em>run()</em>, was available:</p>

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 241–244why, one step back
241
242<pre><code>run();243</code></pre>244

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 245why, one step back
245<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 246–250why, one step back
246so we can do things like:</p>
247248<pre><code>app.listen();249app.listen(3000);250</code></pre>

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

line 251why, one step back
251

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 252–253why, one step back
252<h3 id="Route-Parameters">Route Parameters</h3>
253

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 254why, one step back
254<p>Previously we could use <em>this.param()</em> to attempt

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 255–261why, one step back
255fetching a route, query string, or request body parameter:</p>
256257<pre><code>get('/user/:id', function(){258 this.param('id');259});260</code></pre>261

Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894

lines 262–269why, one step back
262<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>
263264<pre><code>app.get('/user/:id', function(){265 req.param('id');266});267</code></pre>268269<p>Route parameters are also passed as the third argument:</p>

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 270–275why, one step back
270
271<pre><code>app.get('/user/:id', function(req, res, params){272 params.id;273});274</code></pre>275

Control passing docsTj Holowaychukbefore adoption548a070

lines 276–286why, one step back
276<h3 id="Passing-Route-Control">Passing Route Control</h3>
277278<p>Old express had a weak notion of route passing,279which did not support async, and was never properly280implemented for practical use:</p>281282<pre><code>get('/', function(){283 this.pass('/foobar');284});285</code></pre>286

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

lines 287–288why, one step back
287<p>Now Express has access to Connect's <em>next()</em> function,
288which is passed as the fourth and final argument. Calling <em>next()</em> will

Control passing docsTj Holowaychukbefore adoption548a070

lines 289–297why, one step back
289pass control to the next <em>matching route</em>, or continue down the stack
290of Connect middleware.</p>291292<pre><code>app.get('/user/:id?', function(req, res, params, next){293 next();294});295296app.get('/user', function(){297 // ... respond

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 298–303why, one step back
298});
299</code></pre>300301<h3 id="View-Rendering">View Rendering</h3>302303<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

lines 304–305why, one step back
304the <em>Content-Type</em> can be set via <em>res.contentType()</em> or
305<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 306–316why, one step back
306should now be <em>layout.haml</em>.</p>
307308<p>Previously a view render looked something like this:</p>309310<pre><code>get('/', function(){311 this.render('index.html.haml', {312 locals: { title: 'My Site' }313 });314});315</code></pre>316

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 317why, one step back
317<p>We now have <em>res.render()</em>, however the options passed to <a href="http://github.com/visionmedia/haml.js">haml</a>, <a href="http://github.com/visionmedia/jade">jade</a>, and others

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 318–323why, one step back
318remain the same.</p>
319320<pre><code>app.get('/', function(req, res){321 res.render('index.haml', {322 locals: { title: 'My Site' }323 });

Control passing docsTj Holowaychukbefore adoption548a070

lines 324–326why, one step back
324});
325</code></pre>326

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 327why, one step back
327<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>

Added partial migration docsTj Holowaychukbefore adoption2a674f4

lines 328–332why, one step back
328
329<pre><code>this.partial('comment.html.haml', { collection: comments });330</code></pre>331332<p>Although this worked just fine, it was generally to verbose, the similar but new API

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 333why, one step back
333looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>

Added partial migration docsTj Holowaychukbefore adoption2a674f4

lines 334–348why, one step back
334
335<pre><code>partial('comment.haml', { collection: comments });336</code></pre>337338<p>To make things even less verbose we can assume the extension when ommitted:</p>339340<pre><code>partial('comment', { collection: comments });341</code></pre>342343<p>And once again even further, when rendering a collection we can simply pass344an array, if no other options are desired:</p>345346<pre><code>partial('comments', comments);347</code></pre>348

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 349–360why, one step back
349<h3 id="Redirect">Redirect</h3>
350351<p>Previously you would</p>352353<pre><code>this.redirect('/somewhere');354</code></pre>355356<p>However now you should use the <a href="http://extjs.github.com/Connect/redirect.html">Redirect Middleware</a>:</p>357358<pre><code>res.redirect('/somewhere');359</code></pre>360

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

line 361why, one step back
361</div>

Added images back to docsTj Holowaychukbefore adoption860b899

line 362why, one step back
362 </div>

Started new docsTj Holowaychukbefore adoption29641ae

lines 363–365why, one step back
363 </div>
364 </body>365</html>