Skip to content
Myr

docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 022c5e1 · Browse files · 6 files+11 added−737 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+11 added−737 removed

  • other:+11 added−737 removed

6 files+11 added−737 removed

modified:docs/guide.1+3 added
965 unmodified lines
966.967.IP "" 0968.969.P970Local variables passed (or generated) take precedence, however locals passed to the parent view are available in the child view as well\. So for example if we were to render a blog post with \fIpartial(\'blog/post\', post)\fR it would generate the \fIpost\fR local, but the view calling this function had the local \fIuser\fR, it would be available to the \fIblog/post\fR view as well\.971.972.P973For documentation on altering the object name view res\.partial() \fIhttp://expressjs\.com/guide\.html#res\-partial\-view\-options\-\fR\.974.975.P976\fBNOTE:\fR be careful about when you use partial collections, as rendering an array with a length of 100 means we have to render 100 views\. For simple collections you may inline the iteration instead of using partial collection support to decrease overhead\.
1110 unmodified lines
modified:docs/guide.html+2 added
846 unmodified lines
847<li><em>collectionLength</em> length of the collection</li>848</ul>849850851<p>Local variables passed (or generated) take precedence, however locals passed to the parent view are available in the child view as well. So for example if we were to render a blog post with <em>partial('blog/post', post)</em> it would generate the <em>post</em> local, but the view calling this function had the local <em>user</em>, it would be available to the <em>blog/post</em> view as well.</p>852853<p>For documentation on altering the object name view <a href="http://expressjs.com/guide.html#res-partial-view-options-">res.partial()</a>.</p>854855<p><strong>NOTE:</strong> be careful about when you use partial collections, as rendering an array with a length of 100 means we have to render 100 views. For simple collections you may inline the iteration instead of using partial collection support to decrease overhead.</p>856
710 unmodified lines
modified:docs/guide.md+2 added-2 removed
600 unmodified lines
601 });602603The _req.session_ object also has methods such as _Session#touch()_, _Session#destroy()_, _Session#regenerate()_ among others to maintain and manipulate sessions. For more information view the [Connect Session](http://senchalabs.github.com/connect/middleware-session.html) documentation.604605### Migration Guide605### 2.x Migration Guide606607 Express 1.x developers may reference the [Migration Guide](migrate.html) to get up to speed on how to upgrade your application.607 Express 1.x developers may reference the [Migration Guide](migrate.html) to get up to speed on how to upgrade your application to work with Express 2.x, Connect 1.x, and Node 0.4.x.608609### req.header(key[, defaultValue])610611Get the case-insensitive request header _key_, with optional _defaultValue_:
566 unmodified lines
modified:docs/migrate.1+2 added-339 removed
1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "MIGRATE" "" "October 2010" "" ""4.TH "MIGRATE" "" "March 2011" "" ""5.6.SH "NAME"7\fBmigrate\fR8.9.SS "Built On Connect"10Express 1\.x is written to run on\-top of the Connect \fIhttp://extjs\.github\.com/Connect\fR middlware framework, thus the \fIPlugin\fR has been replaced by Connect\'s middleware\. By abstracting our middleware to Connect we allow additional community frameworks to develop robust, high\-level frameworks using the same technologies as Express\.11.12.SS "Creating Applications"13Previously due to legacy code implemented in the early days of node, Express unfortunately had some globals\. The DSL would previously be accessed as shown below:14.15.IP "" 416.17.nf9.SS "Express 1\.x to 2\.x Migration"1019require(\'express\');2021configure(function(){22 // app configuration23});2425get(\'/\', function(){26 return \'hello world\';27});28.29.fi30.31.IP "" 032.33.P34Now we utilize the CommonJS module system appropriately, and introduce \fIexpress\.createServer()\fR which accepts the same arguments as \fIhttp\.createServer()\fR:35.36.IP "" 437.38.nf3940var express = require(\'express\'),41 app = express\.createServer();4243app\.configure(function(){44 // app configuration45});4647app\.get(\'/\', function(req, res){48 res\.send(\'hello world\');49});50.51.fi52.53.IP "" 054.55.P56Express 1\.x does \fInot\fR currently allow returning of a string\.57.58.SS "Plugins vs Middleware"59Previously Express was bundled with plugins, which were essentially what are now Connect middleware\. Previously plugins would be utilized in a manor similar to below:60.61.IP "" 462.63.nf6465use(Logger);66use(MethodOverride);67use(Cookie);68.69.fi70.71.IP "" 072.73.P74Which we can now \fIuse()\fR within our app, or pass to the \fIexpress\.createServer()\fR method:75.76.IP "" 477.78.nf7980var app = express\.createServer(81 express\.logger(),82 express\.methodOverride(),83 express\.cookieDecoder()84);85.86.fi87.88.IP "" 089.90.P91or:92.93.IP "" 494.95.nf9697var app = express\.createServer();9899app\.use(express\.logger());100app\.use(express\.methodOverride());101app\.use(express\.cookieDecoder());102.103.fi104.105.IP "" 0106.107.P108For documentation on creating Connect middleware visit Middleware Authoring \fIhttp://extjs\.github\.com/Connect/#Middleware\-Authoring\fR\.109.110.SS "Running Applications"111Previously a global function \fIrun()\fR, was available:112.113.IP "" 4114.115.nf116117run();118.119.fi120.121.IP "" 0122.123.P124The new \fIexpress\.Server\fR has the same API as \fIhttp\.Server\fR, so we can do things like:125.126.IP "" 4127.128.nf129130app\.listen();131app\.listen(3000);132.133.fi134.135.IP "" 0136.137.SS "Route Parameters"138Previously we could use \fIthis\.param()\fR to attempt fetching a route, query string, or request body parameter:139.140.IP "" 4141.142.nf143144get(\'/user/:id\', function(){145 this\.param(\'id\');146});147.148.fi149.150.IP "" 0151.152.P153Polymorphic parameter access can be done using \fBreq\.param()\fR:154.155.IP "" 4156.157.nf158159app\.get(\'/user/:id\', function(req, res){160 req\.param(\'id\');161});162.163.fi164.165.IP "" 0166.167.P168Route parameters are available via \fBreq\.params\fR:169.170.IP "" 4171.172.nf173174app\.get(\'/user/:id\', function(req, res){175 req\.params\.id;176});177.178.fi179.180.IP "" 0181.182.SS "Passing Route Control"183Old express had a weak notion of route passing, which did not support async, and was never properly implemented for practical use:184.185.IP "" 4186.187.nf188189get(\'/\', function(){190 this\.pass(\'/foobar\');191});192.193.fi194.195.IP "" 0196.197.P198Now Express has access to Connect\'s \fInext()\fR function, which is passed as the third and final argument\. Calling \fInext()\fR will pass control to the next \fImatching route\fR, or continue down the stack of Connect middleware\.199.200.IP "" 4201.202.nf203204app\.get(\'/user/:id?\', function(req, res, next){205 next();206});207208app\.get(\'/user\', function(){209 // \.\.\. respond210});211.212.fi213.214.IP "" 0215.216.SS "View Rendering"217View filenames no longer take the form \fINAME\fR\.\fITYPE\fR\.\fIENGINE\fR, the \fIContent\-Type\fR can be set via \fIres\.contentType()\fR or \fIres\.header()\fR\. For example what was previously \fIlayout\.html\.haml\fR, should now be \fIlayout\.haml\fR\.218.219.P220Previously a view render looked something like this:221.222.IP "" 4223.224.nf225226get(\'/\', function(){227 this\.render(\'index\.html\.haml\', {228 locals: { title: \'My Site\' }229 });230});231.232.fi233.234.IP "" 0235.236.P237We now have \fIres\.render()\fR, however the options passed to haml \fIhttp://github\.com/visionmedia/haml\.js\fR, jade \fIhttp://github\.com/visionmedia/jade\fR, and others remain the same\.238.239.IP "" 4240.241.nf242243app\.get(\'/\', function(req, res){244 res\.render(\'index\.haml\', {245 locals: { title: \'My Site\' }246 });247});248.249.fi250.251.IP "" 0252.253.P254Previously rendering of a collection via \fIpartial()\fR would look something like this:255.256.IP "" 4257.258.nf259260this\.partial(\'comment\.html\.haml\', { collection: comments });261.262.fi263.264.IP "" 0265.266.P267Although this worked just fine, it was generally to verbose, the similar but new API looks like this, as \fIpartial()\fR is \fIalways\fR passed as a local variable:268.269.IP "" 4270.271.nf272273partial(\'comment\.haml\', { collection: comments });274.275.fi276.277.IP "" 0278.279.P280To make things even less verbose we can assume the extension when omitted:281.282.IP "" 4283.284.nf285286partial(\'comment\', { collection: comments });287.288.fi289.290.IP "" 0291.292.P293And once again even further, when rendering a collection we can simply pass an array, if no other options are desired:294.295.IP "" 4296.297.nf298299partial(\'comments\', comments);300.301.fi302.303.IP "" 0304.305.SS "Redirecting"306Previously you would307.308.IP "" 4309.310.nf311312this\.redirect(\'/somewhere\');313.314.fi315.316.IP "" 0317.318.P319However you would now:320.321.IP "" 4322.323.nf324325res\.redirect(\'/somewhere\');326res\.redirect(\'/somewhere\', 301);327.328.fi329.330.IP "" 0331.332.SS "HTTP Client"333Previously Express provided a high level http client, this library is no more as it does not belong in Express, however it may be resurrected as a separate module\.334.335.SS "Core Extensions"336Express is no longer dependent on the JavaScript Extensions \fIhttp://github\.com/visionmedia/ext\.js\fR library, so those of you using the methods provided by it such as \fBObject\.merge(a, b)\fR will need to roll your own, or install the module via:337.338.IP "" 4339.340.nf341342$ npm install ext343.344.fi345.346.IP "" 0347
modified:docs/migrate.html+1 added-209 removed
193 unmodified lines
194<h2 id="Express">Express</h2>195<p class="man-name">196 <code>migrate</code>197</p>198<h3 id="Built-On-Connect">Built On Connect</h3>198<h3 id="Express-1-x-to-2-x-Migration">Express 1.x to 2.x Migration</h3>199200<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware201framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware202to Connect we allow additional community frameworks to develop robust, high-level frameworks using203the same technologies as Express.</p>204205<h3 id="Creating-Applications">Creating Applications</h3>206207<p>Previously due to legacy code implemented in the early days of node,208Express unfortunately had some globals. The DSL would previously be209accessed as shown below:</p>210211<pre><code>require('express');212213configure(function(){214 // app configuration215});216217get('/', function(){218 return 'hello world';219});220</code></pre>221222<p>Now we utilize the CommonJS module system appropriately, and223introduce <em>express.createServer()</em> which accepts the same arguments224as <em>http.createServer()</em>:</p>225226<pre><code>var express = require('express'),227 app = express.createServer();228229app.configure(function(){230 // app configuration231});232233app.get('/', function(req, res){234 res.send('hello world');235});236</code></pre>237238<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>239240<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>241242<p>Previously Express was bundled with plugins, which were essentially what243are now Connect middleware. Previously plugins would be utilized in a manor244similar to below:</p>245246<pre><code>use(Logger);247use(MethodOverride);248use(Cookie);249</code></pre>250251<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>252253<pre><code>var app = express.createServer(254 express.logger(),255 express.methodOverride(),256 express.cookieDecoder()257);258</code></pre>259260<p>or:</p>261262<pre><code>var app = express.createServer();263264app.use(express.logger());265app.use(express.methodOverride());266app.use(express.cookieDecoder());267</code></pre>268269<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>270271<h3 id="Running-Applications">Running Applications</h3>272273<p>Previously a global function <em>run()</em>, was available:</p>274275<pre><code>run();276</code></pre>277278<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,279so we can do things like:</p>280281<pre><code>app.listen();282app.listen(3000);283</code></pre>284285<h3 id="Route-Parameters">Route Parameters</h3>286287<p>Previously we could use <em>this.param()</em> to attempt288fetching a route, query string, or request body parameter:</p>289290<pre><code>get('/user/:id', function(){291 this.param('id');292});293</code></pre>294295<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>296297<pre><code>app.get('/user/:id', function(req, res){298 req.param('id');299});300</code></pre>301302<p>Route parameters are available via <code>req.params</code>:</p>303304<pre><code>app.get('/user/:id', function(req, res){305 req.params.id;306});307</code></pre>308309<h3 id="Passing-Route-Control">Passing Route Control</h3>310311<p>Old express had a weak notion of route passing,312which did not support async, and was never properly313implemented for practical use:</p>314315<pre><code>get('/', function(){316 this.pass('/foobar');317});318</code></pre>319320<p>Now Express has access to Connect's <em>next()</em> function,321which is passed as the third and final argument. Calling <em>next()</em> will322pass control to the next <em>matching route</em>, or continue down the stack323of Connect middleware.</p>324325<pre><code>app.get('/user/:id?', function(req, res, next){326 next();327});328329app.get('/user', function(){330 // ... respond331});332</code></pre>333334<h3 id="View-Rendering">View Rendering</h3>335336<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,337the <em>Content-Type</em> can be set via <em>res.contentType()</em> or338<em>res.header()</em>. For example what was previously <em>layout.html.haml</em>,339should now be <em>layout.haml</em>.</p>340341<p>Previously a view render looked something like this:</p>342343<pre><code>get('/', function(){344 this.render('index.html.haml', {345 locals: { title: 'My Site' }346 });347});348</code></pre>349350<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 others351remain the same.</p>352353<pre><code>app.get('/', function(req, res){354 res.render('index.haml', {355 locals: { title: 'My Site' }356 });357});358</code></pre>359360<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>361362<pre><code>this.partial('comment.html.haml', { collection: comments });363</code></pre>364365<p>Although this worked just fine, it was generally to verbose, the similar but new API366looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>367368<pre><code>partial('comment.haml', { collection: comments });369</code></pre>370371<p>To make things even less verbose we can assume the extension when omitted:</p>372373<pre><code>partial('comment', { collection: comments });374</code></pre>375376<p>And once again even further, when rendering a collection we can simply pass377an array, if no other options are desired:</p>378379<pre><code>partial('comments', comments);380</code></pre>381382<h3 id="Redirecting">Redirecting</h3>383384<p>Previously you would</p>385386<pre><code>this.redirect('/somewhere');387</code></pre>388389<p>However you would now:</p>390391<pre><code>res.redirect('/somewhere');392res.redirect('/somewhere', 301);393</code></pre>394395<h3 id="HTTP-Client">HTTP Client</h3>396397<p>Previously Express provided a high level http client, this library is no more398as it does not belong in Express, however it may be resurrected as a separate module.</p>399400<h3 id="Core-Extensions">Core Extensions</h3>401402<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 to403roll your own, or install the module via:</p>404405<pre><code>$ npm install ext406</code></pre>407200</div>201 </div>202 </div>203 </body>
1 unmodified line
modified:docs/migrate.md+1 added-187 removed