migrate.html
This file
Path
docs/migrate.html
403 lines · 10.8 KiB · HTML
Last changed by
Toggling menusTj Holowaychukbefore adoption9719a24
History of this fileTake it
The walk stopped after 200 commits: lines older than c53883b point at it.
Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 1–3why, one step back1<html>2 <head>3 <title>Express - node web framework</title>Toggling menusTj Holowaychukbefore adoption9719a24
line 4why, one step back4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 5–70why, one step back5 <style>6 #tagline {7 margin-left: 75px;8 margin-bottom: 30px;9 color: rgba(255,255,255,0.7); }10 html {11 background: #1c1c1c url(images/bg.tile.jpg); }1213 body {14 margin: 0;15 padding-bottom: 30px;16 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";17 font-size: 14px;18 line-height: 1.5;19 -webkit-text-stroke: 1px rgba(0, 0, 0, 0.1);20 -moz-text-stroke: 1px rgba(0, 0, 0, 0.1);21 background: url(images/bg.jpg) 50% 0 no-repeat;22 color: #8b8b8b; }2324 * {25 outline: none; }2627 em {28 color: white; }2930 a img {31 border: none !important; }3233 a {34 font-weight: bold;35 text-decoration: none;36 color: white;37 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;38 -webkit-transition-duration: 0.15s;39 -webkit-transition-timing-function: ease-out; }40 a:hover {41 opacity: 0.8; }4243 h1, h2, h3 {44 margin: 45px 0 0 0;45 color: white;46 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }4748 h3 {49 font-size: 18px; }5051 pre {52 margin: 20px 10px;53 padding: 25px 20px;54 background: rgba(0,0,0,0.5);55 border: 1px solid #323232;56 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);57 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);58 -webkit-border-radius: 5px;59 -moz-border-radius: 5px; }6061 code {62 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }6364 ul {65 margin: 15px 0;66 padding: 0 0 0 35px; }67 ul li {68 margin: 0;69 padding: 2px 0;70 list-style: square; }Toggling menusTj Holowaychukbefore adoption9719a24
lines 71–74why, one step back71 ul li ul {72 margin: 0;73 padding-left: 12px;74 }Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 75–104why, one step back7576 .sect {77 margin-left: 40px; }7879 #logo {80 display: block;81 margin-left: 30%;82 margin-bottom: 30px;83 width: 194px;84 height: 51px;85 background: url(images/logo.png) 0 0 no-repeat;86 text-indent: -99999px; }87 #logo:hover {88 opacity: 0.7; }89 #logo:active {90 opacity: 0.3; }9192 #ribbon {93 position: fixed;94 top: 0;95 right: 0;96 z-index: 2; }9798 #wrapper {99 width: 100%;100 min-height: 800px;101 background: url(images/top.png) 0 0 repeat-x; }102103 #container {104 margin: 0 auto;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 105why, one step back105 padding-top: 80px;Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 106–109why, one step back106 width: 550px; }107108 #toc {109 position: fixed;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 110why, one step back110 top: 0;Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 111–115why, one step back111 left: 0;112 margin: 0 0 0 15px;113 padding: 15px;114 height: 100%;115 background: rgba(0,0,0,0.2);Merge branch 'fix-toc'Tj Holowaychukbefore adoptionbb18f87
line 116why, one step back116 overflow: auto;Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 117–153why, one step back117 border-right: 1px solid rgba(255,255,255,0.05);118 }119 #toc li {120 padding: 0;121 list-style: none;122 }123 #toc li a {124 font-size: 11px;125 }126 #menu {127 margin-left: 65px;128 padding: 0;129 padding-bottom: 30px; }130 #menu li {131 display: inline;132 list-style: none; }133 #menu li a {134 display: block;135 float: left;136 margin: 0 2px;137 padding: 3px 15px;138 background: rgba(0,0,0,0.2);139 -webkit-border-radius: 8px;140 -moz-border-radius: 8px;141 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);142 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);143 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;144 -webkit-transition-duration: 0.15s;145 -webkit-transition-timing-function: ease-out; }146 #menu li a:hover,147 #menu li a.active {148 background: rgba(0,0,0,0.5); }149 #menu li a:active {150 background: rgba(0,0,0,0.1);151 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);152 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }153 </style>Toggling menusTj Holowaychukbefore adoption9719a24
lines 154–165why, one step back154 <script>155 $(function(){156 $('.section').hide();157 $('.toggle, a.section-title').toggle(function(){158 $(this).siblings('ul').fadeIn(300);159 return false;160 }, function(){161 $(this).siblings('ul').fadeOut(300);162 return false;163 });164 });165 </script>Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 166–184why, one step back166 </head>167 <body>168 <a href='http://github.com/visionmedia/express'> 169 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 170 </a>171 <div id="wrapper">172 <div id="container">173 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 174 <p id="tagline">175 High performance, high class web development for176 <a href="http://nodejs.org">Node.js</a>177 </p>178 <ul id="menu">179 <li><a href="index.html">Home</a></li>180 <li><a href="guide.html">Guide</a></li>181 <li><a href="contrib.html">Contributing</a></li>182 <li><a href="migrate.html">1.x Migration</a></li>183 </ul>184<div class='mp'>Toggling menusTj Holowaychukbefore adoption9719a24
lines 185–188why, one step back185<h2 id="Express">Express</h2>186<p class="man-name">187 <code>migrate</code>188</p>Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 189–243why, one step back189<h3 id="Built-On-Connect">Built On Connect</h3>190191<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware192framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware193to Connect we allow additional community frameworks to develop robust, high-level frameworks using194the same technologies as Express.</p>195196<h3 id="Creating-Applications">Creating Applications</h3>197198<p>Previously due to legacy code implemented in the early days of node,199Express unfortunately had some globals. The DSL would previously be200accessed as shown below:</p>201202<pre><code>require('express');203204configure(function(){205 // app configuration206});207208get('/', function(){209 return 'hello world';210});211</code></pre>212213<p>Now we utilize the CommonJS module system appropriately, and214introduce <em>express.createServer()</em> which accepts the same arguments215as <em>http.createServer()</em>:</p>216217<pre><code>var express = require('express'),218 app = express.createServer();219220app.configure(function(){221 // app configuration222});223224app.get('/', function(req, res){225 res.send('hello world');226});227</code></pre>228229<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>230231<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>232233<p>Previously Express was bundled with plugins, which were essentially what234are now Connect middleware. Previously plugins would be utilized in a manor235similar to below:</p>236237<pre><code>use(Logger);238use(MethodOverride);239use(Cookie);240</code></pre>241242<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>243Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 244–247why, one step back244<pre><code>var app = express.createServer(245 express.logger(),246 express.methodOverride(),247 express.cookieDecoder()Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 248–252why, one step back248);249</code></pre>250251<p>or:</p>252Added app.register() docsTj Holowaychukbefore adoption77e5d8e
line 253why, one step back253<pre><code>var app = express.createServer();Docs for session exampleTj Holowaychukbefore adoptionc53883b
line 254why, one step back254Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 255–257why, one step back255app.use(express.logger());256app.use(express.methodOverride());257app.use(express.cookieDecoder());Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 258–292why, one step back258</code></pre>259260<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>261262<h3 id="Running-Applications">Running Applications</h3>263264<p>Previously a global function <em>run()</em>, was available:</p>265266<pre><code>run();267</code></pre>268269<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,270so we can do things like:</p>271272<pre><code>app.listen();273app.listen(3000);274</code></pre>275276<h3 id="Route-Parameters">Route Parameters</h3>277278<p>Previously we could use <em>this.param()</em> to attempt279fetching a route, query string, or request body parameter:</p>280281<pre><code>get('/user/:id', function(){282 this.param('id');283});284</code></pre>285286<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>287288<pre><code>app.get('/user/:id', function(req, res){289 req.param('id');290});291</code></pre>292Updated docsTj Holowaychukbefore adoptiond691ecb
line 293why, one step back293<p>Route parameters are available via <code>req.params</code>:</p>Docs for session exampleTj Holowaychukbefore adoptionc53883b
line 294why, one step back294Updated docsTj Holowaychukbefore adoptiond691ecb
lines 295–296why, one step back295<pre><code>app.get('/user/:id', function(req, res){296 req.params.id;Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 297–311why, one step back297});298</code></pre>299300<h3 id="Passing-Route-Control">Passing Route Control</h3>301302<p>Old express had a weak notion of route passing,303which did not support async, and was never properly304implemented for practical use:</p>305306<pre><code>get('/', function(){307 this.pass('/foobar');308});309</code></pre>310311<p>Now Express has access to Connect's <em>next()</em> function,Updated docsTj Holowaychukbefore adoptiond691ecb
line 312why, one step back312which is passed as the third and final argument. Calling <em>next()</em> willDocs for session exampleTj Holowaychukbefore adoptionc53883b
lines 313–315why, one step back313pass control to the next <em>matching route</em>, or continue down the stack314of Connect middleware.</p>315Updated docsTj Holowaychukbefore adoptiond691ecb
line 316why, one step back316<pre><code>app.get('/user/:id?', function(req, res, next){Docs for session exampleTj Holowaychukbefore adoptionc53883b
lines 317–403why, one step back317 next();318});319320app.get('/user', function(){321 // ... respond322});323</code></pre>324325<h3 id="View-Rendering">View Rendering</h3>326327<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,328the <em>Content-Type</em> can be set via <em>res.contentType()</em> or329<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,330should now be <em>layout.haml</em>.</p>331332<p>Previously a view render looked something like this:</p>333334<pre><code>get('/', function(){335 this.render('index.html.haml', {336 locals: { title: 'My Site' }337 });338});339</code></pre>340341<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 others342remain the same.</p>343344<pre><code>app.get('/', function(req, res){345 res.render('index.haml', {346 locals: { title: 'My Site' }347 });348});349</code></pre>350351<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>352353<pre><code>this.partial('comment.html.haml', { collection: comments });354</code></pre>355356<p>Although this worked just fine, it was generally to verbose, the similar but new API357looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>358359<pre><code>partial('comment.haml', { collection: comments });360</code></pre>361362<p>To make things even less verbose we can assume the extension when omitted:</p>363364<pre><code>partial('comment', { collection: comments });365</code></pre>366367<p>And once again even further, when rendering a collection we can simply pass368an array, if no other options are desired:</p>369370<pre><code>partial('comments', comments);371</code></pre>372373<h3 id="Redirecting">Redirecting</h3>374375<p>Previously you would</p>376377<pre><code>this.redirect('/somewhere');378</code></pre>379380<p>However you would now:</p>381382<pre><code>res.redirect('/somewhere');383res.redirect('/somewhere', 301);384</code></pre>385386<h3 id="HTTP-Client">HTTP Client</h3>387388<p>Previously Express provided a high level http client, this library is no more389as it does not belong in Express, however it may be resurrected as a separate module.</p>390391<h3 id="Core-Extensions">Core Extensions</h3>392393<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 to394roll your own, or install the module via:</p>395396<pre><code>$ npm install ext397</code></pre>398399</div>400 </div>401 </div>402 </body>403</html>