migrate.html
This file
Path
docs/migrate.html
382 lines · 10.3 KiB · HTML
Last changed by
Merge branch 'fix-toc'Tj Holowaychukbefore adoptionbb18f87
History of this fileTake it
The walk stopped after 200 commits: lines older than 5279ade point at it.
Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 1–99why, one step back1<html>2 <head>3 <title>Express - node web framework</title>4 <style>5 #tagline {6 margin-left: 75px;7 margin-bottom: 30px;8 color: rgba(255,255,255,0.7); }9 html {10 background: #1c1c1c url(images/bg.tile.jpg); }1112 body {13 margin: 0;14 padding-bottom: 30px;15 font: 14px/1.4 "Helvetica Neue", "Lucida Grande", "Arial";16 font-size: 14px;17 line-height: 1.5;18 -webkit-text-stroke: 1px rgba(0, 0, 0, 0.1);19 -moz-text-stroke: 1px rgba(0, 0, 0, 0.1);20 background: url(images/bg.jpg) 50% 0 no-repeat;21 color: #8b8b8b; }2223 * {24 outline: none; }2526 em {27 color: white; }2829 a img {30 border: none !important; }3132 a {33 font-weight: bold;34 text-decoration: none;35 color: white;36 -webkit-transition-property: opacity, -webkit-transform, color, background-color, padding, -webkit-box-shadow;37 -webkit-transition-duration: 0.15s;38 -webkit-transition-timing-function: ease-out; }39 a:hover {40 opacity: 0.8; }4142 h1, h2, h3 {43 margin: 45px 0 0 0;44 color: white;45 text-shadow: 1px 2px 2px rgba(0,0,0,0.6); }4647 h3 {48 font-size: 18px; }4950 pre {51 margin: 20px 10px;52 padding: 25px 20px;53 background: rgba(0,0,0,0.5);54 border: 1px solid #323232;55 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);56 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);57 -webkit-border-radius: 5px;58 -moz-border-radius: 5px; }5960 code {61 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }6263 ul {64 margin: 15px 0;65 padding: 0 0 0 35px; }66 ul li {67 margin: 0;68 padding: 2px 0;69 list-style: square; }7071 .sect {72 margin-left: 40px; }7374 #logo {75 display: block;76 margin-left: 30%;77 margin-bottom: 30px;78 width: 194px;79 height: 51px;80 background: url(images/logo.png) 0 0 no-repeat;81 text-indent: -99999px; }82 #logo:hover {83 opacity: 0.7; }84 #logo:active {85 opacity: 0.3; }8687 #ribbon {88 position: fixed;89 top: 0;90 right: 0;91 z-index: 2; }9293 #wrapper {94 width: 100%;95 min-height: 800px;96 background: url(images/top.png) 0 0 repeat-x; }9798 #container {99 margin: 0 auto;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 100why, one step back100 padding-top: 80px;Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 101–104why, one step back101 width: 550px; }102103 #toc {104 position: fixed;Regenerated docs againTj Holowaychukbefore adoption8ead901
line 105why, one step back105 top: 0;Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 106–110why, one step back106 left: 0;107 margin: 0 0 0 15px;108 padding: 15px;109 height: 100%;110 background: rgba(0,0,0,0.2);Merge branch 'fix-toc'Tj Holowaychukbefore adoptionbb18f87
line 111why, one step back111 overflow: auto;Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 112–114why, one step back112 border-right: 1px solid rgba(255,255,255,0.05);113 }114 #toc li {More view docsTj Holowaychukbefore adoption1c8ff48
line 115why, one step back115 padding: 0;Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 116–222why, one step back116 list-style: none;117 }118 #toc li a {119 font-size: 11px;120 }121 #menu {122 margin-left: 65px;123 padding: 0;124 padding-bottom: 30px; }125 #menu li {126 display: inline;127 list-style: none; }128 #menu li a {129 display: block;130 float: left;131 margin: 0 2px;132 padding: 3px 15px;133 background: rgba(0,0,0,0.2);134 -webkit-border-radius: 8px;135 -moz-border-radius: 8px;136 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);137 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);138 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;139 -webkit-transition-duration: 0.15s;140 -webkit-transition-timing-function: ease-out; }141 #menu li a:hover,142 #menu li a.active {143 background: rgba(0,0,0,0.5); }144 #menu li a:active {145 background: rgba(0,0,0,0.1);146 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);147 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }148 </style>149 </head>150 <body>151 <a href='http://github.com/visionmedia/express'> 152 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 153 </a>154 <div id="wrapper">155 <div id="container">156 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 157 <p id="tagline">158 High performance, high class web development for159 <a href="http://nodejs.org">Node.js</a>160 </p>161 <ul id="menu">162 <li><a href="index.html">Home</a></li>163 <li><a href="guide.html">Guide</a></li>164 <li><a href="contrib.html">Contributing</a></li>165 <li><a href="migrate.html">1.x Migration</a></li>166 </ul>167<div class='mp'>168<h3 id="Built-On-Connect">Built On Connect</h3>169170<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware171framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware172to Connect we allow additional community frameworks to develop robust, high-level frameworks using173the same technologies as Express.</p>174175<h3 id="Creating-Applications">Creating Applications</h3>176177<p>Previously due to legacy code implemented in the early days of node,178Express unfortunately had some globals. The DSL would previously be179accessed as shown below:</p>180181<pre><code>require('express');182183configure(function(){184 // app configuration185});186187get('/', function(){188 return 'hello world';189});190</code></pre>191192<p>Now we utilize the CommonJS module system appropriately, and193introduce <em>express.createServer()</em> which accepts the same arguments194as <em>http.createServer()</em>:</p>195196<pre><code>var express = require('express'),197 app = express.createServer();198199app.configure(function(){200 // app configuration201});202203app.get('/', function(req, res){204 res.send('hello world');205});206</code></pre>207208<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>209210<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>211212<p>Previously Express was bundled with plugins, which were essentially what213are now Connect middleware. Previously plugins would be utilized in a manor214similar to below:</p>215216<pre><code>use(Logger);217use(MethodOverride);218use(Cookie);219</code></pre>220221<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>222Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 223–226why, one step back223<pre><code>var app = express.createServer(224 express.logger(),225 express.methodOverride(),226 express.cookieDecoder()Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 227–231why, one step back227);228</code></pre>229230<p>or:</p>231Added app.register() docsTj Holowaychukbefore adoption77e5d8e
line 232why, one step back232<pre><code>var app = express.createServer();Added more req.flash() testsTj Holowaychukbefore adoption5279ade
line 233why, one step back233Added app.register() docsTj Holowaychukbefore adoption77e5d8e
lines 234–236why, one step back234app.use(express.logger());235app.use(express.methodOverride());236app.use(express.cookieDecoder());Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 237–266why, one step back237</code></pre>238239<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>240241<h3 id="Running-Applications">Running Applications</h3>242243<p>Previously a global function <em>run()</em>, was available:</p>244245<pre><code>run();246</code></pre>247248<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,249so we can do things like:</p>250251<pre><code>app.listen();252app.listen(3000);253</code></pre>254255<h3 id="Route-Parameters">Route Parameters</h3>256257<p>Previously we could use <em>this.param()</em> to attempt258fetching a route, query string, or request body parameter:</p>259260<pre><code>get('/user/:id', function(){261 this.param('id');262});263</code></pre>264265<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>266Fixed migration typoTj Holowaychukbefore adoptiona9c3f56
line 267why, one step back267<pre><code>app.get('/user/:id', function(req, res){Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 268–271why, one step back268 req.param('id');269});270</code></pre>271Updated docsTj Holowaychukbefore adoptiond691ecb
line 272why, one step back272<p>Route parameters are available via <code>req.params</code>:</p>Added more req.flash() testsTj Holowaychukbefore adoption5279ade
line 273why, one step back273Updated docsTj Holowaychukbefore adoptiond691ecb
lines 274–275why, one step back274<pre><code>app.get('/user/:id', function(req, res){275 req.params.id;Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 276–290why, one step back276});277</code></pre>278279<h3 id="Passing-Route-Control">Passing Route Control</h3>280281<p>Old express had a weak notion of route passing,282which did not support async, and was never properly283implemented for practical use:</p>284285<pre><code>get('/', function(){286 this.pass('/foobar');287});288</code></pre>289290<p>Now Express has access to Connect's <em>next()</em> function,Updated docsTj Holowaychukbefore adoptiond691ecb
line 291why, one step back291which is passed as the third and final argument. Calling <em>next()</em> willAdded more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 292–294why, one step back292pass control to the next <em>matching route</em>, or continue down the stack293of Connect middleware.</p>294Updated docsTj Holowaychukbefore adoptiond691ecb
line 295why, one step back295<pre><code>app.get('/user/:id?', function(req, res, next){Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 296–382why, one step back296 next();297});298299app.get('/user', function(){300 // ... respond301});302</code></pre>303304<h3 id="View-Rendering">View Rendering</h3>305306<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,307the <em>Content-Type</em> can be set via <em>res.contentType()</em> or308<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,309should now be <em>layout.haml</em>.</p>310311<p>Previously a view render looked something like this:</p>312313<pre><code>get('/', function(){314 this.render('index.html.haml', {315 locals: { title: 'My Site' }316 });317});318</code></pre>319320<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 others321remain the same.</p>322323<pre><code>app.get('/', function(req, res){324 res.render('index.haml', {325 locals: { title: 'My Site' }326 });327});328</code></pre>329330<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>331332<pre><code>this.partial('comment.html.haml', { collection: comments });333</code></pre>334335<p>Although this worked just fine, it was generally to verbose, the similar but new API336looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>337338<pre><code>partial('comment.haml', { collection: comments });339</code></pre>340341<p>To make things even less verbose we can assume the extension when omitted:</p>342343<pre><code>partial('comment', { collection: comments });344</code></pre>345346<p>And once again even further, when rendering a collection we can simply pass347an array, if no other options are desired:</p>348349<pre><code>partial('comments', comments);350</code></pre>351352<h3 id="Redirecting">Redirecting</h3>353354<p>Previously you would</p>355356<pre><code>this.redirect('/somewhere');357</code></pre>358359<p>However you would now:</p>360361<pre><code>res.redirect('/somewhere');362res.redirect('/somewhere', 301);363</code></pre>364365<h3 id="HTTP-Client">HTTP Client</h3>366367<p>Previously Express provided a high level http client, this library is no more368as it does not belong in Express, however it may be resurrected as a separate module.</p>369370<h3 id="Core-Extensions">Core Extensions</h3>371372<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 to373roll your own, or install the module via:</p>374375<pre><code>$ npm install ext376</code></pre>377378</div>379 </div>380 </div>381 </body>382</html>