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
Provenance
- Commit
4609984- Tree
61b651a- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
022c5e1
6 files changed+11 added−737 removed
modified:docs/guide.1+3 added
965 unmodified lines966 .967 .IP "" 0968 .969 .P970+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 \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+.P973 For 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 linesmodified:docs/guide.html+2 added
846 unmodified lines847 <li><em>collectionLength</em> length of the collection</li>848 </ul>849 850 851+<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>852+853 <p>For documentation on altering the object name view <a href="http://expressjs.com/guide.html#res-partial-view-options-">res.partial()</a>.</p>854 855 <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 linesmodified:docs/guide.md+2 added-2 removed
600 unmodified lines601 });602 603 The _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.604 605-### Migration Guide605+### 2.x Migration Guide606 607- 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.608 609 ### req.header(key[, defaultValue])610 611 Get the case-insensitive request header _key_, with optional _defaultValue_:566 unmodified linesmodified: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"10-Express 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"13-Previously 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"10 19-require(\'express\');20-21-configure(function(){22- // app configuration23-});24-25-get(\'/\', function(){26- return \'hello world\';27-});28-.29-.fi30-.31-.IP "" 032-.33-.P34-Now 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-.nf39-40-var express = require(\'express\'),41- app = express\.createServer();42-43-app\.configure(function(){44- // app configuration45-});46-47-app\.get(\'/\', function(req, res){48- res\.send(\'hello world\');49-});50-.51-.fi52-.53-.IP "" 054-.55-.P56-Express 1\.x does \fInot\fR currently allow returning of a string\.57-.58-.SS "Plugins vs Middleware"59-Previously 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-.nf64-65-use(Logger);66-use(MethodOverride);67-use(Cookie);68-.69-.fi70-.71-.IP "" 072-.73-.P74-Which we can now \fIuse()\fR within our app, or pass to the \fIexpress\.createServer()\fR method:75-.76-.IP "" 477-.78-.nf79-80-var app = express\.createServer(81- express\.logger(),82- express\.methodOverride(),83- express\.cookieDecoder()84-);85-.86-.fi87-.88-.IP "" 089-.90-.P91-or:92-.93-.IP "" 494-.95-.nf96-97-var app = express\.createServer();98-99-app\.use(express\.logger());100-app\.use(express\.methodOverride());101-app\.use(express\.cookieDecoder());102-.103-.fi104-.105-.IP "" 0106-.107-.P108-For documentation on creating Connect middleware visit Middleware Authoring \fIhttp://extjs\.github\.com/Connect/#Middleware\-Authoring\fR\.109-.110-.SS "Running Applications"111-Previously a global function \fIrun()\fR, was available:112-.113-.IP "" 4114-.115-.nf116-117-run();118-.119-.fi120-.121-.IP "" 0122-.123-.P124-The new \fIexpress\.Server\fR has the same API as \fIhttp\.Server\fR, so we can do things like:125-.126-.IP "" 4127-.128-.nf129-130-app\.listen();131-app\.listen(3000);132-.133-.fi134-.135-.IP "" 0136-.137-.SS "Route Parameters"138-Previously we could use \fIthis\.param()\fR to attempt fetching a route, query string, or request body parameter:139-.140-.IP "" 4141-.142-.nf143-144-get(\'/user/:id\', function(){145- this\.param(\'id\');146-});147-.148-.fi149-.150-.IP "" 0151-.152-.P153-Polymorphic parameter access can be done using \fBreq\.param()\fR:154-.155-.IP "" 4156-.157-.nf158-159-app\.get(\'/user/:id\', function(req, res){160- req\.param(\'id\');161-});162-.163-.fi164-.165-.IP "" 0166-.167-.P168-Route parameters are available via \fBreq\.params\fR:169-.170-.IP "" 4171-.172-.nf173-174-app\.get(\'/user/:id\', function(req, res){175- req\.params\.id;176-});177-.178-.fi179-.180-.IP "" 0181-.182-.SS "Passing Route Control"183-Old 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-.nf188-189-get(\'/\', function(){190- this\.pass(\'/foobar\');191-});192-.193-.fi194-.195-.IP "" 0196-.197-.P198-Now 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-.nf203-204-app\.get(\'/user/:id?\', function(req, res, next){205- next();206-});207-208-app\.get(\'/user\', function(){209- // \.\.\. respond210-});211-.212-.fi213-.214-.IP "" 0215-.216-.SS "View Rendering"217-View 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-.P220-Previously a view render looked something like this:221-.222-.IP "" 4223-.224-.nf225-226-get(\'/\', function(){227- this\.render(\'index\.html\.haml\', {228- locals: { title: \'My Site\' }229- });230-});231-.232-.fi233-.234-.IP "" 0235-.236-.P237-We 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-.nf242-243-app\.get(\'/\', function(req, res){244- res\.render(\'index\.haml\', {245- locals: { title: \'My Site\' }246- });247-});248-.249-.fi250-.251-.IP "" 0252-.253-.P254-Previously rendering of a collection via \fIpartial()\fR would look something like this:255-.256-.IP "" 4257-.258-.nf259-260-this\.partial(\'comment\.html\.haml\', { collection: comments });261-.262-.fi263-.264-.IP "" 0265-.266-.P267-Although 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-.nf272-273-partial(\'comment\.haml\', { collection: comments });274-.275-.fi276-.277-.IP "" 0278-.279-.P280-To make things even less verbose we can assume the extension when omitted:281-.282-.IP "" 4283-.284-.nf285-286-partial(\'comment\', { collection: comments });287-.288-.fi289-.290-.IP "" 0291-.292-.P293-And 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-.nf298-299-partial(\'comments\', comments);300-.301-.fi302-.303-.IP "" 0304-.305-.SS "Redirecting"306-Previously you would307-.308-.IP "" 4309-.310-.nf311-312-this\.redirect(\'/somewhere\');313-.314-.fi315-.316-.IP "" 0317-.318-.P319-However you would now:320-.321-.IP "" 4322-.323-.nf324-325-res\.redirect(\'/somewhere\');326-res\.redirect(\'/somewhere\', 301);327-.328-.fi329-.330-.IP "" 0331-.332-.SS "HTTP Client"333-Previously 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"336-Express 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-.nf341-342-$ npm install ext343-.344-.fi345-.346-.IP "" 0347-modified:docs/migrate.html+1 added-209 removed
193 unmodified lines194 <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>199 200-<p>Express 1.x is written to run on-top of the <a href="http://extjs.github.com/Connect">Connect</a> middlware201-framework, thus the <em>Plugin</em> has been replaced by Connect's middleware. By abstracting our middleware202-to Connect we allow additional community frameworks to develop robust, high-level frameworks using203-the same technologies as Express.</p>204-205-<h3 id="Creating-Applications">Creating Applications</h3>206-207-<p>Previously due to legacy code implemented in the early days of node,208-Express unfortunately had some globals. The DSL would previously be209-accessed as shown below:</p>210-211-<pre><code>require('express');212-213-configure(function(){214- // app configuration215-});216-217-get('/', function(){218- return 'hello world';219-});220-</code></pre>221-222-<p>Now we utilize the CommonJS module system appropriately, and223-introduce <em>express.createServer()</em> which accepts the same arguments224-as <em>http.createServer()</em>:</p>225-226-<pre><code>var express = require('express'),227- app = express.createServer();228-229-app.configure(function(){230- // app configuration231-});232-233-app.get('/', function(req, res){234- res.send('hello world');235-});236-</code></pre>237-238-<p>Express 1.x does <em>not</em> currently allow returning of a string.</p>239-240-<h3 id="Plugins-vs-Middleware">Plugins vs Middleware</h3>241-242-<p>Previously Express was bundled with plugins, which were essentially what243-are now Connect middleware. Previously plugins would be utilized in a manor244-similar to below:</p>245-246-<pre><code>use(Logger);247-use(MethodOverride);248-use(Cookie);249-</code></pre>250-251-<p>Which we can now <em>use()</em> within our app, or pass to the <em>express.createServer()</em> method:</p>252-253-<pre><code>var app = express.createServer(254- express.logger(),255- express.methodOverride(),256- express.cookieDecoder()257-);258-</code></pre>259-260-<p>or:</p>261-262-<pre><code>var app = express.createServer();263-264-app.use(express.logger());265-app.use(express.methodOverride());266-app.use(express.cookieDecoder());267-</code></pre>268-269-<p>For documentation on creating Connect middleware visit <a href="http://extjs.github.com/Connect/#Middleware-Authoring">Middleware Authoring</a>.</p>270-271-<h3 id="Running-Applications">Running Applications</h3>272-273-<p>Previously a global function <em>run()</em>, was available:</p>274-275-<pre><code>run();276-</code></pre>277-278-<p>The new <em>express.Server</em> has the same API as <em>http.Server</em>,279-so we can do things like:</p>280-281-<pre><code>app.listen();282-app.listen(3000);283-</code></pre>284-285-<h3 id="Route-Parameters">Route Parameters</h3>286-287-<p>Previously we could use <em>this.param()</em> to attempt288-fetching a route, query string, or request body parameter:</p>289-290-<pre><code>get('/user/:id', function(){291- this.param('id');292-});293-</code></pre>294-295-<p>Polymorphic parameter access can be done using <code>req.param()</code>:</p>296-297-<pre><code>app.get('/user/:id', function(req, res){298- req.param('id');299-});300-</code></pre>301-302-<p>Route parameters are available via <code>req.params</code>:</p>303-304-<pre><code>app.get('/user/:id', function(req, res){305- req.params.id;306-});307-</code></pre>308-309-<h3 id="Passing-Route-Control">Passing Route Control</h3>310-311-<p>Old express had a weak notion of route passing,312-which did not support async, and was never properly313-implemented for practical use:</p>314-315-<pre><code>get('/', function(){316- this.pass('/foobar');317-});318-</code></pre>319-320-<p>Now Express has access to Connect's <em>next()</em> function,321-which is passed as the third and final argument. Calling <em>next()</em> will322-pass control to the next <em>matching route</em>, or continue down the stack323-of Connect middleware.</p>324-325-<pre><code>app.get('/user/:id?', function(req, res, next){326- next();327-});328-329-app.get('/user', function(){330- // ... respond331-});332-</code></pre>333-334-<h3 id="View-Rendering">View Rendering</h3>335-336-<p>View filenames no longer take the form <em>Express</em>.<em>TYPE</em>.<em>ENGINE</em>,337-the <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>,339-should now be <em>layout.haml</em>.</p>340-341-<p>Previously a view render looked something like this:</p>342-343-<pre><code>get('/', function(){344- this.render('index.html.haml', {345- locals: { title: 'My Site' }346- });347-});348-</code></pre>349-350-<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 others351-remain the same.</p>352-353-<pre><code>app.get('/', function(req, res){354- res.render('index.haml', {355- locals: { title: 'My Site' }356- });357-});358-</code></pre>359-360-<p>Previously rendering of a collection via <em>partial()</em> would look something like this:</p>361-362-<pre><code>this.partial('comment.html.haml', { collection: comments });363-</code></pre>364-365-<p>Although this worked just fine, it was generally to verbose, the similar but new API366-looks like this, as <em>partial()</em> is <em>always</em> passed as a local variable:</p>367-368-<pre><code>partial('comment.haml', { collection: comments });369-</code></pre>370-371-<p>To make things even less verbose we can assume the extension when omitted:</p>372-373-<pre><code>partial('comment', { collection: comments });374-</code></pre>375-376-<p>And once again even further, when rendering a collection we can simply pass377-an array, if no other options are desired:</p>378-379-<pre><code>partial('comments', comments);380-</code></pre>381-382-<h3 id="Redirecting">Redirecting</h3>383-384-<p>Previously you would</p>385-386-<pre><code>this.redirect('/somewhere');387-</code></pre>388-389-<p>However you would now:</p>390-391-<pre><code>res.redirect('/somewhere');392-res.redirect('/somewhere', 301);393-</code></pre>394-395-<h3 id="HTTP-Client">HTTP Client</h3>396-397-<p>Previously Express provided a high level http client, this library is no more398-as it does not belong in Express, however it may be resurrected as a separate module.</p>399-400-<h3 id="Core-Extensions">Core Extensions</h3>401-402-<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 to403-roll your own, or install the module via:</p>404-405-<pre><code>$ npm install ext406-</code></pre>407-200 </div>201 </div>202 </div>203 </body>1 unmodified linemodified:docs/migrate.md+1 added-187 removed
1223456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
### Built On Connect### Express 1.x to 2.x Migration
Express 1.x is written to run on-top of the [Connect](http://extjs.github.com/Connect) middlwareframework, thus the _Plugin_ has been replaced by Connect's middleware. By abstracting our middlewareto Connect we allow additional community frameworks to develop robust, high-level frameworks usingthe same technologies as Express.
### Creating Applications
Previously due to legacy code implemented in the early days of node,Express unfortunately had some globals. The DSL would previously beaccessed as shown below:
require('express');
configure(function(){ // app configuration });
get('/', function(){ return 'hello world'; });
Now we utilize the CommonJS module system appropriately, andintroduce _express.createServer()_ which accepts the same argumentsas _http.createServer()_:
var express = require('express'), app = express.createServer(); app.configure(function(){ // app configuration }); app.get('/', function(req, res){ res.send('hello world'); });
Express 1.x does _not_ currently allow returning of a string.
### Plugins vs Middleware
Previously Express was bundled with plugins, which were essentially whatare now Connect middleware. Previously plugins would be utilized in a manorsimilar to below:
use(Logger); use(MethodOverride); use(Cookie);
Which we can now _use()_ within our app, or pass to the _express.createServer()_ method:
var app = express.createServer( express.logger(), express.methodOverride(), express.cookieDecoder() );
or:
var app = express.createServer();
app.use(express.logger()); app.use(express.methodOverride()); app.use(express.cookieDecoder());
For documentation on creating Connect middleware visit [Middleware Authoring](http://extjs.github.com/Connect/#Middleware-Authoring).
### Running Applications
Previously a global function _run()_, was available:
run();
The new _express.Server_ has the same API as _http.Server_,so we can do things like:
app.listen(); app.listen(3000);
### Route Parameters
Previously we could use _this.param()_ to attemptfetching a route, query string, or request body parameter:
get('/user/:id', function(){ this.param('id'); });
Polymorphic parameter access can be done using `req.param()`:
app.get('/user/:id', function(req, res){ req.param('id'); });
Route parameters are available via `req.params`:
app.get('/user/:id', function(req, res){ req.params.id; });
### Passing Route Control
Old express had a weak notion of route passing,which did not support async, and was never properly implemented for practical use:
get('/', function(){ this.pass('/foobar'); });
Now Express has access to Connect's _next()_ function,which is passed as the third and final argument. Calling _next()_ willpass control to the next _matching route_, or continue down the stackof Connect middleware.
app.get('/user/:id?', function(req, res, next){ next(); });
app.get('/user', function(){ // ... respond });
### View Rendering
View filenames no longer take the form _NAME_._TYPE_._ENGINE_,the _Content-Type_ can be set via _res.contentType()_ or_res.header()_. For example what was previously _layout.html.haml_,should now be _layout.haml_.
Previously a view render looked something like this:
get('/', function(){ this.render('index.html.haml', { locals: { title: 'My Site' } }); });
We now have _res.render()_, however the options passed to [haml](http://github.com/visionmedia/haml.js), [jade](http://github.com/visionmedia/jade), and othersremain the same.
app.get('/', function(req, res){ res.render('index.haml', { locals: { title: 'My Site' } }); });
Previously rendering of a collection via _partial()_ would look something like this:
this.partial('comment.html.haml', { collection: comments });
Although this worked just fine, it was generally to verbose, the similar but new APIlooks like this, as _partial()_ is _always_ passed as a local variable:
partial('comment.haml', { collection: comments });
To make things even less verbose we can assume the extension when omitted:
partial('comment', { collection: comments });
And once again even further, when rendering a collection we can simply passan array, if no other options are desired:
partial('comments', comments);
### Redirecting
Previously you would
this.redirect('/somewhere');
However you would now:
res.redirect('/somewhere'); res.redirect('/somewhere', 301);
### HTTP Client
Previously Express provided a high level http client, this library is no moreas it does not belong in Express, however it may be resurrected as a separate module.
### Core Extensions
Express is no longer dependent on the [JavaScript Extensions](http://github.com/visionmedia/ext.js) library, so those of you using the methods provided by it such as `Object.merge(a, b)` will need toroll your own, or install the module via:
$ npm install extNo newline at end of file