Skip to content
Myr

Rebuilt 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 cc27ee0 · Browse files · 8 files+220 added−62 removed
This commit

State

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

Diff stats

8 files+220 added−62 removed

  • other:+220 added−62 removed

8 files+220 added−62 removed

modified:docs/api.htmlbinary

A binary file, modified.

modified:docs/guide.1+125 added-3 removed
1.\" generated with Ronn/v0.7.32.\" http://github.com/rtomayko/ronn/tree/0.7.33.4.TH "GUIDE" "" "October 2010" "" ""4.TH "GUIDE" "" "November 2010" "" ""5.6.SH "NAME"7\fBguide\fR8.
252 unmodified lines
261.fi262.263.IP "" 0264.265.P266For example we can \fBPOST\fR some json, and echo the json back using the \fIbodyDecoder\fR middleware which will parse json request bodies (as well as others), and place the result in \fIreq\.body\fR:267.268.IP "" 4269.270.nf271272var express = require(\'express\')273 , app = express\.createServer();274275app\.use(express\.bodyDecoder());276277app\.post(\'/\', function(req, res){278 res\.send(req\.body);279});280281app\.listen(3000);282.283.fi284.285.IP "" 0286.287.SS "Passing Route Control"288We may pass control to the next \fImatching\fR route, by calling the \fIthird\fR argument, the \fInext()\fR function\. When a match cannot be made, control is passed back to Connect, and middleware continue to be invoked\. The same is true for several routes which have the same path defined, they will simply be executed in order until one does \fInot\fR call \fInext()\fR\.289.290.IP "" 4
16 unmodified lines
307.fi308.309.IP "" 0310.311.P312Express 1\.0 also introduces the \fIall()\fR method, which provides a route callback matching any HTTP method\. This is useful in many ways, one example being the loading of resources before executing subsequent routes as shown below:313.314.IP "" 4315.316.nf317318var express = require(\'express\')319 , app = express\.createServer();320321var users = [{ name: \'tj\' }];322323app\.all(\'/user/:id/:op?\', function(req, res, next){324 req\.user = users[req\.params\.id];325 if (req\.user) {326 next();327 } else {328 next(new Error(\'cannot find user \' + req\.params\.id));329 }330});331332app\.get(\'/user/:id\', function(req, res){333 res\.send(\'viewing \' + req\.user\.name);334});335336app\.get(\'/user/:id/edit\', function(req, res){337 res\.send(\'editing \' + req\.user\.name);338});339340app\.put(\'/user/:id\', function(req, res){341 res\.send(\'updating \' + req\.user\.name);342});343344app\.get(\'*\', function(req, res){345 res\.send(\'what???\', 404);346});347348app\.listen(3000);349.350.fi351.352.IP "" 0353.354.SS "Middleware"355Middleware via Connect \fIhttp://github\.com/senchalabs/connect\fR can be passed to \fIexpress\.createServer()\fR as you would with a regular Connect server\. For example:356.357.IP "" 4
578 unmodified lines
936.937.IP "\(bu" 4938CoffeeKup \fIhttp://github\.com/mauricemach/coffeekup\fR CoffeeScript based templating939.940.IP "\(bu" 4941jQuery Templates \fIhttps://github\.com/kof/node\-jqtpl\fR for node942.943.IP "" 0944.945.SS "Session Support"946Sessions support can be added by using Connect\'s \fIsession\fR middleware\. To do so we also need the \fIcookieDecoder\fR middleware place above it, which will parse and populate cookie data to \fIreq\.cookies\fR\.
487 unmodified lines
1434.SS "res\.partial(view[, options])"1435Render \fIview\fR partial with the given \fIoptions\fR\. This method is always available to the view as a local variable\.1436.1437.IP "\(bu" 41370\fIas\fR Variable name for each \fIcollection\fR value, defaults to the view name\.1438\fIobject\fR the object named by \fIas\fR or derived from the view name1439.1440.IP "\(bu" 41441\fIas\fR Variable name for each \fIcollection\fR or \fIobject\fR value, defaults to the view name\.1442.1443.IP "\(bu" 41444as: \'something\' will add the \fIsomething\fR local variable1445.1446.IP "\(bu" 41447as: this will use the collection value as the template context
61 unmodified lines
1509.IP "" 41510.1511.nf15121442partials(\'movie\', { collection: movies, as: global });1513partial(\'movie\', { collection: movies, as: global });1514// In view: director1515.1516.fi1517.1518.IP "" 01519.1520.P1521This same logic applies to a single partial object usage:1522.1523.IP "" 41524.1525.nf15261527partial(\'movie\', { object: movie, as: this });1528// In view: this\.director15291530partial(\'movie\', { object: movie, as: global });1531// In view: director15321533partial(\'movie\', { object: movie, as: \'video\' });1534// In view: video\.director15351536partial(\'movie\', { object: movie });1537// In view: movie\.director1538.1539.fi1540.1541.IP "" 01542.1543.P1544When a non\-collection (does \fInot\fR have \fI\.length\fR) is passed as the second argument, it is assumed to be the \fIobject\fR, after which the object\'s local variable name is derived from the view name:1545.1546.IP "" 41547.1548.nf15491550partial(\'movie\', movie);1551// => In view: movie\.director1552.1553.fi1554.1555.IP "" 01556.1557.SS "app\.set(name[, val])"1558Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:1559.1560.IP "" 4
7 unmodified lines
1568.fi1569.1570.IP "" 01571.1572.P1573Alternatively you may simply access the settings via \fIapp\.settings\fR:1574.1575.IP "" 41576.1577.nf15781579app\.settings\.views1580// => \.\.\.path\.\.\.1581.1582.fi1583.1584.IP "" 01585.1586.SS "app\.enable(name)"1587Enable the given setting \fIname\fR:1588.1589.IP "" 4
282 unmodified lines
modified:docs/guide.html+80 added-2 removed
412 unmodified lines
413 /products.xml414 /products415</code></pre>416417<p>For example we can <strong>POST</strong> some json, and echo the json back using the <em>bodyDecoder</em> middleware which will parse json request bodies (as well as others), and place the result in <em>req.body</em>:</p>418419<pre><code>var express = require('express')420 , app = express.createServer();421422app.use(express.bodyDecoder());423424app.post('/', function(req, res){425 res.send(req.body);426});427428app.listen(3000);429</code></pre>430431<h3 id="Passing-Route-Control">Passing Route Control</h3>432433<p>We may pass control to the next <em>matching</em> route, by calling the <em>third</em> argument,434the <em>next()</em> function. When a match cannot be made, control is passed back to Connect,
12 unmodified lines
447 // do something else448});449</code></pre>450451<p>Express 1.0 also introduces the <em>all()</em> method, which provides a route callback matching any HTTP method. This is useful in many ways, one example being the loading of resources before executing subsequent routes as shown below:</p>452453<pre><code>var express = require('express')454 , app = express.createServer();455456var users = [{ name: 'tj' }];457458app.all('/user/:id/:op?', function(req, res, next){459 req.user = users[req.params.id];460 if (req.user) {461 next();462 } else {463 next(new Error('cannot find user ' + req.params.id));464 }465});466467app.get('/user/:id', function(req, res){468 res.send('viewing ' + req.user.name);469});470471app.get('/user/:id/edit', function(req, res){472 res.send('editing ' + req.user.name);473});474475app.put('/user/:id', function(req, res){476 res.send('updating ' + req.user.name);477});478479app.get('*', function(req, res){480 res.send('what???', 404);481});482483app.listen(3000); 484</code></pre>485486<h3 id="Middleware">Middleware</h3>487488<p>Middleware via <a href="http://github.com/senchalabs/connect">Connect</a> can be489passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>
331 unmodified lines
821<li><a href="http://jade-lang.com">Jade</a> haml.js successor</li>822<li><a href="http://github.com/visionmedia/haml.js">Haml</a> pythonic indented templates</li>823<li><a href="http://github.com/visionmedia/ejs">EJS</a> Embedded JavaScript</li>824<li><a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a> CoffeeScript based templating</li>825<li><a href="https://github.com/kof/node-jqtpl">jQuery Templates</a> for node</li>826</ul>827828829<h3 id="Session-Support">Session Support</h3>
324 unmodified lines
1154<p>Render <em>view</em> partial with the given <em>options</em>. This method is always available1155to the view as a local variable.</p>11561157<ul>1158<li><em>object</em> the object named by <em>as</em> or derived from the view name</li>1108<li><p><em>as</em> Variable name for each <em>collection</em> value, defaults to the view name.</p>1159<li><p><em>as</em> Variable name for each <em>collection</em> or <em>object</em> value, defaults to the view name.</p>11601161<ul>1162<li>as: 'something' will add the <em>something</em> local variable</li>1163<li>as: this will use the collection value as the template context</li>
31 unmodified lines
11951196<p>Another alternative is to "explode" the properties of the collection item into1197pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>11981148<pre><code>partials('movie', { collection: movies, as: global });1199<pre><code>partial('movie', { collection: movies, as: global });1200// In view: director1201</code></pre>12021203<p>This same logic applies to a single partial object usage:</p>12041205<pre><code>partial('movie', { object: movie, as: this });1206// In view: this.director12071208partial('movie', { object: movie, as: global });1209// In view: director12101211partial('movie', { object: movie, as: 'video' });1212// In view: video.director12131214partial('movie', { object: movie });1215// In view: movie.director1216</code></pre>12171218<p>When a non-collection (does <em>not</em> have <em>.length</em>) is passed as the second argument, it is assumed to be the <em>object</em>, after which the object's local variable name is derived from the view name:</p>12191220<pre><code>partial('movie', movie);1221// =&gt; In view: movie.director1222</code></pre>12231224<h3 id="app-set-name-val-">app.set(name[, val])</h3>12251226<p>Apply an application level setting <em>name</em> to <em>val</em>, or1227get the value of <em>name</em> when <em>val</em> is not present:</p>
2 unmodified lines
1230app.set('views');1231// =&gt; ...path...1232</code></pre>12331234<p>Alternatively you may simply access the settings via <em>app.settings</em>:</p>12351236<pre><code>app.settings.views1237// =&gt; ...path...1238</code></pre>12391240<h3 id="app-enable-name-">app.enable(name)</h3>12411242<p>Enable the given setting <em>name</em>:</p>1243
176 unmodified lines
modified:docs/index.1-37 removed
101 unmodified lines
102.IP "\(bu" 4103View the source \fIhttp://github\.com/visionmedia/express\fR104.105.IP "" 0106.107.SH "Apps Using Express"108.109.IP "\(bu" 4110LearnBoost \fIhttp://learnboost\.com\fR \- Online gradebook software111.112.IP "\(bu" 4113Markup\.IO \fIhttp://markup\.io/\fR \- Draw on any website to share ideas114.115.IP "\(bu" 4116wtfjs \fIhttp://wtfjs\.com/\fR \- JavaScript WTFs :)117.118.IP "\(bu" 4119Node Knockout \fIhttp://nodeknockout\.com/\fR \- node knockout competition site120.121.IP "\(bu" 4122Node News \fIhttp://nodejs\.se/\fR \- node news aggregator123.124.IP "\(bu" 4125Code Shelver \fIhttp://codeshelver\.com/\fR \- GitHub watch list app126.127.IP "\(bu" 4128Clickdummy \fIhttp://clickdummy\.net/\fR \- Fast prototyping for designers129.130.IP "\(bu" 4131E\-Resistible \fIhttp://e\-resistible\.co\.uk\fR \- Online takeaway ordering app132.133.IP "\(bu" 4134Storify \fIhttp://storify\.com\fR \- The future of publishing135.136.IP "\(bu" 4137Ogre \fIhttp://ogre\.adc4gis\.com/\fR \- Translates spatial files into GeoJSON138.139.IP "\(bu" 4140Widescript \fIhttp://widescript\.com/\fR \- A digital reading app targeted to people who study or make use of reference material141.142.IP "" 0106
modified:docs/index.html-17 removed
245 unmodified lines
246<li>View the <a href="http://github.com/visionmedia/express">source</a></li>247</ul>248249250<h2 id="Apps-Using-Express">Apps Using Express</h2>251252<ul>253<li><a href="http://learnboost.com">LearnBoost</a> - Online gradebook software</li>254<li><a href="http://markup.io/">Markup.IO</a> - Draw on any website to share ideas</li>255<li><a href="http://wtfjs.com/">wtfjs</a> - JavaScript WTFs :)</li>256<li><a href="http://nodeknockout.com/">Node Knockout</a> - node knockout competition site</li>257<li><a href="http://nodejs.se/">Node News</a> - node news aggregator</li>258<li><a href="http://codeshelver.com/">Code Shelver</a> - GitHub watch list app</li>259<li><a href="http://clickdummy.net/">Clickdummy</a> - Fast prototyping for designers</li>260<li><a href="http://e-resistible.co.uk">E-Resistible</a> - Online takeaway ordering app</li>261<li><a href="http://storify.com">Storify</a> - The future of publishing</li>262<li><a href="http://ogre.adc4gis.com/">Ogre</a> - Translates spatial files into GeoJSON</li>263<li><a href="http://widescript.com/">Widescript</a> - A digital reading app targeted to people who study or make use of reference material</li>264</ul>265266250</div>251 </div>252 </div>253 </body>
1 unmodified line
modified:lib/express/index.js+11 added-1 removed
modified:package.json+1 added-1 removed
modified:Readme.md+3 added-1 removed