fixed docs due to markdown-js not supporting html
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 187dc5d · Browse files · 10 files·+682 added−434 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+682 added−434 removed
- other:+682 added−434 removed
Provenance
- Commit
a75e60a- Tree
55b36b9- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
187dc5d
10 files changed+682 added−434 removed
modified:docs/applications.html+18 added-14 removed
188 unmodified lines189 <li><a href="guide.html">Guide</a></li>190 <li><a href="screencasts.html">Screencasts</a></li>191 <li><a href="applications.html">Applications</a></li>192 </ul>193-<p><br /></p>193 194+195+<br />196+197+198 <p><a href="http://learnboost.com">Learnboost</a> is a free online gradebook application, aimed to crush the competition with innovative, realtime, enjoyable features.</p>199 197-<p>[<img alt="LearnBoost" src="images/apps/learnboost.png)](http://learnboost.com" /></p>200+<p><a href="http://learnboost.com"><img src="images/apps/learnboost.png" alt="LearnBoost" /></a></p>201 202 <p><a href="http://storify.com">Storify</a> lets you turn what people post on social media websites into compelling stories.</p>203 201-<p>[<img alt="Storify" src="images/apps/storify.png)](http://storify.com" /></p>204+<p><a href="http://storify.com"><img src="images/apps/storify.png" alt="Storify" /></a></p>205 206 <p><a href="http://pakistansurvey.org/">Pakistan Survey</a> by <a href="http://developmentseed.org">Development Seed</a>, provides in-depth agency-specific analysis from regional experts with data from 1,000 interviews across 120 villages in all seven tribal agencies and mapping of 142 reported drone strikes in FATA through July 2010.</p>207 205-<p>[<img alt="Pakistan Survey" src="images/apps/developmentseed.png)](http://pakistansurvey.org" /></p>208+<p><a href="http://pakistansurvey.org"><img src="images/apps/developmentseed.png" alt="Pakistan Survey" /></a></p>209 210 <p><a href="http://markup.io">Markup.IO</a> allows you to draw directly on <em>any</em> website, then share with others to share your thoughts.</p>211 209-<p>[<img alt="Markup.IO" src="images/apps/markupio.png)](http://markup.io" /></p>212+<p><a href="http://markup.io"><img src="images/apps/markupio.png" alt="Markup.IO" /></a></p>213 214 <p><a href="http://scrabb.ly">Scrabb.ly</a> is a massively multiplayer scrabble game initially created for the <a href="http://nodeknockout.com/">Node Knockout</a> competition.</p>215 213-<p>[<img alt="Online Realtime Scrabble" src="images/apps/scrabbly.png)](http://scrabb.ly" /></p>216+<p><a href="http://scrabb.ly"><img src="images/apps/scrabbly.png" alt="Online Realtime Scrabble" /></a></p>217 218 <p><a href="http://clickdummy.net/">ClickDummy</a> is a rapid mockup prototyping application for designers and dummies.</p>219 217-<p>[<img alt="Mockup Prototying" src="images/apps/clickdummy.png)](http://clickdummy.net" /></p>220+<p><a href="http://clickdummy.net"><img src="images/apps/clickdummy.png" alt="Mockup Prototying" /></a></p>221 222 <p><a href="http://nodeknockout.com">Node Knockout</a> organized the first ever node-specific competition with hundreds of contestants.</p>223 221-<p>[<img alt="Node Knockout Competition Express" src="images/apps/nodeko.png)](http://nodeknockout.com" /></p>224+<p><a href="http://nodeknockout.com"><img src="images/apps/nodeko.png" alt="Node Knockout Competition Express" /></a></p>225 223-<p><a href="http://widescript.com">Widescript</a> is an innovative app that helps you focus and interact with your texts - on your desktop, your couch or on the go.</p>226+<p><a href="http://widescript.com">Widescript</a> is an innovative app that helps you focus and interact with your texts – on your desktop, your couch or on the go.</p>227 225-<p>[<img alt="Widescript" src="images/apps/widescript.png)](http://widescript.com" /></p>228+<p><a href="http://widescript.com"><img src="images/apps/widescript.png" alt="Widescript" /></a></p>229 230 <p><a href="http://www.e-resistible.co.uk/">e-resistable</a> is an online order takeaway system providing an intuitive way to fill your belly from your computer!</p>231 229-<p>[<img alt="Online Takeaway" src="images/apps/e-resistable.png)](http://www.e-resistible.co.uk" /></p>232+<p><a href="http://www.e-resistible.co.uk"><img src="images/apps/e-resistable.png" alt="Online Takeaway" /></a></p>233 234 <p><a href="http://toptwittertrends.com">Top Twitter Trends</a> utilizes MongoDB, Socket.IO, jQuery and many other exciting libraries to bring you trending tweets in realtime.</p>235 233-<p>[<img alt="Twitter Trends" src="images/apps/toptwittertrends.png)](http://toptwittertrends.com" /></p>236+<p><a href="http://toptwittertrends.com"><img src="images/apps/toptwittertrends.png" alt="Twitter Trends" /></a></p>237 235-<p><br /></p>238+<br />239 240+241 <p>The applications shown above are not listed in any specific order. To have an application added or removed please contact <a href="http://github.com/visionmedia">TJ Holowaychuk</a>.</p>242 </div>243 </div>244 </body>241-</html>245+</html>modified:docs/contrib.html+21 added-10 removed
188 unmodified lines189 <li><a href="guide.html">Guide</a></li>190 <li><a href="screencasts.html">Screencasts</a></li>191 <li><a href="applications.html">Applications</a></li>192 </ul>193-<h3 id="Development-Dependencies">Development Dependencies</h3>193+<h3>Development Dependencies</h3>194 195 <p>Express development dependencies are stored within the <em>./support</em> directory. To196 update them execute:</p>197 198-<pre><code>$ git submodule update --init</code></pre>198+<pre><code>$ git submodule update --init199+</code></pre>200 200-<h3 id="Running-Tests">Running Tests</h3>201+<h3>Running Tests</h3>202 203 <p>Express uses the <a href="http://github.com/visionmedia/expresso">Expresso</a> TDD204 framework to write and run elegant test suites extremely fast. To run all test suites205 simply execute:</p>206 206-<pre><code>$ make test</code></pre>207+<pre><code>$ make test208+</code></pre>209 210 <p>To target specific suites we may specify the files via:</p>211 210-<pre><code>$ make test TESTS=test/view.test.js</code></pre>212+<pre><code>$ make test TESTS=test/view.test.js213+</code></pre>214 215 <p>To check test coverage run:</p>216 214-<pre><code>$ make test-cov</code></pre>217+<pre><code>$ make test-cov218+</code></pre>219 216-<h3 id="Contributions">Contributions</h3>220+<h3>Contributions</h3>221 222 <p>To accept a contribution, you should follow these guidelines:</p>223 220-<ul><li>All tests <em>must</em> pass</li><li>Your alterations or additions <em>must</em> include tests</li><li>Your commit(s) should be <em>focused</em>, do not commit once for several changes</li><li>Do <em>not</em> alter release information such as the <em>version</em>, or <em>History.md</em></li><li>Indents are <em>2</em> spaces.</li></ul>224+<ul>225+<li>All tests <em>must</em> pass</li>226+<li>Your alterations or additions <em>must</em> include tests</li>227+<li>Your commit(s) should be <em>focused</em>, do not commit once for several changes</li>228+<li>Do <em>not</em> alter release information such as the <em>version</em>, or <em>History.md</em></li>229+<li>Indents are <em>2</em> spaces.</li>230+</ul>231 222-<h3 id="Documentation">Documentation</h3>232 233+<h3>Documentation</h3>234+235 <p>To contribute documentation edit the markdown files in <em>./docs</em>, however236 do <em>not</em> run <em>make docs</em>, as they will be re-built and published with each release.</p>237 </div>238 </div>239 </body>229-</html>240+</html>modified:docs/executable.html+9 added-7 removed
188 unmodified lines189 <li><a href="guide.html">Guide</a></li>190 <li><a href="screencasts.html">Screencasts</a></li>191 <li><a href="applications.html">Applications</a></li>192 </ul>193-<h2 id="Synopsis">Synopsis</h2>193+<h2>Synopsis</h2>194 195-<pre><code>express [options] [PATH]</code></pre>195+<pre><code>express [options] [PATH]196+</code></pre>197 197-<h2 id="Description">Description</h2>198+<h2>Description</h2>199 199-<p>The <em>express</em> executable generates apps at the given <strong>PATH</strong> or the 200+<p>The <em>express</em> executable generates apps at the given <strong>PATH</strong> or the201 current working directory. Although Express is not bound to a specific202 application structure, this executable creates a maintainable base app.</p>203 203-<h2 id="Options">Options</h2>204+<h2>Options</h2>205 206 <pre><code> -s, --sessions Add session support207 -t, --template ENGINE Add template ENGINE support (jade|ejs). Defaults to jade208 -c, --css ENGINE Add stylesheet ENGINE support (less|sass|stylus). Defaults to plain css209 -v, --version Output framework version209- -h, --help Output help information</code></pre>210+ -h, --help Output help information211+</code></pre>212 </div>213 </div>214 </body>213-</html>215+</html>modified:docs/guide.html+462 added-304 removed
177 unmodified lines178 <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"><ul id="toc">182-<li><a href="#Installation">Installation</a></li>183-<li><a href="#Creating-A-Server">Creating A Server</a></li>184-<li><a href="#Creating-An-HTTPS-Server">Creating An HTTPS Server</a></li>185-<li><a href="#Configuration">Configuration</a></li>186-<li><a href="#Settings">Settings</a></li>187-<li><a href="#Routing">Routing</a></li>188-<li><a href="#Passing-Route-Control">Passing Route Control</a></li>189-<li><a href="#Middleware">Middleware</a></li>190-<li><a href="#Route-Middleware">Route Middleware</a></li>191-<li><a href="#HTTP-Methods">HTTP Methods</a></li>192-<li><a href="#Error-Handling">Error Handling</a></li>193-<li><a href="#Route-Param-Pre-conditions">Route Param Pre-conditions</a></li>194-<li><a href="#View-Rendering">View Rendering</a></li>195-<li><a href="#View-Partials">View Partials</a></li>196-<li><a href="#View-Lookup">View Lookup</a></li>197-<li><a href="#Template-Engines">Template Engines</a></li>198-<li><a href="#Session-Support">Session Support</a></li>199-<li><a href="#Migration-Guide">Migration Guide</a></li>182+<li><a href="#installation">Installation</a></li>183+<li><a href="#creating-a server">Creating A Server</a></li>184+<li><a href="#creating-an https server">Creating An HTTPS Server</a></li>185+<li><a href="#configuration">Configuration</a></li>186+<li><a href="#settings">Settings</a></li>187+<li><a href="#routing">Routing</a></li>188+<li><a href="#passing-route control">Passing Route Control</a></li>189+<li><a href="#middleware">Middleware</a></li>190+<li><a href="#route-middleware">Route Middleware</a></li>191+<li><a href="#http-methods">HTTP Methods</a></li>192+<li><a href="#error-handling">Error Handling</a></li>193+<li><a href="#route-param pre-conditions">Route Param Pre-conditions</a></li>194+<li><a href="#view-rendering">View Rendering</a></li>195+<li><a href="#view-partials">View Partials</a></li>196+<li><a href="#view-lookup">View Lookup</a></li>197+<li><a href="#template-engines">Template Engines</a></li>198+<li><a href="#session-support">Session Support</a></li>199+<li><a href="#migration-guide">Migration Guide</a></li>200 <li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Request</a><ul class="section" id="section-Request">201-<li><a href="#req-header-key-defaultValue">header()</a></li>202-<li><a href="#req-accepts-type">accepts()</a></li>203-<li><a href="#req-is-type">is()</a></li>204-<li><a href="#req-param-name-default">param()</a></li>205-<li><a href="#req-flash-type-msg">flash()</a></li>206-<li><a href="#req-isXMLHttpRequest">isXMLHttpRequest</a></li>201+<li><a href="#req.header()">header()</a></li>202+<li><a href="#req.accepts()">accepts()</a></li>203+<li><a href="#req.is()">is()</a></li>204+<li><a href="#req.param()">param()</a></li>205+<li><a href="#req.flash()">flash()</a></li>206+<li><a href="#req.isxmlhttprequest">isXMLHttpRequest</a></li>207 </ul></li>208 <li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Response</a><ul class="section" id="section-Response">209-<li><a href="#res-header-key-val">header()</a></li>210-<li><a href="#res-charset">charset</a></li>211-<li><a href="#res-contentType-type">contentType()</a></li>212-<li><a href="#res-attachment-filename">attachment()</a></li>213-<li><a href="#res-sendfile-path-options-callback">sendfile()</a></li>214-<li><a href="#res-download-file-filename-callback">download()</a></li>215-<li><a href="#res-send-body-status-headers-status-status">send()</a></li>216-<li><a href="#res-redirect-url-status">redirect()</a></li>217-<li><a href="#res-cookie-name-val-options">cookie()</a></li>218-<li><a href="#res-clearCookie-name">clearCookie()</a></li>219-<li><a href="#res-render-view-options-fn">render()</a></li>220-<li><a href="#res-partial-view-options">partial()</a></li>221-<li><a href="#res-local-name-val">local()</a></li>222-<li><a href="#res-local-obj">local()</a></li>209+<li><a href="#res.header()">header()</a></li>210+<li><a href="#res.charset">charset</a></li>211+<li><a href="#res.contenttype()">contentType()</a></li>212+<li><a href="#res.attachment()">attachment()</a></li>213+<li><a href="#res.sendfile()">sendfile()</a></li>214+<li><a href="#res.download()">download()</a></li>215+<li><a href="#res.send()">send()</a></li>216+<li><a href="#res.redirect()">redirect()</a></li>217+<li><a href="#res.cookie()">cookie()</a></li>218+<li><a href="#res.clearcookie()">clearCookie()</a></li>219+<li><a href="#res.render()">render()</a></li>220+<li><a href="#res.partial()">partial()</a></li>221+<li><a href="#res.local()">local()</a></li>222+<li><a href="#res.locals()">locals()</a></li>223 </ul></li>224 <li><a href="#" class="toggle">+</a> <a class="section-title" href="#">Server</a><ul class="section" id="section-Server">225-<li><a href="#app-set-name-val">set()</a></li>226-<li><a href="#app-enable-name">enable()</a></li>227-<li><a href="#app-enabled-name">enabled()</a></li>228-<li><a href="#app-disable-name">disable()</a></li>229-<li><a href="#app-disabled-name">disabled()</a></li>230-<li><a href="#app-configure-env-function-function">configure()</a></li>231-<li><a href="#app-redirect-name-val">redirect()</a></li>232-<li><a href="#app-error-function">error()</a></li>233-<li><a href="#app-helpers-obj">helpers()</a></li>234-<li><a href="#app-dynamicHelpers-obj">dynamicHelpers()</a></li>235-<li><a href="#app-mounted-fn">mounted()</a></li>236-<li><a href="#app-register-ext-exports">register()</a></li>237-<li><a href="#app-listen-port-host">listen()</a></li>225+<li><a href="#app.set()">set()</a></li>226+<li><a href="#app.enable()">enable()</a></li>227+<li><a href="#app.enabled()">enabled()</a></li>228+<li><a href="#app.disable()">disable()</a></li>229+<li><a href="#app.disabled()">disabled()</a></li>230+<li><a href="#app.configure()">configure()</a></li>231+<li><a href="#app.redirect()">redirect()</a></li>232+<li><a href="#app.error()">error()</a></li>233+<li><a href="#app.helpers()">helpers()</a></li>234+<li><a href="#app.dynamichelpers()">dynamicHelpers()</a></li>235+<li><a href="#app.mounted()">mounted()</a></li>236+<li><a href="#app.register()">register()</a></li>237+<li><a href="#app.listen()">listen()</a></li>238 </ul></li>239 </ul>240 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 241 <p id="tagline">5 unmodified lines247 <li><a href="guide.html">Guide</a></li>248 <li><a href="screencasts.html">Screencasts</a></li>249 <li><a href="applications.html">Applications</a></li>250 </ul>251-<h3 id="Installation">Installation</h3>251+<h3 id="installation">Installation</h3>252 253-<pre><code>$ npm install express</code></pre>253+<pre><code>$ npm install express254+</code></pre>255 255-<h3 id="Creating-A-Server">Creating A Server</h3>256+<h3 id="creating-a server">Creating A Server</h3>257 258 <p> To create an instance of the <em>express.HTTPServer</em>, simply invoke the <em>createServer()</em> method. With our instance <em>app</em> we can then define routes based on the HTTP verbs, in this example <em>app.get()</em>.</p>259 260 <pre><code>var app = require('express').createServer();1 unmodified line262 app.get('/', function(req, res){263 res.send('hello world');264 });265 265-app.listen(3000);</code></pre>266+app.listen(3000);267+</code></pre>268 267-<h3 id="Creating-An-HTTPS-Server">Creating An HTTPS Server</h3>269+<h3 id="creating-an https server">Creating An HTTPS Server</h3>270 271 <p> To initialize a <em>express.HTTPSServer</em> we do the same as above, however we270- pass an options object, accepting <em>key</em>, <em>cert</em> and the others mentioned in node's <a href="http://nodejs.org/docs/v0.3.7/api/https.html#https.createServer">https documentation</a>.</p>272+ pass an options object, accepting <em>key</em>, <em>cert</em> and the others mentioned in node’s <a href="http://nodejs.org/docs/v0.3.7/api/https.html#https.createServer">https documentation</a>.</p>273 272-<pre><code> var app = require('express').createServer({ key: ... });</code></pre>274+<pre><code> var app = require('express').createServer({ key: ... });275+</code></pre>276 274-<h3 id="Configuration">Configuration</h3>277+<h3 id="configuration">Configuration</h3>278 279 <p>Express supports arbitrary environments, such as <em>production</em> and <em>development</em>. Developers280 can use the <em>configure()</em> method to setup needs required by the current environment. When278-<em>configure()</em> is called without an environment name it will be run in <em>every</em> environment 281+<em>configure()</em> is called without an environment name it will be run in <em>every</em> environment282 prior to the environment specific callback.</p>283 284 <p>In the example below we only <em>dumpExceptions</em>, and respond with exception stack traces285 in <em>development</em> mode, however for both environments we utilize <em>methodOverride</em> and <em>bodyParser</em>.286 Note the use of <em>app.router</em>, which can (optionally) be used to mount the application routes,287 otherwise the first call to <em>app.get()</em>, <em>app.post()</em>, etc will mount the routes.</p>288 289 <pre><code>app.configure(function(){287- app.use(express.methodOverride());288- app.use(express.bodyParser());289- app.use(app.router);290+ app.use(express.methodOverride());291+ app.use(express.bodyParser());292+ app.use(app.router);293 });294 295 app.configure('development', function(){293- app.use(express.static(__dirname + '/public'));294- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));296+ app.use(express.static(__dirname + '/public'));297+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));298 });299 300 app.configure('production', function(){301 var oneYear = 31557600000;302 app.use(express.static(__dirname + '/public', { maxAge: oneYear }));303 app.use(express.errorHandler());304+});301-});</code></pre>305+</code></pre>306 307 <p>For internal and arbitrary settings Express provides the <em>set(key[, val])</em>, <em>enable(key)</em>, <em>disable(key)</em> methods:</p>308 309 <pre><code> app.configure(function(){8 unmodified lines318 // same as app.set('some feature', false);319 320 app.enabled('some feature')321 // => false322+ });318- });</code></pre>323+</code></pre>324 320-<p>To alter the environment we can set the <em>NODE</em>ENV_ environment variable, for example:</p>325+<p>To alter the environment we can set the <em>NODE_ENV</em> environment variable, for example:</p>326 322-<pre><code>$ NODE_ENV=production node app.js</code></pre>327+<pre><code>$ NODE_ENV=production node app.js328+</code></pre>329 330 <p>This is <em>very</em> important, as many caching mechanisms are <em>only enabled</em> when in production.</p>331 326-<h3 id="Settings">Settings</h3>332+<h3 id="settings">Settings</h3>333 334 <p>Express supports the following settings out of the box:</p>335 330-<ul><li><em>home</em> Application base path used for <em>res.redirect()</em> and transparently handling mounted apps.</li><li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li><li><em>view engine</em> Default view engine name for views rendered without extensions</li><li><em>view options</em> An object specifying global view options</li></ul>336+<ul>337+<li><em>home</em> Application base path used for <em>res.redirect()</em> and transparently handling mounted apps.</li>338+<li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li>339+<li><em>view engine</em> Default view engine name for views rendered without extensions</li>340+<li><em>view options</em> An object specifying global view options</li>341+</ul>342 332-<h3 id="Routing">Routing</h3>343 344+<h3 id="routing">Routing</h3>345+346 <p>Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.335-For example we may want to render a user's account for the path <em>/user/12</em>, this336-can be done by defining the route below. The values associated to the named placeholders 347+For example we may want to render a user’s account for the path <em>/user/12</em>, this348+can be done by defining the route below. The values associated to the named placeholders349 are available as <code>req.params</code>.</p>350 351 <pre><code>app.get('/user/:id', function(req, res){340- res.send('user ' + req.params.id);341-});</code></pre>352+ res.send('user ' + req.params.id);353+});354+</code></pre>355 356 <p>A route is simple a string which is compiled to a <em>RegExp</em> internally. For example357 when <em>/user/:id</em> is compiled, a simplified version of the regexp may look similar to:</p>358 346-<pre><code>\/user\/([^\/]+)\/?</code></pre>359+<pre><code>\/user\/([^\/]+)\/?360+</code></pre>361 362 <p>Regular expression literals may also be passed for complex uses. Since capture349-groups with literal <em>RegExp</em>'s are anonymous we can access them directly <code>req.params</code>. So our first capture group would be <em>req.params[0]</em> and the second would follow as <em>req.params[1]</em>.</p>363+groups with literal <em>RegExp</em>’s are anonymous we can access them directly <code>req.params</code>. So our first capture group would be <em>req.params[0]</em> and the second would follow as <em>req.params[1]</em>.</p>364 365 <pre><code>app.get(/^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/, function(req, res){366 res.send(req.params);367+});353-});</code></pre>368+</code></pre>369 370 <p>Curl requests against the previously defined route:</p>371 372 <pre><code> $ curl http://dev:3000/user2 unmodified lines375 [null,null]376 $ curl http://dev:3000/users/1377 ["1",null]378 $ curl http://dev:3000/users/1..15364- ["1","15"]</code></pre>379+ ["1","15"]380+</code></pre>381 382 <p>Below are some route examples, and the associated paths that they383 may consume:</p>384 26 unmodified lines411 /products412 413 "/user/:id.:format?"414 /user/12399- /user/12.json</code></pre>415+ /user/12.json416+</code></pre>417 418 <p>For example we can <strong>POST</strong> some json, and echo the json back using the <em>bodyParser</em> middleware which will parse json request bodies (as well as others), and place the result in <em>req.body</em>:</p>419 420 <pre><code>var express = require('express')4 unmodified lines425 app.post('/', function(req, res){426 res.send(req.body);427 });428 412-app.listen(3000);</code></pre>429+app.listen(3000);430+</code></pre>431 414-<p>Typically we may use a "dumb" placeholder such as "/user/:id" which has no restrictions, however say for example we are limiting a user id to digits, we may use <em>'/user/:id(\d+)'</em> which will <em>not</em> match unless the placeholder value contains only digits.</p>432+<p>Typically we may use a “dumb” placeholder such as “/user/:id” which has no restrictions, however say for example we are limiting a user id to digits, we may use <em>‘/user/:id(\d+)’</em> which will <em>not</em> match unless the placeholder value contains only digits.</p>433 416-<h3 id="Passing-Route-Control">Passing Route Control</h3>434+<h3 id="passing-route control">Passing Route Control</h3>435 436 <p>We may pass control to the next <em>matching</em> route, by calling the <em>third</em> argument,437 the <em>next()</em> function. When a match cannot be made, control is passed back to Connect,438 and middleware continue to be invoked in the order that they are added via <em>use()</em>. The same is true for several routes which have the same path defined, they will simply be executed in order until one does <em>not</em> call <em>next()</em> and decides to respond.</p>439 440 <pre><code>app.get('/users/:id?', function(req, res, next){423- var id = req.params.id;424- if (id) {425- // do something426- } else {427- next();428- }441+ var id = req.params.id;442+ if (id) {443+ // do something444+ } else {445+ next();446+ }447 });448 449 app.get('/users', function(req, res){432- // do something else433-});</code></pre>450+ // do something else451+});452+</code></pre>453 454 <p>The <em>app.all()</em> method is useful for applying the same logic for all HTTP verbs in a single call. Below we use this to load a user from our fake database, and assign it to <em>req.user</em>.</p>455 456 <pre><code>var express = require('express')25 unmodified lines482 app.get('*', function(req, res){483 res.send('what???', 404);484 });485 467-app.listen(3000); </code></pre>486+app.listen(3000); 487+</code></pre>488 469-<h3 id="Middleware">Middleware</h3>489+<h3 id="middleware">Middleware</h3>490 491 <p>Middleware via <a href="http://github.com/senchalabs/connect">Connect</a> can be492 passed to <em>express.createServer()</em> as you would with a regular Connect server. For example:</p>493 494 <pre><code> var express = require('express');495 496 var app = express.createServer(477- express.logger()478- , express.bodyParser()479- );</code></pre>497+ express.logger()498+ , express.bodyParser()499+ );500+</code></pre>501 502 <p>Alternatively we can <em>use()</em> them which is useful when adding middleware within <em>configure()</em> blocks, in a progressive manor.</p>503 483-<pre><code>app.use(express.logger({ format: ':method :uri' }));</code></pre>504+<pre><code>app.use(express.logger({ format: ':method :uri' }));505+</code></pre>506 485-<p>Typically with connect middleware you would <em>require('connect')</em> like so:</p>507+<p>Typically with connect middleware you would <em>require(‘connect’)</em> like so:</p>508 509 <pre><code>var connect = require('connect');510 app.use(connect.logger());489-app.use(connect.bodyParser());</code></pre>511+app.use(connect.bodyParser());512+</code></pre>513 514 <p>This is somewhat annoying, so express re-exports these middleware properties, however they are <em>identical</em>:</p>515 516 <pre><code>app.use(express.logger());494-app.use(express.bodyParser());</code></pre>517+app.use(express.bodyParser());518+</code></pre>519 496-<h3 id="Route-Middleware">Route Middleware</h3>520+<h3 id="route-middleware">Route Middleware</h3>521 522 <p>Routes may utilize route-specific middleware by passing one or more additional callbacks (or arrays) to the method. This feature is extremely useful for restricting access, loading data used by the route etc.</p>523 500-<p>Typically async data retrieval might look similar to below, where we take the <em>:id</em> parameter, and attempt loading a user. </p>524+<p>Typically async data retrieval might look similar to below, where we take the <em>:id</em> parameter, and attempt loading a user.</p>525 526 <pre><code>app.get('/user/:id', function(req, res, next){527 loadUser(req.params.id, function(err, user){528 if (err) return next(err);529 res.send('Viewing user ' + user.name);530 });531+});507-});</code></pre>532+</code></pre>533 509-<p>To keep things DRY and to increase readability we can apply this logic within a middleware. As you can see below, abstracting this logic into middleware allows us to reuse it, and clean up our route at the same time. </p>534+<p>To keep things DRY and to increase readability we can apply this logic within a middleware. As you can see below, abstracting this logic into middleware allows us to reuse it, and clean up our route at the same time.</p>535 536 <pre><code>function loadUser(req, res, next) {537 // You would fetch your user from the db538 var user = users[req.params.id];6 unmodified lines545 }546 547 app.get('/user/:id', loadUser, function(req, res){548 res.send('Viewing user ' + req.user.name);549+});524-});</code></pre>550+</code></pre>551 552 <p>Multiple route middleware can be applied, and will be executed sequentially to apply further logic such as restricting access to a user account. In the example below only the authenticated user may edit his/her account.</p>553 554 <pre><code>function andRestrictToSelf(req, res, next) {3 unmodified lines558 }559 560 app.get('/user/:id/edit', loadUser, andRestrictToSelf, function(req, res){561 res.send('Editing user ' + req.user.name);562+});536-});</code></pre>563+</code></pre>564 565 <p>Keeping in mind that middleware are simply functions, we can define function that <em>returns</em> the middleware in order to create a more expressive and flexible solution as shown below.</p>566 567 <pre><code>function andRestrictTo(role) {5 unmodified lines573 }574 575 app.del('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){576 res.send('Deleted user ' + req.user.name);577+});550-});</code></pre>578+</code></pre>579 552-<p>Commonly used "stacks" of middleware can be passed as an array (<em>applied recursively</em>), which can be mixed and matched to any degree.</p>580+<p>Commonly used “stacks” of middleware can be passed as an array (<em>applied recursively</em>), which can be mixed and matched to any degree.</p>581 582 <pre><code>var a = [middleware1, middleware2]583 , b = [middleware3, middleware4]584 , all = [a, b];2 unmodified lines587 app.get('/bar', a, function(){});588 589 app.get('/', a, middleware3, middleware4, function(){});590 app.get('/', a, b, function(){});563-app.get('/', all, function(){});</code></pre>591+app.get('/', all, function(){});592+</code></pre>593 594 <p>For this example in full, view the <a href="http://github.com/visionmedia/express/blob/master/examples/route-middleware/app.js">route middleware example</a> in the repository.</p>595 567-<h3 id="HTTP-Methods">HTTP Methods</h3>596+<h3 id="http-methods">HTTP Methods</h3>597 598 <p>We have seen <em>app.get()</em> a few times, however Express also exposes other familiar HTTP verbs in the same manor, such as <em>app.post()</em>, <em>app.del()</em>, etc.</p>599 571-<p> A common example for <em>POST</em> usage, is when "submitting" a form. Below we simply set our form method to "post" in our html, and control will be given to the route we have defined below it.</p>600+<p> A common example for <em>POST</em> usage, is when “submitting” a form. Below we simply set our form method to “post” in our html, and control will be given to the route we have defined below it.</p>601 602 <pre><code> <form method="post" action="/">603 <input type="text" name="user[name]" />604 <input type="text" name="user[email]" />605 <input type="submit" value="Submit" />577- </form></code></pre>606+ </form>607+</code></pre>608 579-<p>By default Express does not know what to do with this request body, so we should add the <em>bodyParser</em> middleware, which will parse <em>application/x-www-form-urlencoded</em> and <em>application/json</em> request bodies and place the variables in <em>req.body</em>. We can do this by "using" the middleware as shown below:</p>609+<p>By default Express does not know what to do with this request body, so we should add the <em>bodyParser</em> middleware, which will parse <em>application/x-www-form-urlencoded</em> and <em>application/json</em> request bodies and place the variables in <em>req.body</em>. We can do this by “using” the middleware as shown below:</p>610 581-<pre><code>app.use(express.bodyParser());</code></pre>611+<pre><code>app.use(express.bodyParser());612+</code></pre>613 614 <p>Our route below will now have access to the <em>req.body.user</em> object which will contain the <em>name</em> and <em>email</em> properties when defined.</p>615 616 <pre><code>app.post('/', function(req, res){617 console.log(req.body.user);618 res.redirect('back');619+});588-});</code></pre>620+</code></pre>621 590-<p>When using methods such as <em>PUT</em> with a form, we can utilize a hidden input named <em>_method</em>, which can be used to alter the HTTP method. To do so we first need the <em>methodOverride</em> middleware, which should be placed below <em>bodyParser</em> so that it can utilize it's <em>req.body</em> containing the form values.</p>622+<p>When using methods such as <em>PUT</em> with a form, we can utilize a hidden input named <em>_method</em>, which can be used to alter the HTTP method. To do so we first need the <em>methodOverride</em> middleware, which should be placed below <em>bodyParser</em> so that it can utilize it’s <em>req.body</em> containing the form values.</p>623 624 <pre><code>app.use(express.bodyParser());593-app.use(express.methodOverride());</code></pre>625+app.use(express.methodOverride());626+</code></pre>627 628 <p>The reason that these are not always defaults, is simply because these are not required for Express to be fully functional. Depending on the needs of your application, you may not need these at all, your methods such as <em>PUT</em> and <em>DELETE</em> can still be accessed by clients which can use them directly, although <em>methodOverride</em> provides a great solution for forms. Below shows what the usage of <em>PUT</em> might look like:</p>629 630 <pre><code><form method="post" action="/">5 unmodified lines636 637 app.put('/', function(){638 console.log(req.body.user);639 res.redirect('back');640+});607-});</code></pre>641+</code></pre>642 609-<h3 id="Error-Handling">Error Handling</h3>643+<h3 id="error-handling">Error Handling</h3>644 645 <p>Express provides the <em>app.error()</em> method which receives exceptions thrown within a route,646 or passed to <em>next(err)</em>. Below is an example which serves different pages based on our647 ad-hoc <em>NotFound</em> exception:</p>3 unmodified lines651 Error.call(this, msg);652 Error.captureStackTrace(this, arguments.callee);653 }654 621-NotFound.protoype.__proto__ = Error.prototype;655+NotFound.prototype.__proto__ = Error.prototype;656 657 app.get('/404', function(req, res){658 throw new NotFound;659 });660 661 app.get('/500', function(req, res){662 throw new Error('keyboard cat!');663+});629-});</code></pre>664+</code></pre>665 666 <p>We can call <em>app.error()</em> several times as shown below.667 Here we check for an instanceof <em>NotFound</em> and show the668 404 page, or we pass on to the next error handler.</p>669 670 <p>Note that these handlers can be defined anywhere, as they636-will be placed below the route handlers on <em>listen()</em>. This 671+will be placed below the route handlers on <em>listen()</em>. This672 allows for definition within <em>configure()</em> blocks so we can673 handle exceptions in different ways based on the environment.</p>674 675 <pre><code>app.error(function(err, req, res, next){1 unmodified line677 res.render('404.jade');678 } else {679 next(err);680 }681+});646-});</code></pre>682+</code></pre>683 684 <p>Here we assume all errors as 500 for the simplicity of649-this demo, however you can choose whatever you like. For example when node performs filesystem syscalls, you may receive an error object with the <em>error.code</em> of <em>ENOENT</em>, meaning "no such file or directory", we can utilize this in our error handling and display a page specific to this if desired.</p>685+this demo, however you can choose whatever you like. For example when node performs filesystem syscalls, you may receive an error object with the <em>error.code</em> of <em>ENOENT</em>, meaning “no such file or directory”, we can utilize this in our error handling and display a page specific to this if desired.</p>686 687 <pre><code>app.error(function(err, req, res){688 res.render('500.jade', {689 error: err690 });691+});655-});</code></pre>692+</code></pre>693 694 <p>Our apps could also utilize the Connect <em>errorHandler</em> middleware658-to report on exceptions. For example if we wish to output exceptions 659-in "development" mode to <em>stderr</em> we can use:</p>695+to report on exceptions. For example if we wish to output exceptions696+in “development” mode to <em>stderr</em> we can use:</p>697 661-<pre><code>app.use(express.errorHandler({ dumpExceptions: true }));</code></pre>698+<pre><code>app.use(express.errorHandler({ dumpExceptions: true }));699+</code></pre>700 701 <p>Also during development we may want fancy html pages to show exceptions702 that are passed or thrown, so we can set <em>showStack</em> to true:</p>703 666-<pre><code>app.use(express.errorHandler({ showStack: true, dumpExceptions: true }));</code></pre>704+<pre><code>app.use(express.errorHandler({ showStack: true, dumpExceptions: true }));705+</code></pre>706 707 <p>The <em>errorHandler</em> middleware also responds with <em>json</em> if <em>Accept: application/json</em>708 is present, which is useful for developing apps that rely heavily on client-side JavaScript.</p>709 671-<h3 id="Route-Param-Pre-conditions">Route Param Pre-conditions</h3>710+<h3 id="route-param pre-conditions">Route Param Pre-conditions</h3>711 712 <p>Route param pre-conditions can drastically improve the readability of your application, through implicit loading of data, and validation of request urls. For example if you are constantly fetching common data for several routes, such as loading a user for <em>/user/:id</em>, we might typically do something like below:</p>713 714 <pre><code>app.get('/user/:userId', function(req, res, next){715 User.get(req.params.userId, function(err, user){716 if (err) return next(err);717 res.send('user ' + user.name);718 });719+}); 680-}); </code></pre>720+</code></pre>721 722 <p>With preconditions our params can be mapped to callbacks which may perform validation, coercion, or even loading data from a database. Below we invoke <em>app.param()</em> with the parameter name we wish to map to some middleware, as you can see we receive the <em>id</em> argument which contains the placeholder value. Using this we load the user and perform error handling as usual, and simple call <em>next()</em> to pass control to the next precondition or route handler.</p>723 724 <pre><code>app.param('userId', function(req, res, next, id){2 unmodified lines727 if (!user) return next(new Error('failed to find user'));728 req.user = user;729 next();730 });731+});691-});</code></pre>732+</code></pre>733 734 <p>Doing so, as mentioned drastically improves our route readability, and allows us to easily share this logic throughout our application:</p>735 736 <pre><code>app.get('/user/:userId', function(req, res){737 res.send('user ' + req.user.name);738+});697-});</code></pre>739+</code></pre>740 741 <p>For simple cases such as route placeholder validation and coercion we can simple pass a callback which has an arity of 1 (accepts one argument). Any errors thrown will be passed to <em>next(err)</em>.</p>742 701-<pre><code>app.param('number', function(n){ return parseInt(n, 10); });</code></pre>743+<pre><code>app.param('number', function(n){ return parseInt(n, 10); });744+</code></pre>745 746 <p>We may also apply the same callback to several placeholders, for example a route GET <em>/commits/:from-:to</em> are both numbers, so we may define them as an array:</p>747 705-<pre><code>app.param(['from', 'to'], function(n){ return parseInt(n, 10); });</code></pre>748+<pre><code>app.param(['from', 'to'], function(n){ return parseInt(n, 10); });749+</code></pre>750 707-<h3 id="View-Rendering">View Rendering</h3>751+<h3 id="view-rendering">View Rendering</h3>752 709-<p>View filenames take the form "&lt;name&gt;.&lt;engine&gt;", where &lt;engine&gt; is the name753+<p>View filenames take the form “<name>.<engine>”, where <engine> is the name754 of the module that will be required. For example the view <em>layout.ejs</em> will711-tell the view system to <em>require('ejs')</em>, the module being loaded must export the method <em>exports.compile(str, options)</em>, and return a <em>Function</em> to comply with Express. To alter this behaviour712-<em>app.register()</em> can be used to map engines to file extensions, so that for example "foo.html" can be rendered by ejs.</p>755+tell the view system to <em>require(‘ejs’)</em>, the module being loaded must export the method <em>exports.compile(str, options)</em>, and return a <em>Function</em> to comply with Express. To alter this behaviour756+<em>app.register()</em> can be used to map engines to file extensions, so that for example “foo.html” can be rendered by ejs.</p>757 758 <p>Below is an example using <a href="http://github.com/visionmedia/jade">Jade</a> to render <em>index.html</em>,715-and since we do not use <em>layout: false</em> the rendered contents of <em>index.jade</em> will be passed as 759+and since we do not use <em>layout: false</em> the rendered contents of <em>index.jade</em> will be passed as760 the <em>body</em> local variable in <em>layout.jade</em>.</p>761 762 <pre><code>app.get('/', function(req, res){719- res.render('index.jade', { title: 'My Site' });720-});</code></pre>763+ res.render('index.jade', { title: 'My Site' });764+});765+</code></pre>766 767 <p>The new <em>view engine</em> setting allows us to specify our default template engine,768 so for example when using jade we could set:</p>769 725-<pre><code>app.set('view engine', 'jade');</code></pre>770+<pre><code>app.set('view engine', 'jade');771+</code></pre>772 773 <p>Allowing us to render with:</p>774 729-<pre><code>res.render('index');</code></pre>775+<pre><code>res.render('index');776+</code></pre>777 778 <p>vs:</p>779 733-<pre><code>res.render('index.jade');</code></pre>780+<pre><code>res.render('index.jade');781+</code></pre>782 783 <p>When <em>view engine</em> is set, extensions are entirely optional, however we can still784 mix and match template engines:</p>785 738-<pre><code>res.render('another-page.ejs');</code></pre>786+<pre><code>res.render('another-page.ejs');787+</code></pre>788 789 <p>Express also provides the <em>view options</em> setting, which is applied each time a view is rendered, so for example if you rarely use layouts you may set:</p>790 791 <pre><code>app.set('view options', {792 layout: false793+});744-});</code></pre>794+</code></pre>795 796 <p>Which can then be overridden within the <em>res.render()</em> call if need be:</p>797 748-<pre><code>res.render('myview.ejs', { layout: true });</code></pre>798+<pre><code>res.render('myview.ejs', { layout: true });799+</code></pre>800 801 <p>When an alternate layout is required, we may also specify a path. For example if we have <em>view engine</em> set to <em>jade</em> and a file named <em>./views/mylayout.jade</em> we can simply pass:</p>802 752-<pre><code>res.render('page', { layout: 'mylayout' });</code></pre>803+<pre><code>res.render('page', { layout: 'mylayout' });804+</code></pre>805 806 <p>Otherwise we must specify the extension:</p>807 756-<pre><code>res.render('page', { layout: 'mylayout.jade' });</code></pre>808+<pre><code>res.render('page', { layout: 'mylayout.jade' });809+</code></pre>810 811 <p>These paths may also be absolute:</p>812 760-<pre><code>res.render('page', { layout: __dirname + '/../../mylayout.jade' });</code></pre>813+<pre><code>res.render('page', { layout: __dirname + '/../../mylayout.jade' });814+</code></pre>815 816 <p>A good example of this is specifying custom <em>ejs</em> opening and closing tags:</p>817 818 <pre><code>app.set('view options', {819 open: '{{',820 close: '}}'821+});767-});</code></pre>822+</code></pre>823 769-<h3 id="View-Partials">View Partials</h3>824+<h3 id="view-partials">View Partials</h3>825 771-<p>The Express view system has built-in support for partials and collections, which are "mini" views representing a document fragment. For example rather than iterating826+<p>The Express view system has built-in support for partials and collections, which are “mini” views representing a document fragment. For example rather than iterating827 in a view to display comments, we could use partial collection:</p>828 774-<pre><code>partial('comment', { collection: comments });</code></pre>829+<pre><code>partial('comment', { collection: comments });830+</code></pre>831 832 <p>If no other options or local variables are desired, we can omit the object and simply pass our array, which is equivalent to above:</p>833 778-<pre><code>partial('comment', comments);</code></pre>834+<pre><code>partial('comment', comments);835+</code></pre>836 780-<p>When using the partial collection support a few "magic" locals are provided837+<p>When using the partial collection support a few “magic” locals are provided838 for free:</p>839 783-<ul><li><em>firstInCollection</em> true if this is the first object</li><li><em>indexInCollection</em> index of the object in the collection</li><li><em>lastInCollection</em> true if this is the last object</li><li><em>collectionLength</em> length of the collection</li></ul>840+<ul>841+<li><em>firstInCollection</em> true if this is the first object</li>842+<li><em>indexInCollection</em> index of the object in the collection</li>843+<li><em>lastInCollection</em> true if this is the last object</li>844+<li><em>collectionLength</em> length of the collection</li>845+</ul>846 785-<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>847 848+<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>849+850 <p>For documentation on altering the object name view <a href="http://expressjs.com/guide.html#res-partial-view-options-">res.partial()</a>.</p>851 852 <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>853 791-<h3 id="View-Lookup">View Lookup</h3>854+<h3 id="view-lookup">View Lookup</h3>855 793-<p>View lookup is performed relative to the parent view, for example if we had a page view named <em>views/user/list.jade</em>, and within that view we did <em>partial('edit')</em> it would attempt to load <em>views/user/edit.jade</em>, whereas <em>partial('../messages')</em> would load <em>views/messages.jade</em>.</p>856+<p>View lookup is performed relative to the parent view, for example if we had a page view named <em>views/user/list.jade</em>, and within that view we did <em>partial(‘edit’)</em> it would attempt to load <em>views/user/edit.jade</em>, whereas <em>partial(‘../messages’)</em> would load <em>views/messages.jade</em>.</p>857 795-<p>The view system also allows for index templates, allowing you to have a directory of the same name. For example within a route we may have <em>res.render('users')</em> either <em>views/users.jade</em>, or <em>views/users/index.jade</em>.</p>858+<p>The view system also allows for index templates, allowing you to have a directory of the same name. For example within a route we may have <em>res.render(‘users’)</em> either <em>views/users.jade</em>, or <em>views/users/index.jade</em>.</p>859 797-<p>When utilizing index views as shown above, we may reference <em>views/users/index.jade</em> from a view in the same directory by <em>partial('users')</em>, and the view system will try <em>../users/index</em>, preventing us from needing to call <em>partial('index')</em>.</p>860+<p>When utilizing index views as shown above, we may reference <em>views/users/index.jade</em> from a view in the same directory by <em>partial(‘users’)</em>, and the view system will try <em>../users/index</em>, preventing us from needing to call <em>partial(‘index’)</em>.</p>861 799-<h3 id="Template-Engines">Template Engines</h3>862+<h3 id="template-engines">Template Engines</h3>863 864 <p>Below are a few template engines commonly used with Express:</p>865 803-<ul><li><a href="http://github.com/visionmedia/haml.js">Haml</a> haml implementation</li><li><a href="http://jade-lang.com">Jade</a> haml.js successor</li><li><a href="http://github.com/visionmedia/ejs">EJS</a> Embedded JavaScript</li><li><a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a> CoffeeScript based templating</li><li><a href="https://github.com/kof/node-jqtpl">jQuery Templates</a> for node</li></ul>866+<ul>867+<li><a href="http://github.com/visionmedia/haml.js">Haml</a> haml implementation</li>868+<li><a href="http://jade-lang.com">Jade</a> haml.js successor</li>869+<li><a href="http://github.com/visionmedia/ejs">EJS</a> Embedded JavaScript</li>870+<li><a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a> CoffeeScript based templating</li>871+<li><a href="https://github.com/kof/node-jqtpl">jQuery Templates</a> for node</li>872+</ul>873 805-<h3 id="Session-Support">Session Support</h3>874 807-<p>Sessions support can be added by using Connect's <em>session</em> middleware. To do so we also need the <em>cookieParser</em> middleware place above it, which will parse and populate cookie data to <em>req.cookies</em>.</p>875+<h3 id="session-support">Session Support</h3>876 877+<p>Sessions support can be added by using Connect’s <em>session</em> middleware. To do so we also need the <em>cookieParser</em> middleware place above it, which will parse and populate cookie data to <em>req.cookies</em>.</p>878+879 <pre><code>app.use(express.cookieParser());810-app.use(express.session({ secret: "keyboard cat" }));</code></pre>880+app.use(express.session({ secret: "keyboard cat" }));881+</code></pre>882 883 <p>By default the <em>session</em> middleware uses the memory store bundled with Connect, however many implementations exist. For example <a href="http://github.com/visionmedia/connect-redis">connect-redis</a> supplies a <a href="http://code.google.com/p/redis/">Redis</a> session store and can be used as shown below:</p>884 885 <pre><code>var RedisStore = require('connect-redis');886 app.use(express.cookieParser());816-app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));</code></pre>887+app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));888+</code></pre>889 890 <p>Now the <em>req.session</em> and <em>req.sessionStore</em> properties will be accessible to all routes and subsequent middleware. Properties on <em>req.session</em> are automatically saved on a response, so for example if we wish to shopping cart data:</p>891 892 <pre><code>var RedisStore = require('connect-redis');16 unmodified lines909 if (req.session.items && req.session.items.length) {910 req.flash('info', 'You have %s items in your cart', req.session.items.length);911 }912 res.render('shopping-cart');913+});841-});</code></pre>914+</code></pre>915 916 <p>The <em>req.session</em> object also has methods such as <em>Session#touch()</em>, <em>Session#destroy()</em>, <em>Session#regenerate()</em> among others to maintain and manipulate sessions. For more information view the <a href="http://senchalabs.github.com/connect/middleware-session.html">Connect Session</a> documentation.</p>917 845-<h3 id="Migration-Guide">Migration Guide</h3>918+<h3 id="migration-guide">Migration Guide</h3>919 920 <p> Express 1.x developers may reference the <a href="migrate.html">Migration Guide</a> 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.</p>921 849-<h3 id="req-header-key-defaultValue">req.header(key[, defaultValue])</h3>922+<h3 id="req.header()">req.header(key[, defaultValue])</h3>923 924 <p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>925 926 <pre><code>req.header('Host');927 req.header('host');855-req.header('Accept', '*/*');</code></pre>928+req.header('Accept', '*/*');929+</code></pre>930 931 <p>The <em>Referrer</em> and <em>Referer</em> header fields are special-cased, either will work:</p>932 933 <pre><code>// sent Referrer: http://google.com1 unmodified line935 req.header('Referer');936 // => "http://google.com"937 938 req.header('Referrer');865-// => "http://google.com"</code></pre>939+// => "http://google.com"940+</code></pre>941 867-<h3 id="req-accepts-type">req.accepts(type)</h3>942+<h3 id="req.accepts()">req.accepts(type)</h3>943 944 <p>Check if the <em>Accept</em> header is present, and includes the given <em>type</em>.</p>945 946 <p>When the <em>Accept</em> header is not present <em>true</em> is returned. Otherwise947 the given <em>type</em> is matched by an exact match, and then subtypes. You873-may pass the subtype such as "html" which is then converted internally874-to "text/html" using the mime lookup table.</p>948+may pass the subtype such as “html” which is then converted internally949+to “text/html” using the mime lookup table.</p>950 951 <pre><code>// Accept: text/html952 req.accepts('html');953 // => true6 unmodified lines960 // => true961 962 req.accepts('image/png');963 req.accepts('png');889-// => false</code></pre>964+// => false965+</code></pre>966 891-<h3 id="req-is-type">req.is(type)</h3>967+<h3 id="req.is()">req.is(type)</h3>968 969 <p>Check if the incoming request contains the <em>Content-Type</em>970 header field, and it contains the give mime <em>type</em>.</p>971 7 unmodified lines979 req.is('application/json');980 // => true981 982 req.is('html');907- // => false</code></pre>983+ // => false984+</code></pre>985 986 <p>Ad-hoc callbacks can also be registered with Express, to perform987 assertions again the request, for example if we need an expressive911-way to check if our incoming request is an image, we can register <em>"an image"</em>988+way to check if our incoming request is an image, we can register <em>“an image”</em>989 callback:</p>990 991 <pre><code> app.is('an image', function(req){992 return 0 == req.headers['content-type'].indexOf('image');993+ });916- });</code></pre>994+</code></pre>995 996 <p>Now within our route callbacks, we can use to to assert content types919-such as <em>"image/jpeg"</em>, <em>"image/png"</em>, etc.</p>997+such as <em>“image/jpeg”</em>, <em>“image/png”</em>, etc.</p>998 999 <pre><code> app.post('/image/upload', function(req, res, next){1000 if (req.is('an image')) {1001 // do something1002 } else {1003 next();1004 }1005+ });927- });</code></pre>1006+</code></pre>1007 1008 <p>Keep in mind this method is <em>not</em> limited to checking <em>Content-Type</em>, you1009 can perform any request assertion you wish.</p>1010 932-<p>Wildcard matches can also be made, simplifying our example above for <em>"an image"</em>, by asserting the <em>subtype</em> only:</p>1011+<p>Wildcard matches can also be made, simplifying our example above for <em>“an image”</em>, by asserting the <em>subtype</em> only:</p>1012 934-<pre><code>req.is('image/*');</code></pre>1013+<pre><code>req.is('image/*');1014+</code></pre>1015 936-<p>We may also assert the <em>type</em> as shown below, which would return true for <em>"application/json"</em>, and <em>"text/json"</em>.</p>1016+<p>We may also assert the <em>type</em> as shown below, which would return true for <em>“application/json”</em>, and <em>“text/json”</em>.</p>1017 938-<pre><code>req.is('*/json');</code></pre>1018+<pre><code>req.is('*/json');1019+</code></pre>1020 940-<h3 id="req-param-name-default">req.param(name[, default])</h3>1021+<h3 id="req.param()">req.param(name[, default])</h3>1022 1023 <p>Return the value of param <em>name</em> when present or <em>default</em>.</p>1024 944-<ul><li>Checks route params (<em>req.params</em>), ex: /user/:id</li><li>Checks query string params (<em>req.query</em>), ex: ?id=12</li><li>Checks urlencoded body params (<em>req.body</em>), ex: id=12</li></ul>1025+<ul>1026+<li>Checks route params (<em>req.params</em>), ex: /user/:id</li>1027+<li>Checks query string params (<em>req.query</em>), ex: ?id=12</li>1028+<li>Checks urlencoded body params (<em>req.body</em>), ex: id=12</li>1029+</ul>1030 1031+1032 <p>To utilize urlencoded request bodies, <em>req.body</em>1033 should be an object. This can be done by using1034 the _express.bodyParser middleware.</p>1035 950-<h3 id="req-flash-type-msg">req.flash(type[, msg])</h3>1036+<h3 id="req.flash()">req.flash(type[, msg])</h3>1037 1038 <p>Queue flash <em>msg</em> of the given <em>type</em>.</p>1039 1040 <pre><code>req.flash('info', 'email sent');7 unmodified lines1048 req.flash('info');1049 // => []1050 1051 req.flash();966-// => { error: ['email delivery failed'], info: [] }</code></pre>1052+// => { error: ['email delivery failed'], info: [] }1053+</code></pre>1054 1055 <p>Flash notification message may also utilize formatters, by default only the %s string formatter is available:</p>1056 970-<pre><code>req.flash('info', 'email delivery to _%s_ from _%s_ failed.', toUser, fromUser);</code></pre>1057+<pre><code>req.flash('info', 'email delivery to _%s_ from _%s_ failed.', toUser, fromUser);1058+</code></pre>1059 972-<h3 id="req-isXMLHttpRequest">req.isXMLHttpRequest</h3>1060+<h3 id="req.isxmlhttprequest">req.isXMLHttpRequest</h3>1061 1062 <p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header1063 to see if it was issued by an <em>XMLHttpRequest</em>:</p>1064 1065 <pre><code>req.xhr978-req.isXMLHttpRequest</code></pre>1066+req.isXMLHttpRequest1067+</code></pre>1068 980-<h3 id="res-header-key-val">res.header(key[, val])</h3>1069+<h3 id="res.header()">res.header(key[, val])</h3>1070 1071 <p>Get or set the response header <em>key</em>.</p>1072 1073 <pre><code>res.header('Content-Length');2 unmodified lines1076 res.header('Content-Length', 123);1077 // => 1231078 1079 res.header('Content-Length');991-// => 123</code></pre>1080+// => 1231081+</code></pre>1082 993-<h3 id="res-charset">res.charset</h3>1083+<h3 id="res.charset">res.charset</h3>1084 995-<p>Sets the charset for subsequent <code>Content-Type</code> header fields. For example <code>res.send()</code> and <code>res.render()</code> default to "utf8", so we may explicitly set the charset before rendering a template:</p>1085+<p>Sets the charset for subsequent <code>Content-Type</code> header fields. For example <code>res.send()</code> and <code>res.render()</code> default to “utf8”, so we may explicitly set the charset before rendering a template:</p>1086 1087 <pre><code>res.charset = 'ISO-8859-1';998-res.render('users');</code></pre>1088+res.render('users');1089+</code></pre>1090 1091 <p>or before responding with <code>res.send()</code>:</p>1092 1093 <pre><code>res.charset = 'ISO-8859-1';1003-res.send(str);</code></pre>1094+res.send(str);1095+</code></pre>1096 1005-<p>or with node's <code>res.end()</code>:</p>1097+<p>or with node’s <code>res.end()</code>:</p>1098 1099 <pre><code>res.charset = 'ISO-8859-1';1100 res.header('Content-Type', 'text/plain');1009-res.end(str);</code></pre>1101+res.end(str);1102+</code></pre>1103 1011-<h3 id="res-contentType-type">res.contentType(type)</h3>1104+<h3 id="res.contenttype()">res.contentType(type)</h3>1105 1106 <p>Sets the <em>Content-Type</em> response header to the given <em>type</em>.</p>1107 1108 <pre><code> var filename = 'path/to/image.png';1109 res.contentType(filename);1017- // Content-Type is now "image/png"</code></pre>1110+ // Content-Type is now "image/png"1111+</code></pre>1112 1113 <p>A literal <em>Content-Type</em> works as well:</p>1114 1021-<pre><code> res.contentType('application/json');</code></pre>1115+<pre><code> res.contentType('application/json');1116+</code></pre>1117 1118 <p>Or simply the extension without leading <code>.</code>:</p>1119 1025-<pre><code> res.contentType('json');</code></pre>1120+<pre><code> res.contentType('json');1121+</code></pre>1122 1027-<h3 id="res-attachment-filename">res.attachment([filename])</h3>1123+<h3 id="res.attachment()">res.attachment([filename])</h3>1124 1029-<p>Sets the <em>Content-Disposition</em> response header to "attachment", with optional <em>filename</em>.</p>1125+<p>Sets the <em>Content-Disposition</em> response header to “attachment”, with optional <em>filename</em>.</p>1126 1031-<pre><code> res.attachment('path/to/my/image.png');</code></pre>1127+<pre><code> res.attachment('path/to/my/image.png');1128+</code></pre>1129 1033-<h3 id="res-sendfile-path-options-callback">res.sendfile(path[, options[, callback]])</h3>1130+<h3 id="res.sendfile()">res.sendfile(path[, options[, callback]])</h3>1131 1035-<p>Used by <code>res.download()</code> to transfer an arbitrary file. </p>1132+<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>1133 1037-<pre><code>res.sendfile('path/to/my.file');</code></pre>1134+<pre><code>res.sendfile('path/to/my.file');1135+</code></pre>1136 1137 <p>This method accepts an optional callback which is called when1138 an error occurs, or when the transfer is complete. By default failures call <code>next(err)</code>, however when a callback is supplied you must do this explicitly, or act on the error.</p>1139 2 unmodified lines1142 next(err);1143 } else {1144 console.log('transferred %s', path);1145 }1146+});1048-});</code></pre>1147+</code></pre>1148 1149 <p>Options may also be passed to the internal <em>fs.createReadStream()</em> call, for example altering the <em>bufferSize</em>:</p>1150 1151 <pre><code>res.sendfile(path, { bufferSize: 1024 }, function(err){1152 // handle1153+});1054-});</code></pre>1154+</code></pre>1155 1056-<h3 id="res-download-file-filename-callback">res.download(file[, filename[, callback]])</h3>1156+<h3 id="res.download()">res.download(file[, filename[, callback]])</h3>1157 1158 <p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>1159 1160 <pre><code>res.download('path/to/image.png');1061-res.download('path/to/image.png', 'foo.png');</code></pre>1161+res.download('path/to/image.png', 'foo.png');1162+</code></pre>1163 1164 <p>This is equivalent to:</p>1165 1166 <pre><code>res.attachment(file);1066-res.sendfile(file);</code></pre>1167+res.sendfile(file);1168+</code></pre>1169 1170 <p>An optional callback may be supplied as either the second or third argument, which is passed to <em>res.sendfile()</em>:</p>1171 1172 <pre><code>res.download(path, 'expenses.doc', function(err){1173 // handle1174+});1072-});</code></pre>1175+</code></pre>1176 1074-<h3 id="res-send-body-status-headers-status-status">res.send(body|status[, headers|status[, status]])</h3>1177+<h3 id="res.send()">res.send(body|status[, headers|status[, status]])</h3>1178 1179 <p>The <em>res.send()</em> method is a high level response utility allowing you to pass1180 objects to respond with json, strings for html, Buffer instances, or numbers representing the status code. The following are all valid uses:</p>1181 2 unmodified lines1184 res.send({ some: 'json' });1185 res.send('<p>some html</p>');1186 res.send('Sorry, cant find that', 404);1187 res.send('text', { 'Content-Type': 'text/plain' }, 201);1085- res.send(404);</code></pre>1188+ res.send(404);1189+</code></pre>1190 1191 <p>By default the <em>Content-Type</em> response header is set, however if explicitly1192 assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>1193 it will not be set again.</p>1194 1091-<p>Note that this method <em>end()</em>s the response, so you will want to use node's <em>res.write()</em> for multiple writes or streaming.</p>1195+<p>Note that this method <em>end()</em>s the response, so you will want to use node’s <em>res.write()</em> for multiple writes or streaming.</p>1196 1093-<h3 id="res-redirect-url-status">res.redirect(url[, status])</h3>1197+<h3 id="res.redirect()">res.redirect(url[, status])</h3>1198 1199 <p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>1200 1201 <pre><code>res.redirect('/', 301);1202 res.redirect('/account');1203 res.redirect('http://google.com');1204 res.redirect('home');1101-res.redirect('back');</code></pre>1205+res.redirect('back');1206+</code></pre>1207 1103-<p>Express supports "redirect mapping", which by default provides <em>home</em>, and <em>back</em>.1208+<p>Express supports “redirect mapping”, which by default provides <em>home</em>, and <em>back</em>.1209 The <em>back</em> map checks the <em>Referrer</em> and <em>Referer</em> headers, while <em>home</em> utilizes1105-the "home" setting and defaults to "/".</p>1210+the “home” setting and defaults to “/”.</p>1211 1107-<h3 id="res-cookie-name-val-options">res.cookie(name, val[, options])</h3>1212+<h3 id="res.cookie()">res.cookie(name, val[, options])</h3>1213 1214 <p>Sets the given cookie <em>name</em> to <em>val</em>, with options <em>httpOnly</em>, <em>secure</em>, <em>expires</em> etc.</p>1215 1216 <pre><code>// "Remember me" for 15 minutes 1112-res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000), httpOnly: true });</code></pre>1217+res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000), httpOnly: true });1218+</code></pre>1219 1220 <p>The <em>maxAge</em> property may be used to set <em>expires</em> relative to <em>Date.now()</em> in milliseconds, so our example above can now become:</p>1221 1116-<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });</code></pre>1222+<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });1223+</code></pre>1224 1225 <p>To parse incoming <em>Cookie</em> headers, use the <em>cookieDecoder</em> middleware, which provides the <em>req.cookies</em> object:</p>1226 1227 <pre><code>app.use(express.cookieParser());1228 1229 app.get('/', function(req, res){1230 // use req.cookies.rememberme1231+});1124-});</code></pre>1232+</code></pre>1233 1126-<h3 id="res-clearCookie-name">res.clearCookie(name)</h3>1234+<h3 id="res.clearcookie()">res.clearCookie(name)</h3>1235 1128-<p>Clear cookie <em>name</em> by setting "expires" far in the past.</p>1236+<p>Clear cookie <em>name</em> by setting “expires” far in the past.</p>1237 1130-<pre><code>res.clearCookie('rememberme');</code></pre>1238+<pre><code>res.clearCookie('rememberme');1239+</code></pre>1240 1132-<h3 id="res-render-view-options-fn">res.render(view[, options[, fn]])</h3>1241+<h3 id="res.render()">res.render(view[, options[, fn]])</h3>1242 1243 <p>Render <em>view</em> with the given <em>options</em> and optional callback <em>fn</em>.1244 When a callback function is given a response will <em>not</em> be made1245 automatically, however otherwise a response of <em>200</em> and <em>text/html</em> is given.</p>1246 1138-<p>The <em>options</em> passed are the local variables as well, for example if we want to expose "user" to the view, and prevent a local we do so within the same object:</p>1247+<p>The <em>options</em> passed are the local variables as well, for example if we want to expose “user” to the view, and prevent a local we do so within the same object:</p>1248 1249 <pre><code>var user = { name: 'tj' };1141-res.render('index', { layout: false, user: user });</code></pre>1250+res.render('index', { layout: false, user: user });1251+</code></pre>1252 1143-<h3 id="res-partial-view-options">res.partial(view[, options])</h3>1253+<h3 id="res.partial()">res.partial(view[, options])</h3>1254 1255 <p>Render <em>view</em> partial with the given <em>options</em>. This method is always available1256 to the view as a local variable.</p>1257 1148-<ul><li><em>object</em> the object named by <em>as</em> or derived from the view name</li><li><p><em>as</em> Variable name for each <em>collection</em> or <em>object</em> value, defaults to the view name.</p><ul><li>as: 'something' will add the <em>something</em> local variable</li><li>as: this will use the collection value as the template context</li><li><p>as: global will merge the collection value's properties with <em>locals</em></p></li></ul></li><li><p><em>collection</em> Array of objects, the name is derived from the view name itself. 1149-For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li></ul>1258+<ul>1259+<li><em>object</em> the object named by <em>as</em> or derived from the view name</li>1260+<li><p><em>as</em> Variable name for each <em>collection</em> or <em>object</em> value, defaults to the view name.</p>1261 1262+<ul>1263+<li>as: ‘something’ will add the <em>something</em> local variable</li>1264+<li>as: this will use the collection value as the template context</li>1265+<li>as: global will merge the collection value’s properties with <em>locals</em></li>1266+</ul>1267+</li>1268+<li><p><em>collection</em> Array of objects, the name is derived from the view name itself.1269+For example <em>video.html</em> will have a object <em>video</em> available to it.</p></li>1270+</ul>1271+1272+1273 <p>The following are equivalent, and the name of collection value when passed1274 to the partial will be <em>movie</em> as derived from the name.</p>1275 1276 <pre><code>partial('theatre/movie.jade', { collection: movies });1277 partial('theatre/movie.jade', movies);1278 partial('movie.jade', { collection: movies });1279 partial('movie.jade', movies);1280 partial('movie', movies);1159-// In view: movie.director</code></pre>1281+// In view: movie.director1282+</code></pre>1283 1161-<p>To change the local from <em>movie</em> to <em>video</em> we can use the "as" option:</p>1284+<p>To change the local from <em>movie</em> to <em>video</em> we can use the “as” option:</p>1285 1286 <pre><code>partial('movie', { collection: movies, as: 'video' });1164-// In view: video.director</code></pre>1287+// In view: video.director1288+</code></pre>1289 1290 <p>Also we can make our movie the value of <em>this</em> within our view so that instead1291 of <em>movie.director</em> we could use <em>this.director</em>.</p>1292 1293 <pre><code>partial('movie', { collection: movies, as: this });1170-// In view: this.director</code></pre>1294+// In view: this.director1295+</code></pre>1296 1172-<p>Another alternative is to "expand" the properties of the collection item into1297+<p>Another alternative is to “expand” the properties of the collection item into1298 pseudo globals (local variables) by using <em>as: global</em>, which again is syntactic sugar:</p>1299 1300 <pre><code>partial('movie', { collection: movies, as: global });1176-// In view: director</code></pre>1301+// In view: director1302+</code></pre>1303 1304 <p>This same logic applies to a single partial object usage:</p>1305 1306 <pre><code>partial('movie', { object: movie, as: this });5 unmodified lines1312 partial('movie', { object: movie, as: 'video' });1313 // In view: video.director1314 1315 partial('movie', { object: movie });1190-// In view: movie.director</code></pre>1316+// In view: movie.director1317+</code></pre>1318 1192-<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>1319+<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>1320 1321 <pre><code>var movie = new Movie('Nightmare Before Christmas', 'Tim Burton')1322 partial('movie', movie)1196-// => In view: movie.director</code></pre>1323+// => In view: movie.director1324+</code></pre>1325 1198-<p>The exception of this, is when a "plain" object, aka "{}" or "new Object" is passed, which is considered an object with local variable. For example some may expect a "movie" local with the following, however since it is a plain object "director" and "title" are simply locals:</p>1326+<p>The exception of this, is when a “plain” object, aka “{}” or “new Object” is passed, which is considered an object with local variable. For example some may expect a “movie” local with the following, however since it is a plain object “director” and “title” are simply locals:</p>1327 1328 <pre><code>var movie = { title: 'Nightmare Before Christmas', director: 'Tim Burton' }; 1201-partial('movie', movie)</code></pre>1329+partial('movie', movie)1330+</code></pre>1331 1332 <p>For cases like this where passing a plain object is desired, simply assign it to a key, or use the <code>object</code> key which will use the filename-derived variable name. The examples below are equivalent:</p>1333 1334 <pre><code> partial('movie', { locals: { movie: movie }})1335 partial('movie', { movie: movie })1207- partial('movie', { object: movie })</code></pre>1336+ partial('movie', { object: movie })1337+</code></pre>1338 1339 <p>This exact API can be utilized from within a route, to respond with a fragment via Ajax or WebSockets, for example we can render a collection of users directly from a route:</p>1340 1341 <pre><code>app.get('/users', function(req, res){6 unmodified lines1348 // which internally does partial('user', users)1349 // along with other UI1350 res.render('users', { users: users });1351 }1352+});1222-});</code></pre>1353+</code></pre>1354 1224-<h3 id="res-local-name-val">res.local(name[, val])</h3>1355+<h3 id="res.local()">res.local(name[, val])</h3>1356 1357 <p>Get or set the given local variable <em>name</em>. The locals built up for a response are applied to those given to the view rendering methods such as <code>res.render()</code>.</p>1358 1359 <pre><code> app.all('/movie/:id', function(req, res, next){6 unmodified lines1366 app.get('/movie/:id', function(req, res){1367 // movie is already a local, however we1368 // can pass more if we wish1369 res.render('movie', { displayReviews: true });1370+ });1239- });</code></pre>1371+</code></pre>1372 1241-<h3 id="res-local-obj">res.local(obj)</h3>1373+<h3 id="res.locals()">res.locals(obj)</h3>1374 1375 <p> Assign several locals with the given <em>obj</em>. The following are equivalent:</p>1376 1377 <pre><code> res.local('foo', bar);1378 res.local('bar', baz);1379 1248- res.locals({ foo: bar, bar, baz });</code></pre>1380+ res.locals({ foo: bar, bar, baz });1381+</code></pre>1382 1250-<h3 id="app-set-name-val">app.set(name[, val])</h3>1383+<h3 id="app.set()">app.set(name[, val])</h3>1384 1385 <p>Apply an application level setting <em>name</em> to <em>val</em>, or1386 get the value of <em>name</em> when <em>val</em> is not present:</p>1387 1388 <pre><code>app.set('views', __dirname + '/views');1389 app.set('views');1257-// => ...path...</code></pre>1390+// => ...path...1391+</code></pre>1392 1393 <p>Alternatively you may simply access the settings via <em>app.settings</em>:</p>1394 1395 <pre><code>app.settings.views1262-// => ...path...</code></pre>1396+// => ...path...1397+</code></pre>1398 1264-<h3 id="app-enable-name">app.enable(name)</h3>1399+<h3 id="app.enable()">app.enable(name)</h3>1400 1401 <p>Enable the given setting <em>name</em>:</p>1402 1403 <pre><code>app.enable('some arbitrary setting');1404 app.set('some arbitrary setting');1405 // => true1406 1407 app.enabled('some arbitrary setting');1273-// => true</code></pre>1408+// => true1409+</code></pre>1410 1275-<h3 id="app-enabled-name">app.enabled(name)</h3>1411+<h3 id="app.enabled()">app.enabled(name)</h3>1412 1413 <p>Check if setting <em>name</em> is enabled:</p>1414 1415 <pre><code>app.enabled('view cache');1416 // => false1417 1418 app.enable('view cache');1419 app.enabled('view cache');1284-// => true</code></pre>1420+// => true1421+</code></pre>1422 1286-<h3 id="app-disable-name">app.disable(name)</h3>1423+<h3 id="app.disable()">app.disable(name)</h3>1424 1425 <p>Disable the given setting <em>name</em>:</p>1426 1427 <pre><code>app.disable('some setting');1428 app.set('some setting');1429 // => false1430 1431 app.disabled('some setting');1295-// => false</code></pre>1432+// => false1433+</code></pre>1434 1297-<h3 id="app-disabled-name">app.disabled(name)</h3>1435+<h3 id="app.disabled()">app.disabled(name)</h3>1436 1437 <p>Check if setting <em>name</em> is disabled:</p>1438 1439 <pre><code>app.enable('view cache');2 unmodified lines1442 // => false1443 1444 app.disable('view cache');1445 app.disabled('view cache');1308-// => true</code></pre>1446+// => true1447+</code></pre>1448 1310-<h3 id="app-configure-env-function-function">app.configure(env|function[, function])</h3>1449+<h3 id="app.configure()">app.configure(env|function[, function])</h3>1450 1451 <p>Define a callback function for the given <em>env</em> (or all environments) with callback <em>function</em>:</p>1452 1453 <pre><code>app.configure(function(){1 unmodified line1455 });1456 1457 app.configure('development', function(){1458 // executed for 'development' only1459+});1320-});</code></pre>1460+</code></pre>1461 1322-<h3 id="app-redirect-name-val">app.redirect(name, val)</h3>1462+<h3 id="app.redirect()">app.redirect(name, val)</h3>1463 1464 <p>For use with <em>res.redirect()</em> we can map redirects at the application level as shown below:</p>1465 1326-<pre><code>app.redirect('google', 'http://google.com');</code></pre>1466+<pre><code>app.redirect('google', 'http://google.com');1467+</code></pre>1468 1469 <p>Now in a route we may call:</p>1470 1330-<p> res.redirect('google');</p>1471+<p> res.redirect(‘google’);</p>1472 1473 <p>We may also map dynamic redirects:</p>1474 1475 <pre><code>app.redirect('comments', function(req, res){1476 return '/post/' + req.params.id + '/comments';1477+});1336-});</code></pre>1478+</code></pre>1479 1480 <p>So now we may do the following, and the redirect will dynamically adjust to1481 the context of the request. If we called this route with <em>GET /post/12</em> our1482 redirect <em>Location</em> would be <em>/post/12/comments</em>.</p>1483 1484 <pre><code>app.get('/post/:id', function(req, res){1485 res.redirect('comments');1486+});1344-});</code></pre>1487+</code></pre>1488 1489 <p>When mounted, <em>res.redirect()</em> will respect the mount-point. For example if a blog app is mounted at <em>/blog</em>, the following will redirect to <em>/blog/posts</em>:</p>1490 1348-<pre><code>res.redirect('/posts');</code></pre>1491+<pre><code>res.redirect('/posts');1492+</code></pre>1493 1350-<h3 id="app-error-function">app.error(function)</h3>1494+<h3 id="app.error()">app.error(function)</h3>1495 1496 <p>Adds an error handler <em>function</em> which will receive the exception as the first parameter as shown below.1497 Note that we may set several error handlers by making several calls to this method, however the handler1498 should call <em>next(err)</em> if it does not wish to deal with the exception:</p>1499 1500 <pre><code>app.error(function(err, req, res, next){1501 res.send(err.message, 500);1502+});1358-});</code></pre>1503+</code></pre>1504 1360-<h3 id="app-helpers-obj">app.helpers(obj)</h3>1505+<h3 id="app.helpers()">app.helpers(obj)</h3>1506 1507 <p>Registers static view helpers.</p>1508 1364-<p> app.helpers({1365- name: function(first, last){ return first + ', ' + last }1366- , firstName: 'tj'1367- , lastName: 'holowaychuk'1368- });</p>1509+<p> app.helpers({</p>1510 1511+<pre><code> name: function(first, last){ return first + ', ' + last }1512+, firstName: 'tj'1513+, lastName: 'holowaychuk'1514+</code></pre>1515+1516+<p> });</p>1517+1518 <p>Our view could now utilize the <em>firstName</em> and <em>lastName</em> variables,1519 as well as the <em>name()</em> function exposed.</p>1520 1373-<pre><code><%= name(firstName, lastName) %></code></pre>1521+<pre><code><%= name(firstName, lastName) %>1522+</code></pre>1523 1375-<h3 id="app-dynamicHelpers-obj">app.dynamicHelpers(obj)</h3>1524+<h3 id="app.dynamichelpers()">app.dynamicHelpers(obj)</h3>1525 1526 <p>Registers dynamic view helpers. Dynamic view helpers1527 are simply functions which accept <em>req</em>, <em>res</em>, and are1528 evaluated against the <em>Server</em> instance before a view is rendered. The <em>return value</em> of this function2 unmodified lines1531 <pre><code>app.dynamicHelpers({1532 session: function(req, res){1533 return req.session;1534 }1535+});1386-});</code></pre>1536+</code></pre>1537 1538 <p>All views would now have <em>session</em> available so that session data can be accessed via <em>session.name</em> etc:</p>1539 1390-<pre><code><%= session.name %></code></pre>1540+<pre><code><%= session.name %>1541+</code></pre>1542 1392-<h3 id="app-mounted-fn">app.mounted(fn)</h3>1543+<h3 id="app.mounted()">app.mounted(fn)</h3>1544 1545 <p>Assign a callback <em>fn</em> which is called when this <em>Server</em> is passed to <em>Server#use()</em>.</p>1546 1547 <pre><code>var app = express.createServer(),3 unmodified lines1551 // parent is app1552 // "this" is blog1553 });1554 1404-app.use(blog);</code></pre>1555+app.use(blog);1556+</code></pre>1557 1406-<h3 id="app-register-ext-exports">app.register(ext, exports)</h3>1558+<h3 id="app.register()">app.register(ext, exports)</h3>1559 1560 <p>Register the given template engine <em>exports</em>1409-as <em>ext</em>. For example we may wish to map ".html"1561+as <em>ext</em>. For example we may wish to map “.html”1562 files to jade:</p>1563 1412-<pre><code> app.register('.html', require('jade'));</code></pre>1564+<pre><code> app.register('.html', require('jade'));1565+</code></pre>1566 1567 <p>This is also useful for libraries that may not1568 match extensions correctly. For example my haml.js1416-library is installed from npm as "hamljs" so instead1417-of layout.hamljs, we can register the engine as ".haml":</p>1569+library is installed from npm as “hamljs” so instead1570+of layout.hamljs, we can register the engine as “.haml”:</p>1571 1419-<pre><code> app.register('.haml', require('haml-js'));</code></pre>1572+<pre><code> app.register('.haml', require('haml-js'));1573+</code></pre>1574 1575 <p>For engines that do not comply with the Express1576 specification, we can also wrap their api this way. Below1577 we map <em>.md</em> to render markdown files, rendering the html once1578 since it will not change on subsequent calls, and support local substitution1425-in the form of "{name}".</p>1579+in the form of “{name}”.</p>1580 1581 <pre><code> app.register('.md', {1582 compile: function(str, options){1583 var html = md.toHTML(str);2 unmodified lines1586 return locals[name];1587 });1588 };1589 }1590+ });1436- });</code></pre>1591+</code></pre>1592 1438-<h3 id="app-listen-port-host">app.listen([port[, host]])</h3>1593+<h3 id="app.listen()">app.listen([port[, host]])</h3>1594 1595 <p>Bind the app server to the given <em>port</em>, which defaults to 3000. When <em>host</em> is omitted all1441-connections will be accepted via <em>INADDR</em>ANY_.</p>1596+connections will be accepted via <em>INADDR_ANY</em>.</p>1597 1598 <pre><code>app.listen();1599 app.listen(3000);1445-app.listen(3000, 'n.n.n.n');</code></pre>1600+app.listen(3000, 'n.n.n.n');1601+</code></pre>1602 1603 <p>The <em>port</em> argument may also be a string representing the path to a unix domain socket:</p>1604 1449-<pre><code>app.listen('/tmp/express.sock');</code></pre>1605+<pre><code>app.listen('/tmp/express.sock');1606+</code></pre>1607 1608 <p>Then try it out:</p>1609 1610 <pre><code>$ telnet /tmp/express.sock2 unmodified lines1613 HTTP/1.1 200 OK1614 Content-Type: text/plain1615 Content-Length: 111616 1460-Hello World</code></pre>1617+Hello World1618+</code></pre>1619 </div>1620 </div>1621 </body>1464-</html>1622+</html>modified:docs/index.html+47 added-10 removed
194 unmodified lines195 app.get('/', function(req, res){196 res.send('Hello World');197 });198 199-app.listen(3000);</code></pre>199+app.listen(3000);200+</code></pre>201 201-<h2 id="Features">Features</h2>202+<h2>Features</h2>203 203-<ul><li>Robust routing</li><li>Redirection helpers</li><li>Dynamic view helpers</li><li>Application level view options</li><li>Content negotiation</li><li>Application mounting</li><li>Focus on high performance</li><li>View rendering and partials support</li><li>Environment based configuration</li><li>Session based flash notifications</li><li>Built on <a href="http://github.com/senchalabs/connect">Connect</a></li><li><a href="executable.html">Executable</a> for generating applications quickly</li><li>High test coverage</li></ul>204+<ul>205+<li>Robust routing</li>206+<li>Redirection helpers</li>207+<li>Dynamic view helpers</li>208+<li>Application level view options</li>209+<li>Content negotiation</li>210+<li>Application mounting</li>211+<li>Focus on high performance</li>212+<li>View rendering and partials support</li>213+<li>Environment based configuration</li>214+<li>Session based flash notifications</li>215+<li>Built on <a href="http://github.com/senchalabs/connect">Connect</a></li>216+<li><a href="executable.html">Executable</a> for generating applications quickly</li>217+<li>High test coverage</li>218+</ul>219 205-<h2 id="Contributors">Contributors</h2>220 221+<h2>Contributors</h2>222+223 <p>The following are the major contributors of Express (in no specific order).</p>224 209-<ul><li>TJ Holowaychuk (<a href="http://github.com/visionmedia)">visionmedia</a></li><li>Ciaran Jessup (<a href="http://github.com/ciaranj)">ciaranj</a></li><li>Aaron Heckmann (<a href="http://github.com/aheckmann)">aheckmann</a></li><li>Guillermo Rauch (<a href="http://github.com/guille)">guille</a></li></ul>225+<ul>226+<li>TJ Holowaychuk (<a href="http://github.com/visionmedia">visionmedia</a>)</li>227+<li>Ciaran Jessup (<a href="http://github.com/ciaranj">ciaranj</a>)</li>228+<li>Aaron Heckmann (<a href="http://github.com/aheckmann">aheckmann</a>)</li>229+<li>Guillermo Rauch (<a href="http://github.com/guille">guille</a>)</li>230+</ul>231 211-<h2 id="Third-Party-Modules">Third-Party Modules</h2>232 233+<h2>Third-Party Modules</h2>234+235 <p>The following modules compliment or extend Express directly:</p>236 215-<ul><li><a href="http://github.com/visionmedia/express-resource">express-resource</a> provides resourceful routing</li><li><a href="http://github.com/visionmedia/express-messages">express-messages</a> flash message notification rendering</li><li><a href="http://github.com/visionmedia/express-configure">express-configure</a> async configuration support (load settings from redis etc)</li><li><a href="http://github.com/visionmedia/express-namespace">express-namespace</a> namespaced routing support</li></ul>237+<ul>238+<li><a href="http://github.com/visionmedia/express-resource">express-resource</a> provides resourceful routing</li>239+<li><a href="http://github.com/visionmedia/express-messages">express-messages</a> flash message notification rendering</li>240+<li><a href="http://github.com/visionmedia/express-configure">express-configure</a> async configuration support (load settings from redis etc)</li>241+<li><a href="http://github.com/visionmedia/express-namespace">express-namespace</a> namespaced routing support</li>242+</ul>243 217-<h2 id="More-Information">More Information</h2>244 219-<ul><li><a href="http://groups.google.com/group/express-js">Google Group</a> for discussion</li><li>Follow <a href="http://twitter.com/tjholowaychuk">tjholowaychuk</a> on twitter for updates</li><li>View the <a href="http://senchalabs.github.com/connect">Connect</a> documentation</li><li>View the <a href="http://wiki.github.com/senchalabs/connect/">Connect Wiki</a> for contrib middleware</li><li>View the <a href="http://github.com/visionmedia/express/tree/master/examples/">examples</a></li><li>View the <a href="http://github.com/visionmedia/express">source</a></li><li>View the <a href="contrib.html">contrib guide</a></li></ul>245+<h2>More Information</h2>246+247+<ul>248+<li><a href="http://groups.google.com/group/express-js">Google Group</a> for discussion</li>249+<li>Follow <a href="http://twitter.com/tjholowaychuk">tjholowaychuk</a> on twitter for updates</li>250+<li>View the <a href="http://senchalabs.github.com/connect">Connect</a> documentation</li>251+<li>View the <a href="http://wiki.github.com/senchalabs/connect/">Connect Wiki</a> for contrib middleware</li>252+<li>View the <a href="http://github.com/visionmedia/express/tree/master/examples/">examples</a></li>253+<li>View the <a href="http://github.com/visionmedia/express">source</a></li>254+<li>View the <a href="contrib.html">contrib guide</a></li>255+</ul>256+257 </div>258 </div>259 </body>223-</html>260+</html>modified:docs/migrate.html+64 added-42 removed
188 unmodified lines189 <li><a href="guide.html">Guide</a></li>190 <li><a href="screencasts.html">Screencasts</a></li>191 <li><a href="applications.html">Applications</a></li>192 </ul>193-<h3 id="Express-1-x-to-2-x-Migration">Express 1.x to 2.x Migration</h3>193+<h3>Express 1.x to 2.x Migration</h3>194 195-<h3 id="HTTPS">HTTPS</h3>195+<h3>HTTPS</h3>196 197 <p> Creating an HTTPS server is simply, simply pass the TLS options to <em>express.createServer()</em>:</p>198 199 <pre><code> var app = express.createServer({200 key: ...201 , cert: ...202 });203 204- app.listen(443);</code></pre>204+ app.listen(443);205+</code></pre>206 206-<h3 id="req-header-Referrer">req.header() Referrer</h3>207+<h3>req.header() Referrer</h3>208 209 <p> Previously if anyone was doing something similar to:</p>210 211 <pre><code> req.headers.referrer || req.headers.referer211- req.header('Referrer') || req.header('Referer')</code></pre>212+ req.header('Referrer') || req.header('Referer')213+</code></pre>214 215 <p> With the new special-case we may now simply use <em>Referrer</em> which will return either if defined:</p>216 215-<pre><code> req.header('Referrer')</code></pre>217+<pre><code> req.header('Referrer')218+</code></pre>219 217-<h3 id="res-local-name-val">res.local(name, val)</h3>220+<h3>res.local(name, val)</h3>221 222 <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>223 224 <p> For example we may utilize this feature to create locals in middleware:</p>6 unmodified lines231 }232 233 app.get('/user/:id', loadUser, function(req, res){234 res.render('user');235+ });232- });</code></pre>236+</code></pre>237 234-<h3 id="req-param-name-defaultValue">req.param(name[, defaultValue])</h3>238+<h3>req.param(name[, defaultValue])</h3>239 240 <p> Previously only <em>name</em> was accepted, so some of you may have been doing the following:</p>241 238-<pre><code> var id = req.param('id') || req.user.id;</code></pre>242+<pre><code> var id = req.param('id') || req.user.id;243+</code></pre>244 245 <p> The new <em>defaultValue</em> argument can handle this nicely:</p>246 242-<pre><code> var id = req.param('id', req.user.id);</code></pre>247+<pre><code> var id = req.param('id', req.user.id);248+</code></pre>249 244-<h3 id="app-helpers-app-locals">app.helpers() / app.locals()</h3>250+<h3>app.helpers() / app.locals()</h3>251 252 <p> <em>app.locals()</em> is now an alias of <em>app.helpers()</em>, as helpers makes more sense for functions.</p>253 248-<h3 id="req-accepts-type">req.accepts(type)</h3>254+<h3>req.accepts(type)</h3>255 256 <p> <em>req.accepts()</em> now accepts extensions:</p>257 258 <pre><code> // Accept: text/html9 unmodified lines268 // => true269 270 req.accepts('image/png');271 req.accepts('png');266- // => false</code></pre>272+ // => false273+</code></pre>274 268-<h3 id="res-cookie">res.cookie()</h3>275+<h3>res.cookie()</h3>276 277 <p> Previously only directly values could be passed, so for example:</p>278 272-<pre><code>res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000) });</code></pre>279+<pre><code>res.cookie('rememberme', 'yes', { expires: new Date(Date.now() + 900000) });280+</code></pre>281 282 <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>283 276-<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });</code></pre>284+<pre><code>res.cookie('rememberme', 'yes', { maxAge: 900000 });285+</code></pre>286 278-<h3 id="res-download-res-sendfile">res.download() / res.sendfile()</h3>287+<h3>res.download() / res.sendfile()</h3>288 280-<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>289+<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>290 291 <pre><code> res.download('/path/to/file');292 293 res.download('/path/to/file', function(err){1 unmodified line295 console.error(err);296 } else {297 console.log('transferred');298 }299+ });290- });</code></pre>300+</code></pre>301 302 <p> The <em>stream threshold</em> setting was removed.</p>303 294-<h3 id="res-render">res.render()</h3>304+<h3>res.render()</h3>305 306 <p> Previously locals were passed as a separate key:</p>307 298-<pre><code> res.render('user', { layout: false, locals: { user: user }});</code></pre>308+<pre><code> res.render('user', { layout: false, locals: { user: user }});309+</code></pre>310 311 <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>312 302-<pre><code> res.render('user', { layout: false, user: user });</code></pre>313+<pre><code> res.render('user', { layout: false, user: user });314+</code></pre>315 304-<h3 id="res-partial">res.partial()</h3>316+<h3>res.partial()</h3>317 318 <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>319 320 <pre><code> // render a collection of comments321 res.partial('comment', [comment1, comment2]); 322 323 // render a single comment312- res.partial('comment', comment);</code></pre>324+ res.partial('comment', comment);325+</code></pre>326 314-<h3 id="partial-locals">partial() locals</h3>327+<h3>partial() locals</h3>328 329 <p> Both <em>res.partial()</em> and the <em>partial()</em> functions accept an single object consisting of both the options and the locals. Previously with Express 1.x you may pass <em>user</em> to a partial, along with <em>date</em> like so:</p>330 318-<pre><code> partial('user', { object: user, locals: { date: new Date }})</code></pre>331+<pre><code> partial('user', { object: user, locals: { date: new Date }})332+</code></pre>333 334 <p>or perhaps if you preferred not to use the inferred name <em>user</em> you may used a local for this as well:</p>335 322-<pre><code> partial('user', { locals: { user: user, date: new Date }})</code></pre>336+<pre><code> partial('user', { locals: { user: user, date: new Date }})337+</code></pre>338 339 <p> With recent changes to Express 2.x the object passed is now both, so the following is valid for the <em>object</em> option and locals:</p>340 326-<pre><code> partial('user', { object: user, date: new Date })</code></pre>341+<pre><code> partial('user', { object: user, date: new Date })342+</code></pre>343 344 <p> Or the following which is equivalent, however the local var name is explicitly set to <em>user</em> instead of deduced from the filename.</p>345 330-<pre><code> partial('user', { user: user, date: new Date })</code></pre>346+<pre><code> partial('user', { user: user, date: new Date })347+</code></pre>348 332-<p> When a "basic" object aka <em>{}</em> or <em>new Object</em> is passed, it is considered options, otherwise it is considered the <em>object</em>. The following are equivalent:</p>349+<p> When a “basic” object aka <em>{}</em> or <em>new Object</em> is passed, it is considered options, otherwise it is considered the <em>object</em>. The following are equivalent:</p>350 351 <pre><code> partial('user', user); 335- partial('user', { object: user }); </code></pre>352+ partial('user', { object: user }); 353+</code></pre>354 337-<h3 id="Template-Engine-Compliance">Template Engine Compliance</h3>355+<h3>Template Engine Compliance</h3>356 357 <p> To comply with Express previously engines needed the following signature:</p>358 341-<pre><code> engine.render(str, options, function(err){});</code></pre>359+<pre><code> engine.render(str, options, function(err){});360+</code></pre>361 362 <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>363 364 <pre><code> var fn = engine.compile(str, options);346- fn(locals);</code></pre>365+ fn(locals);366+</code></pre>367 348-<h3 id="View-Partial-Lookup">View Partial Lookup</h3>368+<h3>View Partial Lookup</h3>369 370 <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>371 352-<h3 id="Mime-Types">Mime Types</h3>372+<h3>Mime Types</h3>373 374 <p> Express and Connect now utilize the <em>mime</em> module in npm, so to add more use:</p>375 356-<pre><code> require('mime').define({ 'foo/bar': ['foo', 'bar'] });</code></pre>376+<pre><code> require('mime').define({ 'foo/bar': ['foo', 'bar'] });377+</code></pre>378 358-<h3 id="static-middleware">static() middleware</h3>379+<h3>static() middleware</h3>380 381 <p> Previously named <code>staticProvider()</code>, the now <code>static()</code> middleware takes a single directory path, followed by options.</p>382 362-<pre><code> app.use(express.static(__dirname + '/public', { maxAge: oneYear }));</code></pre>383+<pre><code> app.use(express.static(__dirname + '/public', { maxAge: oneYear }));384+</code></pre>385 386 <p>Previously when using options the <code>root</code> option would be used for this:</p>387 388 <pre><code> app.use(express.staticProvider({ root: __dirname + '/public', maxAge: oneYear }));367- </code></pre>389+</code></pre>390 </div>391 </div>392 </body>371-</html>393+</html>modified:docs/screencasts.html+13 added-9 removed
188 unmodified lines189 <li><a href="guide.html">Guide</a></li>190 <li><a href="screencasts.html">Screencasts</a></li>191 <li><a href="applications.html">Applications</a></li>192 </ul>193-<h3 id="Introduction">Introduction</h3>193+<h3>Introduction</h3>194 195 <p>This introduction screencast covers the basics of Express, and how to get started with your first application.</p>196 197-<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr<em>1116090935.swf' /><param name='flashvars' value='i=139583' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr</em>1116090935.swf' flashvars='i=139583' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>197+<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=139583' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=139583' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>198 199-<h3 id="View-Partials">View Partials</h3>199 200+<h3>View Partials</h3>201+202 <p>In this screencast we work with partials to display a collection of users using the <a href="http://jade-lang.com">Jade</a> template engine, and learn about view path resolution.</p>203 203-<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr<em>1116090935.swf' /><param name='flashvars' value='i=139591' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr</em>1116090935.swf' flashvars='i=139591' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>204+<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=139591' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=139591' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>205 205-<h3 id="Route-Specific-Middleware">Route Specific Middleware</h3>206 207+<h3>Route Specific Middleware</h3>208+209 <p>In the screencast below we learn about the benefits of route-specific middleware.</p>210 209-<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr<em>1116090935.swf' /><param name='flashvars' value='i=140296' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr</em>1116090935.swf' flashvars='i=140296' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>211+<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=140296' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=140296' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>212 211-<h3 id="Route-Param-Preconditions">Route Param Preconditions</h3>213 214+<h3>Route Param Preconditions</h3>215+216 <p>Learn about route parameter (<em>/user/:id</em>) pre-conditions, providing automated validation, and loading of data via the named route param segments.</p>217 215-<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr<em>1116090935.swf' /><param name='flashvars' value='i=140300' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr</em>1116090935.swf' flashvars='i=140300' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>218+<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=140300' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=140300' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>219+220 </div>221 </div>222 </body>219-</html>223+</html>modified:support/toc.js+34 added-36 removed
2 unmodified lines345678910111213141516171819202122232425262728293031323378910111213141516171819202122232425262728293031323334373839404142434445353637383940414243442 unmodified linesvar fs = require('fs'), file = process.argv[2];
if (file) { var js = fs.readFileSync(file, 'utf8'), headers = js.match(/<h3 id="(.*?)">(.*?)<\/h3>/g), toc = ['<ul id="toc">'], sections = {}; if (js.indexOf('id="toc"') < 0) { headers.forEach(function(header){ var captures = header.match(/id="(.*?)">(.*?)</), id = captures[1], title = captures[2].replace(/\(.*?\)/, '()') if (~title.indexOf('.')) { var parts = title.split('.'), recv = parts.shift(), method = parts.shift(); if (recv == 'app') recv = 'Server'; if (recv == 'req') recv = 'Request'; if (recv == 'res') recv = 'Response'; sections[recv] = sections[recv] || []; sections[recv].push('<li><a href="#' + id + '">' + method + '</a></li>'); } else { toc.push('<li><a href="#' + id + '">' + title + '</a></li>'); } }); toc.push(renderSections()); toc.push('</ul>'); js = js.replace('<div id="container">', '<div id="container">' + toc.join('\n')); fs.writeFileSync(file, js); } var html = fs.readFileSync(file, 'utf8') , toc = ['<ul id="toc">'] , sections = {};
html = html.replace(/<h3>(.*?)<\/h3>/g, function(_, title){ var id = title.toLowerCase().replace(' ', '-').replace(/\(.*?\)/, '()'); if (~title.indexOf('.')) { var parts = title.split('.') , recv = parts.shift() , method = parts.shift().replace(/\(.*?\)/, '()'); if (recv == 'app') recv = 'Server'; if (recv == 'req') recv = 'Request'; if (recv == 'res') recv = 'Response'; sections[recv] = sections[recv] || []; sections[recv].push('<li><a href="#' + id + '">' + method + '</a></li>'); } else { toc.push('<li><a href="#' + id + '">' + title + '</a></li>'); } return '<h3 id="' + id + '">' + title + '</h3>'; });
toc.push(renderSections()); toc.push('</ul>'); html = html.replace('<div id="container">', '<div id="container">' + toc.join('\n')); fs.writeFileSync(file, html);}
function renderSections() { var buf = []; Object.keys(sections).forEach(function(section){ var methods = sections[section], a = '<a href="#" class="toggle">+</a> <a class="section-title" href="#">' + section + '</a>'; buf.push('<li>' + a + '<ul class="section" id="section-' + section + '">'); buf.push(methods.join('\n')); buf.push('</ul></li>'); }); return buf.join('\n'); var buf = []; Object.keys(sections).forEach(function(section){ var methods = sections[section], a = '<a href="#" class="toggle">+</a> <a class="section-title" href="#">' + section + '</a>'; buf.push('<li>' + a + '<ul class="section" id="section-' + section + '">'); buf.push(methods.join('\n')); buf.push('</ul></li>'); }); return buf.join('\n');}No newline at end of fileNo newline at end of filemodified:History.md+13 added
1 2+n.n.n / 2011-03-18 3+==================4+5+ * connect 1.1.16+ * refactored res.redirect()7+ * doc typo8+ * doc typo9+ * regenerated docs10+ * removed manpages from make11+ * Release 2.0.012+ * Fixed up index view path alternative13+ * Changed; res.locals() without object returns the locals14+15 2.0.0 / 2011-03-17 16 ==================17 18 * Fixed up index view path alternative.537 unmodified linesmodified:Makefile+1 added-2 removed
20 unmodified lines21 @./support/toc.js docs/guide.html22 23 %.html: %.md24 @echo "... $< -> $@"25- @ronn --fragment $< \25+ @markdown $< \26 | cat docs/layout/head.html - docs/layout/foot.html \27- | sed 's/NAME/Express/g' \27 > $@28 29 site:30 rm -fr /tmp/docs \9 unmodified lines