Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

411 lines · 11.0 KiB · HTML

Last changed by

Fixed typo in docsTj Holowaychukbefore adoption0a84824

History of this file

Take it

The walk stopped after 200 commits: lines older than 5842a3b point at it.

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 1–3why, one step back
1<html>
2 <head>3 <title>Express - node web framework</title>

Move menu up after scrolling. Closes #352Tj Holowaychukbefore adoptionce23e5f

lines 4–16why, one step back
4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
5 <script>6 $(function(){7 var done;8 $(document).scroll(function(event){9 if (!done) {10 $('#toc').animate({11 top: 012 });13 }14 });15 });16 </script>

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 17–18why, one step back
17 <style>
18 #header {

Absolute labs bannerTj Holowaychukbefore adoption2b2fa7e

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 20–21why, one step back
20 top: 10px;
21 left: 0;

Fixed bannerTj Holowaychukbefore adoption2fda5c7

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 24–59why, one step back
24 width: 100%;
25 border-top: 1px solid rgba(0,0,0,0.7);26 border-bottom: 1px solid rgba(0,0,0,0.7);27 background: rgba(255,255,255,0.1) url(http://www.sencha.com/favicon.ico) no-repeat 15px 50%;28 text-align: left;29 color: #fff;30 }31 #tagline {32 margin-left: 75px;33 margin-bottom: 30px;34 color: rgba(255,255,255,0.7); }35 html {36 background: #1c1c1c url(images/bg.tile.jpg); }3738 body {39 margin: 0;40 padding-bottom: 30px;41 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";42 font-size: 14px;43 line-height: 1.5;44 -webkit-text-stroke: 1px rgba(0, 0, 0, 0.1);45 -moz-text-stroke: 1px rgba(0, 0, 0, 0.1);46 background: url(images/bg.jpg) 50% 0 no-repeat;47 color: #8b8b8b; }4849 * {50 outline: none; }5152 em {53 color: white; }5455 a img {56 border: none !important; }5758 a {59 font-weight: bold;

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

line 60why, one step back
60 text-decoration: none;

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 61–128why, one step back
61 color: white;
62 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;63 -webkit-transition-duration: 0.15s;64 -webkit-transition-timing-function: ease-out; }65 a:hover {66 opacity: 0.8; }6768 h1, h2, h3 {69 margin: 45px 0 0 0;70 color: white;71 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }7273 h3 {74 font-size: 18px; }7576 pre {77 margin: 20px 10px;78 padding: 25px 20px;79 background: rgba(0,0,0,0.5);80 border: 1px solid #323232;81 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);82 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);83 -webkit-border-radius: 5px;84 -moz-border-radius: 5px; }8586 code {87 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }8889 ul {90 margin: 15px 0;91 padding: 0 0 0 35px; }92 ul li {93 margin: 0;94 padding: 2px 0;95 list-style: square; }9697 .sect {98 margin-left: 40px; }99100 #logo {101 display: block;102 margin-left: 30%;103 margin-bottom: 30px;104 width: 194px;105 height: 51px;106 background: url(images/logo.png) 0 0 no-repeat;107 text-indent: -99999px; }108 #logo:hover {109 opacity: 0.7; }110 #logo:active {111 opacity: 0.3; }112113 #ribbon {114 position: fixed;115 top: 0;116 right: 0;117 z-index: 2; }118119 #wrapper {120 width: 100%;121 min-height: 800px;122 background: url(images/top.png) 0 0 repeat-x; }123124 #container {125 margin: 0 auto;126 padding-top: 110px;127 width: 550px; }128

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

lines 129–139why, one step back
129 #toc {
130 position: fixed;131 top: 60px;132 left: 0;133 margin: 0 0 0 15px;134 padding: 15px;135 height: 100%;136 background: rgba(0,0,0,0.2);137 border-right: 1px solid rgba(255,255,255,0.05);138 }139 #toc li {

More view docsTj Holowaychukbefore adoption1c8ff48

line 140why, one step back
140 padding: 0;

Merge branch 'docs' into connectTj Holowaychukbefore adoption492f70f

lines 141–145why, one step back
141 list-style: none;
142 }143 #toc li a {144 font-size: 11px;145 }

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

line 146why, one step back
146 #menu {

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 148–162why, one step back
148 padding: 0;
149 padding-bottom: 30px; }150 #menu li {151 display: inline;152 list-style: none; }153 #menu li a {154 display: block;155 float: left;156 margin: 0 2px;157 padding: 3px 15px;158 background: rgba(0,0,0,0.2);159 -webkit-border-radius: 8px;160 -moz-border-radius: 8px;161 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);162 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);

Removed annoying padding transitionTj Holowaychukbefore adoption346b2a2

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 164–182why, one step back
164 -webkit-transition-duration: 0.15s;
165 -webkit-transition-timing-function: ease-out; }166 #menu li a:hover,167 #menu li a.active {168 background: rgba(0,0,0,0.5); }169 #menu li a:active {170 background: rgba(0,0,0,0.1);171 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);172 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }173 </style>174 </head>175 <body>176 <a href='http://github.com/visionmedia/express'> 177 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 178 </a>179 <div id="header"><strong>Sencha</strong> labs</div>180 <div id="wrapper">181 <div id="container">182 <a href='http://github.com/visionmedia/express' id='logo'>Express</a>

Fixed bannerTj Holowaychukbefore adoption2fda5c7

lines 183–186why, one step back
183 <p id="tagline">
184 High performance, high class web development for185 <a href="http://nodejs.org">Node.js</a>186 </p>

Added menu to docsTj Holowaychukbefore adoptionac560be

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

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

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

Added menu to docsTj Holowaychukbefore adoptionac560be

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

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

Started guideTj Holowaychukbefore adoption9e3a0c6

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

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

line 195why, one step back
195

Started migration docsTj Holowaychukbefore adoption9e68a5b

line 196why, one step back
196<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 197–199why, one step back
197framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware
198to Connect we allow additional community frameworks to develop robust, high-level frameworks using199the same technologies as Express.</p>

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 200–218why, one step back
200
201<h3 id="Creating-Applications">Creating Applications</h3>202203<p>Previously due to legacy code implemented in the early days of node,204Express unfortunately had some globals. The DSL would previously be205accessed as shown below:</p>206207<pre><code>require('express');208209configure(function(){210 // app configuration211});212213get('/', function(){214 return 'hello world';215});216</code></pre>217218<p>Now we utilize the CommonJS module system appropriately, and

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 221–233why, one step back
221
222<pre><code>var express = require('express'),223 app = express.createServer();224225app.configure(function(){226 // app configuration227});228229app.get('/', function(req, res){230 res.send('hello world');231});232</code></pre>233

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 234–246why, one step back
234<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>
235236<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>237238<p>Previously Express was bundled with plugins, which were essentially what239are now Connect middleware. Previously plugins would be utilized in a manor240similar to below:</p>241242<pre><code>use(Logger);243use(MethodOverride);244use(Cookie);245</code></pre>246

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 247why, one step back
247<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 248–253why, one step back
248
249<pre><code>var connect = require('connect');250251var app = express.createServer(252 connect.logger(),253 connect.methodOverride(),

Fixed typo in docsTj Holowaychukbefore adoption0a84824

line 254why, one step back
254 connect.cookieDecoder()

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 255–262why, one step back
255);
256</code></pre>257258<p>or:</p>259260<pre><code>var connect = require('connect');261var app = express.createServer();262

Updated docsTj Holowaychukbefore adoptioncacada8

lines 263–265why, one step back
263app.use(connect.logger());
264app.use(connect.methodOverride());265app.use(connect.cookieDecoder());

Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7

lines 266–268why, one step back
266</code></pre>
267268<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 269why, one step back
269

Started migration docsTj Holowaychukbefore adoption9e68a5b

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 273–276why, one step back
273
274<pre><code>run();275</code></pre>276

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Started migration docsTj Holowaychukbefore adoption9e68a5b

lines 278–282why, one step back
278so we can do things like:</p>
279280<pre><code>app.listen();281app.listen(3000);282</code></pre>

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

line 283why, one step back
283

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 287–293why, one step back
287fetching a route, query string, or request body parameter:</p>
288289<pre><code>get('/user/:id', function(){290 this.param('id');291});292</code></pre>293

Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894

lines 294–295why, one step back
294<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>
295

Fixed migration typoTj Holowaychukbefore adoptiona9c3f56

line 296why, one step back
296<pre><code>app.get('/user/:id', function(req, res){

Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894

lines 297–301why, one step back
297 req.param('id');
298});299</code></pre>300301<p>Route parameters are also passed as the third argument:</p>

Migration docs for paramsTj Holowaychukbefore adoptionda84c0b

lines 302–307why, one step back
302
303<pre><code>app.get('/user/:id', function(req, res, params){304 params.id;305});306</code></pre>307

Control passing docsTj Holowaychukbefore adoption548a070

lines 308–318why, one step back
308<h3 id="Passing-Route-Control">Passing Route Control</h3>
309310<p>Old express had a weak notion of route passing,311which did not support async, and was never properly312implemented for practical use:</p>313314<pre><code>get('/', function(){315 this.pass('/foobar');316});317</code></pre>318

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Control passing docsTj Holowaychukbefore adoption548a070

lines 321–329why, one step back
321pass control to the next <em>matching route</em>, or continue down the stack
322of Connect middleware.</p>323324<pre><code>app.get('/user/:id?', function(req, res, params, next){325 next();326});327328app.get('/user', function(){329 // ... respond

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 330–335why, one step back
330});
331</code></pre>332333<h3 id="View-Rendering">View Rendering</h3>334335<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2

lines 338–348why, one step back
338should now be <em>layout.haml</em>.</p>
339340<p>Previously a view render looked something like this:</p>341342<pre><code>get('/', function(){343 this.render('index.html.haml', {344 locals: { title: 'My Site' }345 });346});347</code></pre>348

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

line 349why, one step back
349<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 350–355why, one step back
350remain the same.</p>
351352<pre><code>app.get('/', function(req, res){353 res.render('index.haml', {354 locals: { title: 'My Site' }355 });

Control passing docsTj Holowaychukbefore adoption548a070

lines 356–358why, one step back
356});
357</code></pre>358

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added partial migration docsTj Holowaychukbefore adoption2a674f4

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

Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3

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

Added partial migration docsTj Holowaychukbefore adoption2a674f4

lines 366–369why, one step back
366
367<pre><code>partial('comment.haml', { collection: comments });368</code></pre>369

Added more view docsTj Holowaychukbefore adoption2f96506

line 370why, one step back
370<p>To make things even less verbose we can assume the extension when omitted:</p>

Added partial migration docsTj Holowaychukbefore adoption2a674f4

lines 371–380why, one step back
371
372<pre><code>partial('comment', { collection: comments });373</code></pre>374375<p>And once again even further, when rendering a collection we can simply pass376an array, if no other options are desired:</p>377378<pre><code>partial('comments', comments);379</code></pre>380

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

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

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 382–387why, one step back
382
383<p>Previously you would</p>384385<pre><code>this.redirect('/somewhere');386</code></pre>387

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

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

Added redirect migration docsTj Holowaychukbefore adoption74432a6

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

Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7

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

Added contrib docsTj Holowaychukbefore adoptionf0ba57b

lines 392–404why, one step back
392</code></pre>
393394<h3 id="HTTP-Client">HTTP Client</h3>395396<p>Previously Express provided a high level http client, this library is no more397as it does not belong in Express, however it may be resurrected as a separate module.</p>398399<h3 id="Core-Extensions">Core Extensions</h3>400401<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 to402roll your own, or install the module via:</p>403404<pre><code>$ npm install ext

Added redirect migration docsTj Holowaychukbefore adoption74432a6

lines 405–406why, one step back
405</code></pre>
406

Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b

lines 407–411why, one step back
407</div>
408 </div>409 </div>410 </body>411</html>