migrate.html
This file
Path
docs/migrate.html
360 lines · 9.6 KiB · HTML
Last changed by
Added menu to docsTj Holowaychukbefore adoptionac560be
History of this fileTake it
Started new docsTj Holowaychukbefore adoption29641ae
lines 1–5why, one step back1<html>2 <head>3 <title>Express - node web framework</title>4 <style>5 #header {Absolute labs bannerTj Holowaychukbefore adoption2b2fa7e
line 6why, one step back6 position: absolute;More docsTj Holowaychukbefore adoption900c5ed
line 7why, one step back7 top: 10px;More doc stylingTj Holowaychukbefore adoption87b7524
line 8why, one step back8 left: 0;More docsTj Holowaychukbefore adoption900c5ed
line 9why, one step back9 padding: 12px 40px;More doc stylingTj Holowaychukbefore adoption87b7524
line 10why, one step back10 width: 100%;More docsTj Holowaychukbefore adoption900c5ed
lines 11–12why, one step back11 border-top: 1px solid rgba(0,0,0,0.7);12 border-bottom: 1px solid rgba(0,0,0,0.7);More doc stylingTj Holowaychukbefore adoption87b7524
line 13why, one step back13 background: rgba(255,255,255,0.1) url(http://www.sencha.com/favicon.ico) no-repeat 15px 50%;Started new docsTj Holowaychukbefore adoption29641ae
line 14why, one step back14 text-align: left;More doc stylingTj Holowaychukbefore adoption87b7524
line 15why, one step back15 color: #fff;Started new docsTj Holowaychukbefore adoption29641ae
line 16why, one step back16 }More stylingTj Holowaychukbefore adoption7c651e6
lines 17–20why, one step back17 #tagline {18 margin-left: 75px;19 margin-bottom: 30px;20 color: rgba(255,255,255,0.7); }More doc stylingTj Holowaychukbefore adoption87b7524
lines 21–53why, one step back21 html {22 background: #1c1c1c url(images/bg.tile.jpg); }2324 body {25 margin: 0;26 padding-bottom: 30px;27 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";28 font-size: 14px;29 line-height: 1.5;30 -webkit-text-stroke: 1px rgba(0, 0, 0, 0.1);31 -moz-text-stroke: 1px rgba(0, 0, 0, 0.1);32 background: url(images/bg.jpg) 50% 0 no-repeat;33 color: #8b8b8b; }3435 * {36 outline: none; }3738 em {39 color: white; }4041 a img {42 border: none !important; }4344 a {45 font-weight: bold;46 color: white;47 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;48 -webkit-transition-duration: 0.15s;49 -webkit-transition-timing-function: ease-out; }50 a:hover {51 opacity: 0.8; }5253 h1, h2, h3 {Added contributors back to docsTj Holowaychukbefore adoption195c8a9
line 54why, one step back54 margin: 45px 0 0 0;More doc stylingTj Holowaychukbefore adoption87b7524
lines 55–61why, one step back55 color: white;56 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }5758 h3 {59 margin-left: 20px;60 font-size: 18px; }61Started new docsTj Holowaychukbefore adoption29641ae
line 62why, one step back62 pre {More doc stylingTj Holowaychukbefore adoption87b7524
line 63why, one step back63 margin: 20px 10px;More stylingTj Holowaychukbefore adoption7c651e6
line 64why, one step back64 padding: 25px 20px;More doc stylingTj Holowaychukbefore adoption87b7524
lines 65–99why, one step back65 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 back100 position: fixed;More doc stylingTj Holowaychukbefore adoption87b7524
lines 101–111why, one step back101 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 back112 padding-top: 110px;More doc stylingTj Holowaychukbefore adoption87b7524
lines 113–115why, one step back113 width: 550px; }114115 #menu {Added menu to docsTj Holowaychukbefore adoptionac560be
line 116why, one step back116 margin-left: 125px;More doc stylingTj Holowaychukbefore adoption87b7524
lines 117–142why, one step back117 padding: 0;118 padding-bottom: 30px; }119 #menu li {120 display: inline;121 list-style: none; }122 #menu li a {123 display: block;124 float: left;125 margin: 0 2px;126 padding: 3px 15px;127 background: rgba(0,0,0,0.2);128 -webkit-border-radius: 8px;129 -moz-border-radius: 8px;130 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);131 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);132 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;133 -webkit-transition-duration: 0.15s;134 -webkit-transition-timing-function: ease-out; }135 #menu li a:hover,136 #menu li a.active {137 padding: 3px 20px;138 background: rgba(0,0,0,0.5); }139 #menu li a:active {140 background: rgba(0,0,0,0.1);141 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);142 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }Started new docsTj Holowaychukbefore adoption29641ae
lines 143–145why, one step back143 </style>144 </head>145 <body>More doc stylingTj Holowaychukbefore adoption87b7524
lines 146–148why, one step back146 <a href='http://github.com/visionmedia/express'> 147 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 148 </a>Started new docsTj Holowaychukbefore adoption29641ae
line 149why, one step back149 <div id="header"><strong>Sencha</strong> labs</div>Added images back to docsTj Holowaychukbefore adoption860b899
lines 150–152why, one step back150 <div id="wrapper">151 <div id="container">152 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> Added menu to docsTj Holowaychukbefore adoptionac560be
lines 153–157why, one step back153 <ul id="menu">154 <li><a href="index.html">Home</a></li>155 <li><a href="guide.html">Guide</a></li>156 <li><a href="migrate.html">1.x Migration</a></li>157 </ul>Added images back to docsTj Holowaychukbefore adoption860b899
line 158why, one step back158<div class='mp'>Added migrate doc filesTj Holowaychukbefore adoption87bb27c
lines 159–160why, one step back159<h2 id="Migration-Guide">Migration Guide</h2>160Started migration docsTj Holowaychukbefore adoption9e68a5b
line 161why, one step back161<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlwareRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 162why, one step back162framework, thus the <em>Plugin</em> has been replaced by Connect's middleware.</p>Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 163–181why, one step back163164<h3 id="Creating-Applications">Creating Applications</h3>165166<p>Previously due to legacy code implemented in the early days of node,167Express unfortunately had some globals. The DSL would previously be168accessed as shown below:</p>169170<pre><code>require('express');171172configure(function(){173 // app configuration174});175176get('/', function(){177 return 'hello world';178});179</code></pre>180181<p>Now we utilize the CommonJS module system appropriately, andRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
lines 182–183why, one step back182introduce <em>express.createServer()</em> which accepts the same arguments183as <em>http.createServer()</em>:</p>Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 184–196why, one step back184185<pre><code>var express = require('express'),186 app = express.createServer();187188app.configure(function(){189 // app configuration190});191192app.get('/', function(req, res){193 res.send('hello world');194});195</code></pre>196Docs for plugins vs middlewareTj Holowaychukbefore adoption927aae7
lines 197–209why, one step back197<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>198199<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>200201<p>Previously Express was bundled with plugins, which were essentially what202are now Connect middleware. Previously plugins would be utilized in a manor203similar to below:</p>204205<pre><code>use(Logger);206use(MethodOverride);207use(Cookie);208</code></pre>209Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 210why, one step back210<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 211–231why, one step back211212<pre><code>var connect = require('connect');213214var app = express.createServer(215 connect.logger(),216 connect.methodOverride(),217 connect.cookie()218);219</code></pre>220221<p>or:</p>222223<pre><code>var connect = require('connect');224var app = express.createServer();225226app.use('/', connect.logger());227app.use('/', connect.methodOverride());228app.use('/', connect.cookie());229</code></pre>230231<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 232why, one step back232Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 233–234why, one step back233<h3 id="Running-Applications">Running Applications</h3>234Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 235why, one step back235<p>Previously a global function <em>run()</em>, was available:</p>Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 236–239why, one step back236237<pre><code>run();238</code></pre>239Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 240why, one step back240<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,Started migration docsTj Holowaychukbefore adoption9e68a5b
lines 241–245why, one step back241so we can do things like:</p>242243<pre><code>app.listen();244app.listen(3000);245</code></pre>Added migrate doc filesTj Holowaychukbefore adoption87bb27c
line 246why, one step back246Migration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 247–248why, one step back247<h3 id="Route-Parameters">Route Parameters</h3>248Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 249why, one step back249<p>Previously we could use <em>this.param()</em> to attemptMigration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 250–256why, one step back250fetching a route, query string, or request body parameter:</p>251252<pre><code>get('/user/:id', function(){253 this.param('id');254});255</code></pre>256Migration docs for req.param()Tj Holowaychukbefore adoptiondc77894
lines 257–264why, one step back257<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>258259<pre><code>app.get('/user/:id', function(){260 req.param('id');261});262</code></pre>263264<p>Route parameters are also passed as the third argument:</p>Migration docs for paramsTj Holowaychukbefore adoptionda84c0b
lines 265–270why, one step back265266<pre><code>app.get('/user/:id', function(req, res, params){267 params.id;268});269</code></pre>270Control passing docsTj Holowaychukbefore adoption548a070
lines 271–281why, one step back271<h3 id="Passing-Route-Control">Passing Route Control</h3>272273<p>Old express had a weak notion of route passing,274which did not support async, and was never properly275implemented for practical use:</p>276277<pre><code>get('/', function(){278 this.pass('/foobar');279});280</code></pre>281Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
lines 282–283why, one step back282<p>Now Express has access to Connect's <em>next()</em> function,283which is passed as the fourth and final argument. Calling <em>next()</em> willControl passing docsTj Holowaychukbefore adoption548a070
lines 284–292why, one step back284pass control to the next <em>matching route</em>, or continue down the stack285of Connect middleware.</p>286287<pre><code>app.get('/user/:id?', function(req, res, params, next){288 next();289});290291app.get('/user', function(){292 // ... respondAdded view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 293–298why, one step back293});294</code></pre>295296<h3 id="View-Rendering">View Rendering</h3>297298<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
lines 299–300why, one step back299the <em>Content-Type</em> can be set via <em>res.contentType()</em> or300<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,Added view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 301–311why, one step back301should now be <em>layout.haml</em>.</p>302303<p>Previously a view render looked something like this:</p>304305<pre><code>get('/', function(){306 this.render('index.html.haml', {307 locals: { title: 'My Site' }308 });309});310</code></pre>311Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 312why, one step back312<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 othersAdded view rendering migration sectionTj Holowaychukbefore adoption0b86ce2
lines 313–318why, one step back313remain the same.</p>314315<pre><code>app.get('/', function(req, res){316 res.render('index.haml', {317 locals: { title: 'My Site' }318 });Control passing docsTj Holowaychukbefore adoption548a070
lines 319–321why, one step back319});320</code></pre>321Removed backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 322why, one step back322<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 323–327why, one step back323324<pre><code>this.partial('comment.html.haml', { collection: comments });325</code></pre>326327<p>Although this worked just fine, it was generally to verbose, the similar but new APIRemoved backticks from docsTj Holowaychukbefore adoptionc3f71b3
line 328why, one step back328looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>Added partial migration docsTj Holowaychukbefore adoption2a674f4
lines 329–343why, one step back329330<pre><code>partial('comment.haml', { collection: comments });331</code></pre>332333<p>To make things even less verbose we can assume the extension when ommitted:</p>334335<pre><code>partial('comment', { collection: comments });336</code></pre>337338<p>And once again even further, when rendering a collection we can simply pass339an array, if no other options are desired:</p>340341<pre><code>partial('comments', comments);342</code></pre>343Added redirect migration docsTj Holowaychukbefore adoption74432a6
lines 344–355why, one step back344<h3 id="Redirect">Redirect</h3>345346<p>Previously you would</p>347348<pre><code>this.redirect('/somewhere');349</code></pre>350351<p>However now you should use the <a href="http://extjs.github.com/Connect/redirect.html">Redirect Middleware</a>:</p>352353<pre><code>res.redirect('/somewhere');354</code></pre>355Added migrate doc filesTj Holowaychukbefore adoption87bb27c
line 356why, one step back356</div>Added images back to docsTj Holowaychukbefore adoption860b899
line 357why, one step back357 </div>Started new docsTj Holowaychukbefore adoption29641ae
lines 358–360why, one step back358 </div>359 </body>360</html>