Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

396 lines · 10.7 KiB · HTML

Last changed by

Misc stylingTj Holowaychukbefore adoption7b55867

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–61why, one step back
56 color: white;
57 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5859 h3 {60 font-size: 18px; }61

Started new docsTj Holowaychukbefore adoption29641ae

line 62why, one step back
62 pre {

More doc stylingTj Holowaychukbefore adoption87b7524

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

More stylingTj Holowaychukbefore adoption7c651e6

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

More doc stylingTj Holowaychukbefore adoption87b7524

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

Added contributors back to docsTj Holowaychukbefore adoption195c8a9

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

More doc stylingTj Holowaychukbefore adoption87b7524

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

More stylingTj Holowaychukbefore adoption7c651e6

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

More doc stylingTj Holowaychukbefore adoption87b7524

lines 113–114why, one step back
113 width: 550px; }
114

Setting up TOCTj Holowaychukbefore adoption3e15ef1

lines 115–116why, one step back
115 #toc {
116 position: fixed;

Misc stylingTj Holowaychukbefore adoption7b55867

line 117why, one step back
117 top: 60px;

Setting up TOCTj Holowaychukbefore adoption3e15ef1

lines 118–119why, one step back
118 left: 0;
119 margin: 0 0 0 15px;

Misc stylingTj Holowaychukbefore adoption7b55867

lines 120–123why, one step back
120 padding: 15px;
121 height: 100%;122 background: rgba(0,0,0,0.2);123 border-right: 1px solid rgba(255,255,255,0.05);

Setting up TOCTj Holowaychukbefore adoption3e15ef1

lines 124–127why, one step back
124 }
125 #toc li {126 list-style: none;127 }

Misc stylingTj Holowaychukbefore adoption7b55867

lines 128–130why, one step back
128 #toc li a {
129 font-size: 11px;130 }

More doc stylingTj Holowaychukbefore adoption87b7524

line 131why, one step back
131 #menu {

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

line 132why, one step back
132 margin-left: 65px;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 133–147why, one step back
133 padding: 0;
134 padding-bottom: 30px; }135 #menu li {136 display: inline;137 list-style: none; }138 #menu li a {139 display: block;140 float: left;141 margin: 0 2px;142 padding: 3px 15px;143 background: rgba(0,0,0,0.2);144 -webkit-border-radius: 8px;145 -moz-border-radius: 8px;146 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);147 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);

Removed annoying padding transitionTj Holowaychukbefore adoption346b2a2

line 148why, one step back
148 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;

More doc stylingTj Holowaychukbefore adoption87b7524

lines 149–157why, one step back
149 -webkit-transition-duration: 0.15s;
150 -webkit-transition-timing-function: ease-out; }151 #menu li a:hover,152 #menu li a.active {153 background: rgba(0,0,0,0.5); }154 #menu li a:active {155 background: rgba(0,0,0,0.1);156 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);157 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }

Started new docsTj Holowaychukbefore adoption29641ae

lines 158–160why, one step back
158 </style>
159 </head>160 <body>

More doc stylingTj Holowaychukbefore adoption87b7524

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

Started new docsTj Holowaychukbefore adoption29641ae

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

Added images back to docsTj Holowaychukbefore adoption860b899

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

Fixed bannerTj Holowaychukbefore adoption2fda5c7

lines 168–171why, one step back
168 <p id="tagline">
169 High performance, high class web development for170 <a href="http://nodejs.org">Node.js</a>171 </p>

Added menu to docsTj Holowaychukbefore adoptionac560be

lines 172–174why, one step back
172 <ul id="menu">
173 <li><a href="index.html">Home</a></li>174 <li><a href="guide.html">Guide</a></li>

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

line 175why, one step back
175 <li><a href="contrib.html">Contributing</a></li>

Added menu to docsTj Holowaychukbefore adoptionac560be

lines 176–177why, one step back
176 <li><a href="migrate.html">1.x Migration</a></li>
177 </ul>

Added images back to docsTj Holowaychukbefore adoption860b899

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

Started guideTj Holowaychukbefore adoption9e3a0c6

line 179why, one step back
179<h3 id="Built-On-Connect">Built On Connect</h3>

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

line 180why, one step back
180

Started migration docsTj Holowaychukbefore adoption9e68a5b

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

Started guideTj Holowaychukbefore adoption9e3a0c6

lines 182–184why, one step back
182framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware
183to Connect we allow additional community frameworks to develop robust, high-level frameworks using184the same technologies as Express.</p>

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 185–203why, one step back
185
186<h3 id="Creating-Applications">Creating Applications</h3>187188<p>Previously due to legacy code implemented in the early days of node,189Express unfortunately had some globals. The DSL would previously be190accessed as shown below:</p>191192<pre><code>require('express');193194configure(function(){195 // app configuration196});197198get('/', function(){199 return 'hello world';200});201</code></pre>202203<p>Now we utilize the CommonJS module system appropriately, and

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 206–218why, one step back
206
207<pre><code>var express = require('express'),208 app = express.createServer();209210app.configure(function(){211 // app configuration212});213214app.get('/', function(req, res){215 res.send('hello world');216});217</code></pre>218

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 219–231why, one step back
219<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>
220221<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>222223<p>Previously Express was bundled with plugins, which were essentially what224are now Connect middleware. Previously plugins would be utilized in a manor225similar to below:</p>226227<pre><code>use(Logger);228use(MethodOverride);229use(Cookie);230</code></pre>231

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 232why, one step back
232<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 233–249why, one step back
233
234<pre><code>var connect = require('connect');235236var app = express.createServer(237 connect.logger(),238 connect.methodOverride(),239 connect.cookie()240);241</code></pre>242243<p>or:</p>244245<pre><code>var connect = require('connect');246var app = express.createServer();247248app.use('/', connect.logger());249app.use('/', connect.methodOverride());

Added configuration sectionTj Holowaychukbefore adoption83d2555

line 250why, one step back
250app.use('/', connect.cookieDecoder());

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 251–253why, one step back
251</code></pre>
252253<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 254why, one step back
254

Started migration docsTj Holowaychukbefore adoption9e68a5b

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 258–261why, one step back
258
259<pre><code>run();260</code></pre>261

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 263–267why, one step back
263so we can do things like:</p>
264265<pre><code>app.listen();266app.listen(3000);267</code></pre>

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

line 268why, one step back
268

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 272–278why, one step back
272fetching a route, query string, or request body parameter:</p>
273274<pre><code>get('/user/:id', function(){275 this.param('id');276});277</code></pre>278

Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894

lines 279–286why, one step back
279<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>
280281<pre><code>app.get('/user/:id', function(){282 req.param('id');283});284</code></pre>285286<p>Route parameters are also passed as the third argument:</p>

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 287–292why, one step back
287
288<pre><code>app.get('/user/:id', function(req, res, params){289 params.id;290});291</code></pre>292

Control passing docsTj Holowaychukbefore adoption548a070

lines 293–303why, one step back
293<h3 id="Passing-Route-Control">Passing Route Control</h3>
294295<p>Old express had a weak notion of route passing,296which did not support async, and was never properly297implemented for practical use:</p>298299<pre><code>get('/', function(){300 this.pass('/foobar');301});302</code></pre>303

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Control passing docsTj Holowaychukbefore adoption548a070

lines 306–314why, one step back
306pass control to the next <em>matching route</em>, or continue down the stack
307of Connect middleware.</p>308309<pre><code>app.get('/user/:id?', function(req, res, params, next){310 next();311});312313app.get('/user', function(){314 // ... respond

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 315–320why, one step back
315});
316</code></pre>317318<h3 id="View-Rendering">View Rendering</h3>319320<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 323–333why, one step back
323should now be <em>layout.haml</em>.</p>
324325<p>Previously a view render looked something like this:</p>326327<pre><code>get('/', function(){328 this.render('index.html.haml', {329 locals: { title: 'My Site' }330 });331});332</code></pre>333

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 334why, one step back
334<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 335–340why, one step back
335remain the same.</p>
336337<pre><code>app.get('/', function(req, res){338 res.render('index.haml', {339 locals: { title: 'My Site' }340 });

Control passing docsTj Holowaychukbefore adoption548a070

lines 341–343why, one step back
341});
342</code></pre>343

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added partial migration docsTj Holowaychukbefore adoption2a674f4

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added partial migration docsTj Holowaychukbefore adoption2a674f4

lines 351–365why, one step back
351
352<pre><code>partial('comment.haml', { collection: comments });353</code></pre>354355<p>To make things even less verbose we can assume the extension when ommitted:</p>356357<pre><code>partial('comment', { collection: comments });358</code></pre>359360<p>And once again even further, when rendering a collection we can simply pass361an array, if no other options are desired:</p>362363<pre><code>partial('comments', comments);364</code></pre>365

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

line 366why, one step back
366<h3 id="Redirecting">Redirecting</h3>

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 367–372why, one step back
367
368<p>Previously you would</p>369370<pre><code>this.redirect('/somewhere');371</code></pre>372

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

line 373why, one step back
373<p>However you would now:</p>

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 374–375why, one step back
374
375<pre><code>res.redirect('/somewhere');

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

line 376why, one step back
376res.redirect('/somewhere', 301);

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

lines 377–389why, one step back
377</code></pre>
378379<h3 id="HTTP-Client">HTTP Client</h3>380381<p>Previously Express provided a high level http client, this library is no more382as it does not belong in Express, however it may be resurrected as a separate module.</p>383384<h3 id="Core-Extensions">Core Extensions</h3>385386<p>Express is no longer dependent on the <a href="http://github.com/visionmedia/ext.js">JavaScript Extensions</a> library, so those of you using the methods provided by it such as <code>Object.merge(a, b)</code> will need to387roll your own, or install the module via:</p>388389<pre><code>$ npm install ext

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 390–391why, one step back
390</code></pre>
391

Added migrate doc filesTj Holowaychukbefore adoption87bb27c

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

Added images back to docsTj Holowaychukbefore adoption860b899

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

Started new docsTj Holowaychukbefore adoption29641ae

lines 394–396why, one step back
394 </div>
395 </body>396</html>