Skip to content
Myr

migrate.html

This file

Path

docs/migrate.html

360 lines · 10.5 KiB · HTML

Last changed by

docsTj Holowaychukbefore adoption2bb0412

History of this file

Take it

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

Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b

lines 1–135why, one step back
1<html>
2 <head>3 <title>Express - node web framework</title>4 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>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;19 -webkit-font-smoothing: antialiased;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, h4 {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; }49 h4 {50 margin-left: 10px;51 font-size: 14px;52 }5354 pre {55 margin: 20px 10px;56 padding: 25px 20px;57 background: rgba(0,0,0,0.5);58 border: 1px solid #323232;59 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);60 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);61 -webkit-border-radius: 5px;62 -moz-border-radius: 5px; }6364 code {65 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; }6667 ul {68 margin: 15px 0;69 padding: 0 0 0 35px; }70 ul li {71 margin: 0;72 padding: 2px 0;73 list-style: square; }74 ul li ul {75 margin: 0;76 padding-left: 12px;77 }7879 .man-name, #Express { display:none; }8081 .sect {82 margin-left: 40px; }83 img {84 margin-left: 20px;85 margin-bottom: 15px;86 }8788 #logo {89 display: block;90 margin-left: 30%;91 margin-bottom: 30px;92 width: 194px;93 height: 51px;94 background: url(images/logo.png) 0 0 no-repeat;95 text-indent: -99999px; }96 #logo:hover {97 opacity: 0.7; }98 #logo:active {99 opacity: 0.3; }100101 #ribbon {102 position: fixed;103 top: 0;104 right: 0;105 z-index: 2; }106107 #wrapper {108 width: 100%;109 min-height: 800px;110 background: url(images/top.png) 0 0 repeat-x; }111112 #container {113 margin: 0 auto;114 padding-top: 80px;115 width: 550px; }116117 #toc {118 position: fixed;119 top: 0;120 left: 0;121 margin: 0 0 0 15px;122 padding: 15px;123 height: 100%;124 background: rgba(0,0,0,0.2);125 overflow: auto;126 border-right: 1px solid rgba(255,255,255,0.05);127 }128 #toc li {129 padding: 0;130 list-style: none;131 }132 #toc li a {133 font-size: 11px;134 }135 #menu {

Regenerated docsTj Holowaychukbefore adoptiond3abcaf

line 136why, one step back
136 margin-left: 75px;

Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b

lines 137–189why, one step back
137 padding: 0;
138 padding-bottom: 30px; }139 #menu li {140 display: inline;141 list-style: none; }142 #menu li a {143 display: block;144 float: left;145 margin: 0 2px;146 padding: 3px 15px;147 background: rgba(0,0,0,0.2);148 -webkit-border-radius: 8px;149 -moz-border-radius: 8px;150 -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);151 -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.6);152 -webkit-transition-property: opacity, -webkit-transform, color, background-color, -webkit-box-shadow;153 -webkit-transition-duration: 0.15s;154 -webkit-transition-timing-function: ease-out; }155 #menu li a:hover,156 #menu li a.active {157 background: rgba(0,0,0,0.5); }158 #menu li a:active {159 background: rgba(0,0,0,0.1);160 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.4);161 -moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.4); }162 </style>163 <script>164 $(function(){165 $('.section').hide();166 $('.toggle, a.section-title').toggle(function(){167 $(this).siblings('ul').fadeIn(300);168 return false;169 }, function(){170 $(this).siblings('ul').fadeOut(300);171 return false;172 });173 });174 </script>175 </head>176 <body>177 <a href='http://github.com/visionmedia/express'> 178 <img alt='Fork me on GitHub' id='ribbon' src='http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png' /> 179 </a>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>

Added screencasts pageTj Holowaychukbefore adoption4144af3

line 190why, one step back
190 <li><a href="screencasts.html">Screencasts</a></li>

Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b

lines 191–197why, one step back
191 <li><a href="applications.html">Applications</a></li>
192 </ul>193<div class='mp'>194<h2 id="Express">Express</h2>195<p class="man-name">196 <code>migrate</code>197</p>

docsTj Holowaychukbefore adoption4609984

line 198why, one step back
198<h3 id="Express-1-x-to-2-x-Migration">Express 1.x to 2.x Migration</h3>

Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b

line 199why, one step back
199

docsTj Holowaychukbefore adoptionc1a82bf

lines 200–242why, one step back
200<h3 id="HTTPS">HTTPS</h3>
201202<p> Creating an HTTPS server is simply, simply pass the TLS options to <em>express.createServer()</em>:</p>203204<pre><code> var app = express.createServer({205 key: ...206 , cert: ...207 });208209 app.listen(443);210</code></pre>211212<h3 id="req-header-Referrer">req.header() Referrer</h3>213214<p> Previously if anyone was doing something similar to:</p>215216<pre><code> req.headers.referrer || req.headers.referer217 req.header('Referrer') || req.header('Referer')218</code></pre>219220<p> With the new special-case we may now simply use <em>Referrer</em> which will return either if defined:</p>221222<pre><code> req.header('Referrer')223</code></pre>224225<h3 id="res-local-name-val-">res.local(name, val)</h3>226227<p> Previously all local variables had to be passed to <em>res.render()</em>, or either <em>app.helpers()</em> or <em>app.dynamicHelpers()</em>, now we may do this at the request-level progressively. The <em>res.local()</em> method accepts a <em>name</em> and <em>val</em>, however the locals passed to <em>res.render()</em> will take precedence.</p>228229<p> For example we may utilize this feature to create locals in middleware:</p>230231<pre><code> function loadUser(req, res, next) {232 User.get(req.params.id, function(err, user){233 res.local('user', user);234 next();235 });236 }237238 app.get('/user/:id', loadUser, function(req, res){239 res.render('user');240 });241</code></pre>242

docsTj Holowaychukbefore adoption1db2efa

lines 243–279why, one step back
243<h3 id="req-param-name-defaultValue-">req.param(name[, defaultValue])</h3>
244245<p> Previously only <em>name</em> was accepted, so some of you may have been doing the following:</p>246247<pre><code> var id = req.param('id') || req.user.id;248</code></pre>249250<p> The new <em>defaultValue</em> argument can handle this nicely:</p>251252<pre><code> var id = req.param('id', req.user.id);253</code></pre>254255<h3 id="app-helpers-app-locals-">app.helpers() / app.locals()</h3>256257<p> <em>app.locals()</em> is now an alias of <em>app.helpers()</em>, as helpers makes more sense for functions.</p>258259<h3 id="req-accepts-type-">req.accepts(type)</h3>260261<p> <em>req.accepts()</em> now accepts extensions:</p>262263<pre><code> // Accept: text/html264 req.accepts('html');265 req.accepts('.html');266 // =&gt; true267268 // Accept: text/*; application/json269 req.accepts('html');270 req.accepts('text/*');271 req.accepts('text/plain');272 req.accepts('application/json');273 // =&gt; true274275 req.accepts('image/png');276 req.accepts('png');277 // =&gt; false278</code></pre>279

docsTj Holowaychukbefore adoption131970b

lines 280–283why, one step back
280<h3 id="res-cookie-">res.cookie()</h3>
281282<p> Previously only directly values could be passed, so for example:</p>283

docs for res.render() and res.partial()Tj Holowaychukbefore adoption07ce5d3

line 284why, one step back
284<pre><code>res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000) });

docsTj Holowaychukbefore adoption131970b

lines 285–291why, one step back
285</code></pre>
286287<p>However now we have the alternative <em>maxAge</em> property which may be used to set <em>expires</em> relative to <em>Date.now()</em> in milliseconds, so our example above can now become:</p>288289<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });290</code></pre>291

docsTj Holowaychukbefore adoption1db2efa

lines 292–308why, one step back
292<h3 id="res-download-res-sendfile-">res.download() / res.sendfile()</h3>
293294<p> Both of these methods now utilize Connect's static file server behind the scenes (actually the previous Express code was ported to Connect 1.0). With this change comes a change to the callback as well. Previously the <em>path</em> and <em>stream</em> were passed, however now only an <em>error</em> is passed, when no error has occurred the callback will be invoked indicating that the file transfer is complete. The callback remains optional:</p>295296<pre><code> res.download('/path/to/file');297298 res.download('/path/to/file', function(err){299 if (err) {300 console.error(err);301 } else {302 console.log('transferred');303 }304 });305</code></pre>306307<p> The <em>stream threshold</em> setting was removed.</p>308

docsTj Holowaychukbefore adoption2bb0412

lines 309–332why, one step back
309<h3 id="res-render-">res.render()</h3>
310311<p> Previously locals were passed as a separate key:</p>312313<pre><code> res.render('user', { layout: false, locals: { user: user }});314</code></pre>315316<p> In Express 2.0 both the locals and the options are one in the same, meaning you cannot have a local variable named <em>layout</em> as it is reserved for express, however this cleans up the API:</p>317318<pre><code> res.render('user', { layout: false, user: user });319</code></pre>320321<h3 id="res-partial-">res.partial()</h3>322323<p> Express 2.0 adds the <em>res.partial()</em> method, helpful for rendering partial fragments over WebSockets or Ajax requests etc. The API is identical to the <em>partial()</em> calls within views.</p>324325<pre><code> // render a collection of comments326 res.partial('comment', [comment1, comment2]); 327328 // render a single comment329 res.partial('comment', comment);330</code></pre>331332<h3 id="Template-Engine-Compliance">Template Engine Compliance</h3>

docsTj Holowaychukbefore adoption1db2efa

lines 333–346why, one step back
333
334<p> To comply with Express previously engines needed the following signature:</p>335336<pre><code> engine.render(str, options, function(err){});337</code></pre>338339<p> Now they must export a <em>compile()</em> function, returning a function which when called with local variables will render the template. This allows Express to cache the compiled function in memory during production.</p>340341<pre><code> var fn = engine.compile(str, options);342 fn(locals);343</code></pre>344345<h3 id="View-Partial-Lookup">View Partial Lookup</h3>346

docsTj Holowaychukbefore adoption5581ca2

line 347why, one step back
347<p> Previously partials were loaded relative to the now removed <em>view partials</em> directory setting, or by default <em>views/partials</em>, now they are relative to the view calling them, read more on <a href="guide.html#View-Lookup">view lookup</a>.</p>

docsTj Holowaychukbefore adoption1db2efa

lines 348–355why, one step back
348
349<h3 id="Mime-Types">Mime Types</h3>350351<p> Express and Connect now utilize the <em>mime</em> module in npm, so to add more use:</p>352353<pre><code> require('mime').define({ 'foo/bar': ['foo', 'bar'] });354</code></pre>355

Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b

lines 356–360why, one step back
356</div>
357 </div>358 </div>359 </body>360</html>