Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

411 lines · 11.0 KiB · HTML

Last changed by

Updated docsTj Holowaychukbefore adoptiond691ecb

History of this file

Take it

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

More docsTj Holowaychukbefore adoptionde81ee7

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>

More docsTj Holowaychukbefore adoptionde81ee7

lines 17–139why, one step back
17 <style>
18 #header {19 position: absolute;20 top: 10px;21 left: 0;22 padding: 12px 0;23 text-indent: 40px;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;60 text-decoration: none;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; }128129 #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;

More docsTj Holowaychukbefore adoptionde81ee7

lines 141–253why, one step back
141 list-style: none;
142 }143 #toc li a {144 font-size: 11px;145 }146 #menu {147 margin-left: 65px;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);163 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;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> 183 <p id="tagline">184 High performance, high class web development for185 <a href="http://nodejs.org">Node.js</a>186 </p>187 <ul id="menu">188 <li><a href="index.html">Home</a></li>189 <li><a href="guide.html">Guide</a></li>190 <li><a href="contrib.html">Contributing</a></li>191 <li><a href="migrate.html">1.x Migration</a></li>192 </ul>193<div class='mp'>194<h3 id="Built-On-Connect">Built On Connect</h3>195196<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware197framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware198to Connect we allow additional community frameworks to develop robust, high-level frameworks using199the same technologies as Express.</p>200201<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, and219introduce <em>express.createServer()</em> which accepts the same arguments220as <em>http.createServer()</em>:</p>221222<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>233234<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>246247<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>248249<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()

More docsTj Holowaychukbefore adoptionde81ee7

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());

More docsTj Holowaychukbefore adoptionde81ee7

lines 266–295why, 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>269270<h3 id="Running-Applications">Running Applications</h3>271272<p>Previously a global function <em>run()</em>, was available:</p>273274<pre><code>run();275</code></pre>276277<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,278so we can do things like:</p>279280<pre><code>app.listen();281app.listen(3000);282</code></pre>283284<h3 id="Route-Parameters">Route Parameters</h3>285286<p>Previously we could use <em>this.param()</em> to attempt287fetching a route, query string, or request body parameter:</p>288289<pre><code>get('/user/:id', function(){290 this.param('id');291});292</code></pre>293294<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){

More docsTj Holowaychukbefore adoptionde81ee7

lines 297–300why, one step back
297 req.param('id');
298});299</code></pre>300

Updated docsTj Holowaychukbefore adoptiond691ecb

line 301why, one step back
301<p>Route parameters are available via <code>req.params</code>:</p>

More docsTj Holowaychukbefore adoptionde81ee7

line 302why, one step back
302

Updated docsTj Holowaychukbefore adoptiond691ecb

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

More docsTj Holowaychukbefore adoptionde81ee7

lines 305–319why, one step back
305});
306</code></pre>307308<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>318319<p>Now Express has access to Connect's <em>next()</em> function,

Updated docsTj Holowaychukbefore adoptiond691ecb

line 320why, one step back
320which is passed as the third and final argument. Calling <em>next()</em> will

More docsTj Holowaychukbefore adoptionde81ee7

lines 321–323why, one step back
321pass control to the next <em>matching route</em>, or continue down the stack
322of Connect middleware.</p>323

Updated docsTj Holowaychukbefore adoptiond691ecb

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

More docsTj Holowaychukbefore adoptionde81ee7

lines 325–369why, one step back
325 next();
326});327328app.get('/user', function(){329 // ... respond330});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>,336the <em>Content-Type</em> can be set via <em>res.contentType()</em> or337<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,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>348349<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 others350remain the same.</p>351352<pre><code>app.get('/', function(req, res){353 res.render('index.haml', {354 locals: { title: 'My Site' }355 });356});357</code></pre>358359<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>360361<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 API365looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>366367<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>

More docsTj Holowaychukbefore adoptionde81ee7

lines 371–411why, 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>380381<h3 id="Redirecting">Redirecting</h3>382383<p>Previously you would</p>384385<pre><code>this.redirect('/somewhere');386</code></pre>387388<p>However you would now:</p>389390<pre><code>res.redirect('/somewhere');391res.redirect('/somewhere', 301);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 ext405</code></pre>406407</div>408 </div>409 </div>410 </body>411</html>