Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

409 lines · 10.9 KiB · HTML

Last changed by

antialiased textTj Holowaychukbefore adoption8d80f23

History of this file

Take it

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

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

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

Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809

line 4why, one step back
4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 5–18why, one step back
5 <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;

antialiased textTj Holowaychukbefore adoption8d80f23

lines 19–20why, one step back
19 -webkit-font-smoothing: antialiased;
20 -moz-font-smoothing: antialiased;

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 21–42why, one step back
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; }42

HTTP verb docs. Closes #415Tj Holowaychukbefore adoptiond89b951

line 43why, one step back
43 h1, h2, h3, h4 {

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 44–49why, one step back
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; }

HTTP verb docs. Closes #415Tj Holowaychukbefore adoptiond89b951

lines 50–53why, one step back
50 h4 {
51 margin-left: 10px;52 font-size: 14px;53 }

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 54–74why, one step back
54
55 pre {56 margin: 20px 10px;57 padding: 25px 20px;58 background: rgba(0,0,0,0.5);59 border: 1px solid #323232;60 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);61 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);62 -webkit-border-radius: 5px;63 -moz-border-radius: 5px; }6465 code {66 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }6768 ul {69 margin: 15px 0;70 padding: 0 0 0 35px; }71 ul li {72 margin: 0;73 padding: 2px 0;74 list-style: square; }

Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809

lines 75–78why, one step back
75 ul li ul {
76 margin: 0;77 padding-left: 12px;78 }

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

line 79why, one step back
79

Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809

lines 80–81why, one step back
80 .man-name, #Express { display:none; }
81

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 82–110why, one step back
82 .sect {
83 margin-left: 40px; }8485 #logo {86 display: block;87 margin-left: 30%;88 margin-bottom: 30px;89 width: 194px;90 height: 51px;91 background: url(images/logo.png) 0 0 no-repeat;92 text-indent: -99999px; }93 #logo:hover {94 opacity: 0.7; }95 #logo:active {96 opacity: 0.3; }9798 #ribbon {99 position: fixed;100 top: 0;101 right: 0;102 z-index: 2; }103104 #wrapper {105 width: 100%;106 min-height: 800px;107 background: url(images/top.png) 0 0 repeat-x; }108109 #container {110 margin: 0 auto;

Regenerated docs againTj Holowaychukbefore adoption8ead901

line 111why, one step back
111 padding-top: 80px;

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 112–115why, one step back
112 width: 550px; }
113114 #toc {115 position: fixed;

Regenerated docs againTj Holowaychukbefore adoption8ead901

line 116why, one step back
116 top: 0;

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 117–121why, one step back
117 left: 0;
118 margin: 0 0 0 15px;119 padding: 15px;120 height: 100%;121 background: rgba(0,0,0,0.2);

Merge branch 'fix-toc'Tj Holowaychukbefore adoptionbb18f87

line 122why, one step back
122 overflow: auto;

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 123–159why, one step back
123 border-right: 1px solid rgba(255,255,255,0.05);
124 }125 #toc li {126 padding: 0;127 list-style: none;128 }129 #toc li a {130 font-size: 11px;131 }132 #menu {133 margin-left: 65px;134 padding: 0;135 padding-bottom: 30px; }136 #menu li {137 display: inline;138 list-style: none; }139 #menu li a {140 display: block;141 float: left;142 margin: 0 2px;143 padding: 3px 15px;144 background: rgba(0,0,0,0.2);145 -webkit-border-radius: 8px;146 -moz-border-radius: 8px;147 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);148 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);149 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;150 -webkit-transition-duration: 0.15s;151 -webkit-transition-timing-function: ease-out; }152 #menu li a:hover,153 #menu li a.active {154 background: rgba(0,0,0,0.5); }155 #menu li a:active {156 background: rgba(0,0,0,0.1);157 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);158 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }159 </style>

Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809

lines 160–171why, one step back
160 <script>
161 $(function(){162 $('.section').hide();163 $('.toggle, a.section-title').toggle(function(){164 $(this).siblings('ul').fadeIn(300);165 return false;166 }, function(){167 $(this).siblings('ul').fadeOut(300);168 return false;169 });170 });171 </script>

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 172–190why, one step back
172 </head>
173 <body>174 <a href='http://github.com/visionmedia/express'> 175 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 176 </a>177 <div id="wrapper">178 <div id="container">179 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 180 <p id="tagline">181 High performance, high class web development for182 <a href="http://nodejs.org">Node.js</a>183 </p>184 <ul id="menu">185 <li><a href="index.html">Home</a></li>186 <li><a href="guide.html">Guide</a></li>187 <li><a href="contrib.html">Contributing</a></li>188 <li><a href="migrate.html">1.x Migration</a></li>189 </ul>190<div class='mp'>

Merge branch 'guide'Tj Holowaychukbefore adoptionf4a0809

lines 191–194why, one step back
191<h2 id="Express">Express</h2>
192<p class="man-name">193 <code>migrate</code>194</p>

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 195–249why, one step back
195<h3 id="Built-On-Connect">Built On Connect</h3>
196197<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware198framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware199to Connect we allow additional community frameworks to develop robust, high-level frameworks using200the same technologies as Express.</p>201202<h3 id="Creating-Applications">Creating Applications</h3>203204<p>Previously due to legacy code implemented in the early days of node,205Express unfortunately had some globals. The DSL would previously be206accessed as shown below:</p>207208<pre><code>require('express');209210configure(function(){211 // app configuration212});213214get('/', function(){215 return 'hello world';216});217</code></pre>218219<p>Now we utilize the CommonJS module system appropriately, and220introduce <em>express.createServer()</em> which accepts the same arguments221as <em>http.createServer()</em>:</p>222223<pre><code>var express = require('express'),224 app = express.createServer();225226app.configure(function(){227 // app configuration228});229230app.get('/', function(req, res){231 res.send('hello world');232});233</code></pre>234235<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>236237<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>238239<p>Previously Express was bundled with plugins, which were essentially what240are now Connect middleware. Previously plugins would be utilized in a manor241similar to below:</p>242243<pre><code>use(Logger);244use(MethodOverride);245use(Cookie);246</code></pre>247248<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>249

Added app.register() docsTj Holowaychukbefore adoption77e5d8e

lines 250–253why, one step back
250<pre><code>var app = express.createServer(
251 express.logger(),252 express.methodOverride(),253 express.cookieDecoder()

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 254–258why, one step back
254);
255</code></pre>256257<p>or:</p>258

Added app.register() docsTj Holowaychukbefore adoption77e5d8e

line 259why, one step back
259<pre><code>var app = express.createServer();

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

line 260why, one step back
260

Added app.register() docsTj Holowaychukbefore adoption77e5d8e

lines 261–263why, one step back
261app.use(express.logger());
262app.use(express.methodOverride());263app.use(express.cookieDecoder());

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 264–298why, one step back
264</code></pre>
265266<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>267268<h3 id="Running-Applications">Running Applications</h3>269270<p>Previously a global function <em>run()</em>, was available:</p>271272<pre><code>run();273</code></pre>274275<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,276so we can do things like:</p>277278<pre><code>app.listen();279app.listen(3000);280</code></pre>281282<h3 id="Route-Parameters">Route Parameters</h3>283284<p>Previously we could use <em>this.param()</em> to attempt285fetching a route, query string, or request body parameter:</p>286287<pre><code>get('/user/:id', function(){288 this.param('id');289});290</code></pre>291292<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>293294<pre><code>app.get('/user/:id', function(req, res){295 req.param('id');296});297</code></pre>298

Updated docsTj Holowaychukbefore adoptiond691ecb

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

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

line 300why, one step back
300

Updated docsTj Holowaychukbefore adoptiond691ecb

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

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 303–317why, one step back
303});
304</code></pre>305306<h3 id="Passing-Route-Control">Passing Route Control</h3>307308<p>Old express had a weak notion of route passing,309which did not support async, and was never properly310implemented for practical use:</p>311312<pre><code>get('/', function(){313 this.pass('/foobar');314});315</code></pre>316317<p>Now Express has access to Connect's <em>next()</em> function,

Updated docsTj Holowaychukbefore adoptiond691ecb

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

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

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

Updated docsTj Holowaychukbefore adoptiond691ecb

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

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

lines 323–409why, one step back
323 next();
324});325326app.get('/user', function(){327 // ... respond328});329</code></pre>330331<h3 id="View-Rendering">View Rendering</h3>332333<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,334the <em>Content-Type</em> can be set via <em>res.contentType()</em> or335<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,336should now be <em>layout.haml</em>.</p>337338<p>Previously a view render looked something like this:</p>339340<pre><code>get('/', function(){341 this.render('index.html.haml', {342 locals: { title: 'My Site' }343 });344});345</code></pre>346347<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 others348remain the same.</p>349350<pre><code>app.get('/', function(req, res){351 res.render('index.haml', {352 locals: { title: 'My Site' }353 });354});355</code></pre>356357<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>358359<pre><code>this.partial('comment.html.haml', { collection: comments });360</code></pre>361362<p>Although this worked just fine, it was generally to verbose, the similar but new API363looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>364365<pre><code>partial('comment.haml', { collection: comments });366</code></pre>367368<p>To make things even less verbose we can assume the extension when omitted:</p>369370<pre><code>partial('comment', { collection: comments });371</code></pre>372373<p>And once again even further, when rendering a collection we can simply pass374an array, if no other options are desired:</p>375376<pre><code>partial('comments', comments);377</code></pre>378379<h3 id="Redirecting">Redirecting</h3>380381<p>Previously you would</p>382383<pre><code>this.redirect('/somewhere');384</code></pre>385386<p>However you would now:</p>387388<pre><code>res.redirect('/somewhere');389res.redirect('/somewhere', 301);390</code></pre>391392<h3 id="HTTP-Client">HTTP Client</h3>393394<p>Previously Express provided a high level http client, this library is no more395as it does not belong in Express, however it may be resurrected as a separate module.</p>396397<h3 id="Core-Extensions">Core Extensions</h3>398399<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 to400roll your own, or install the module via:</p>401402<pre><code>$ npm install ext403</code></pre>404405</div>406 </div>407 </div>408 </body>409</html>