Skip to content
Myr

More docs

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 5fcf971 · Browse files · 10 files+235 added−54 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+235 added−54 removed

  • other:+235 added−54 removed

10 files+235 added−54 removed

modified:docs/layout/head.html+1 added
modified:docs/contrib.html+1 added
122 unmodified lines
123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 padding: 1px 0;128 list-style: none;129 }130 #toc li a {131 font-size: 11px;
89 unmodified lines
modified:docs/executable.html+1 added
122 unmodified lines
123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 padding: 1px 0;128 list-style: none;129 }130 #toc li a {131 font-size: 11px;
71 unmodified lines
modified:docs/guide.1+93 added-13 removed
109 unmodified lines
110.fi111.112.IP "" 0113.114.P115To alter the environment we can set the \fICONNECT_ENV\fR environment variable, or more specifically \fIEXPRESS_ENV\fR, for example:116.117.IP "" 4118.119.nf120121$ EXPRESS_ENV=production node app\.js122.123.fi124.125.IP "" 0126.127.SS "Settings"128Express supports the following settings out of the box:129.130.IP "\(bu" 4131\fIenv\fR Application environment set internally, use \fIapp\.set(\'env\')\fR to utilize132.133.IP "\(bu" 4134\fIhome\fR Application base path used with \fIres\.redirect()\fR135.136.IP "\(bu" 4137\fIviews\fR Root views directory defaulting to \fBCWD/views\fR
127 unmodified lines
265.fi266.267.IP "" 0268.253.SS "Request#header(key[, defaultValue])"269.SS "req\.header(key[, defaultValue])"270Get the case\-insensitive request header \fIkey\fR, with optional \fIdefaultValue\fR:271.272.IP "" 4273.
6 unmodified lines
280.fi281.282.IP "" 0283.268.SS "Request#accepts(type)"284.SS "req\.accepts(type)"285Check if the \fIAccept\fR header is present, and includes the given \fItype\fR\.286.287.P288When the \fIAccept\fR header is not present \fItrue\fR is returned\. Otherwise the given \fItype\fR is matched by an exact match, and then subtypes\. You may pass the subtype such as \"html\" which is then converted internally to \"text/html\" using the mime lookup table\.
20 unmodified lines
309.fi310.311.IP "" 0312.297.SS "Request#param(name)"313.SS "req\.param(name)"314Return the value of param \fIname\fR when present\.315.316.IP "\(bu" 4317Checks route placeholders, ex: /user/:id
8 unmodified lines
326.327.P328To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIconnect\.bodyDecoder\fR middleware\.329.314.SS "Request#flash(type[, msg])"330.SS "req\.flash(type[, msg])"331Queue flash \fImsg\fR of the given \fItype\fR\.332.333.IP "" 4334.
16 unmodified lines
351.fi352.353.IP "" 0354.339.SS "Request#isXMLHttpRequest"355.SS "req\.isXMLHttpRequest"356Also aliased as \fIreq\.xhr\fR, this getter checks the \fIX\-Requested\-With\fR header to see if it was issued by an \fIXMLHttpRequest\fR:357.358.IP "" 4359.
5 unmodified lines
365.fi366.367.IP "" 0368.353.SS "Response#header(key[, val])"369.SS "res\.header(key[, val])"370Get or set the response header \fIkey\fR\.371.372.IP "" 4373.
11 unmodified lines
385.fi386.387.IP "" 0388.373.SS "Response#contentType(type)"389.SS "res\.contentType(type)"390Sets the \fIContent\-Type\fR response header to the given \fItype\fR\.391.392.IP "" 4393.
6 unmodified lines
400.fi401.402.IP "" 0403.388.SS "Response#attachment([filename])"404.SS "res\.attachment([filename])"405Sets the \fIContent\-Disposition\fR response header to \"attachment\", with optional \fIfilename\fR\.406.407.IP "" 4408.
4 unmodified lines
413.fi414.415.IP "" 0416.401.SS "Response#sendfile(path)"417.SS "res\.sendfile(path)"418Used by \fBres\.download()\fR to transfer an arbitrary file\.419.420.IP "" 4421.
7 unmodified lines
429.430.P431\fBNOTE\fR: this is \fInot\fR a replacement for Connect\'s \fIstaticProvider\fR middleware, nor does it perform any security checks, use with caution when using in a dynamic manor\.432.417.SS "Response#download(file[, filename])"433.SS "res\.download(file[, filename])"434Transfer the given \fIfile\fR as an attachment with optional alternative \fIfilename\fR\.435.436.IP "" 4437.
19 unmodified lines
457.fi458.459.IP "" 0460.445.SS "Response#send(body|status[, headers|status[, status]])"461.SS "res\.send(body|status[, headers|status[, status]])"462The \fBres\.send()\fR method is a high level response utility allowing you to pass objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status code based responses\. The following are all valid uses:463.464.IP "" 4465.
12 unmodified lines
478.479.P480By default the \fIContent\-Type\fR response header is set, however if explicitly assigned through \fBres\.send()\fR or previously with \fBres\.header()\fR or \fBres\.contentType()\fR it will not be set again\.481.466.SS "Response#redirect(url[, status])"482.SS "res\.redirect(url[, status])"483Redirect to the given \fIurl\fR with a default response \fIstatus\fR of 302\.484.485.IP "" 4486.
11 unmodified lines
498.499.P500Express supports \"redirect mapping\", which by default provides \fIhome\fR, and \fIback\fR\. The \fIback\fR map checks the \fIReferrer\fR and \fIReferer\fR headers, while \fIhome\fR utilizes the \"home\" setting and defaults to \"/\"\.501.502.SS "app\.set(name[, val])"503Apply an application level setting \fIname\fR to \fIval\fR, or get the value of \fIname\fR when \fIval\fR is not present:504.505.IP "" 4506.507.nf508509app\.set(\'reload views\', 200);510app\.set(\'reload views\');511// => 200512.513.fi514.515.IP "" 0516.517.SS "app\.enable(name)"518Enable the given setting \fIname\fR:519.520.IP "" 4521.522.nf523524app\.enable(\'some arbitrary setting\');525app\.set(\'some arbitrary setting\');526// => true527.528.fi529.530.IP "" 0531.532.SS "app\.disable(name)"533Disable the given setting \fIname\fR:534.535.IP "" 4536.537.nf538539app\.disable(\'some setting\');540app\.set(\'some setting\');541// => false542.543.fi544.545.IP "" 0546.547.SS "app\.configure(env|function[, function])"548Define a callback function for the given \fIenv\fR (or all environments) with callback \fIfunction\fR:549.550.IP "" 4551.552.nf553554app\.configure(function(){555 // executed for each env556});557558app\.configure(\'development\', function(){559 // executed for \'development\' only560});561.562.fi563.564.IP "" 0565.486.SS "Server#redirect(name, val)"566.SS "app\.redirect(name, val)"567For use with \fBres\.redirect()\fR we can map redirects at the application level as shown below:568.569.IP "" 4570.
44 unmodified lines
modified:docs/guide.html+79 added-26 removed
122 unmodified lines
123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 padding: 1px 0;128 list-style: none;129 }130 #toc li a {131 font-size: 11px;
40 unmodified lines
172<li><a href="#Settings">Settings</a></li>173<li><a href="#Routing">Routing</a></li>174<li><a href="#Passing-Route-Control">Passing Route Control</a></li>175<li><a href="#Middleware">Middleware</a></li>175<li><a href="#Request-header-key-defaultValue-">Request#header</a></li>176<li><a href="#Request-accepts-type-">Request#accepts</a></li>177<li><a href="#Request-param-name-">Request#param</a></li>178<li><a href="#Request-flash-type-msg-">Request#flash</a></li>179<li><a href="#Request-isXMLHttpRequest">Request#isXMLHttpRequest</a></li>180<li><a href="#Response-header-key-val-">Response#header</a></li>181<li><a href="#Response-contentType-type-">Response#contentType</a></li>182<li><a href="#Response-attachment-filename-">Response#attachment</a></li>183<li><a href="#Response-sendfile-path-">Response#sendfile</a></li>184<li><a href="#Response-download-file-filename-">Response#download</a></li>185<li><a href="#Response-send-body-status-headers-status-status-">Response#send</a></li>186<li><a href="#Response-redirect-url-status-">Response#redirect</a></li>187<li><a href="#Server-redirect-name-val-">Server#redirect</a></li>176<li><a href="#req-header-key-defaultValue-">req.header()</a></li>177<li><a href="#req-accepts-type-">req.accepts()</a></li>178<li><a href="#req-param-name-">req.param()</a></li>179<li><a href="#req-flash-type-msg-">req.flash()</a></li>180<li><a href="#req-isXMLHttpRequest">req.isXMLHttpRequest</a></li>181<li><a href="#res-header-key-val-">res.header()</a></li>182<li><a href="#res-contentType-type-">res.contentType()</a></li>183<li><a href="#res-attachment-filename-">res.attachment()</a></li>184<li><a href="#res-sendfile-path-">res.sendfile()</a></li>185<li><a href="#res-download-file-filename-">res.download()</a></li>186<li><a href="#res-send-body-status-headers-status-status-">res.send()</a></li>187<li><a href="#res-redirect-url-status-">res.redirect()</a></li>188<li><a href="#app-set-name-val-">app.set()</a></li>189<li><a href="#app-enable-name-">app.enable()</a></li>190<li><a href="#app-disable-name-">app.disable()</a></li>191<li><a href="#app-configure-env-function-function-">app.configure()</a></li>192<li><a href="#app-redirect-name-val-">app.redirect()</a></li>193</ul>194 <a href='http://github.com/visionmedia/express' id='logo'>Express</a> 195 <p id="tagline">196 High performance, high class web development for
76 unmodified lines
273 // same as app.set('some feature', false);274});275</code></pre>276277<p>To alter the environment we can set the <em>CONNECT_ENV</em> environment variable,278or more specifically <em>EXPRESS_ENV</em>, for example:</p>279280<pre><code>$ EXPRESS_ENV=production node app.js281</code></pre>282283<h3 id="Settings">Settings</h3>284285<p>Express supports the following settings out of the box:</p>286287<ul>288<li><em>env</em> Application environment set internally, use <em>app.set('env')</em> to utilize</li>289<li><em>home</em> Application base path used with <em>res.redirect()</em></li>290<li><em>views</em> Root views directory defaulting to <strong>CWD/views</strong></li>291<li><em>view engine</em> Default view engine name for views rendered without extensions</li>292<li><em>reload views</em> Reloads altered views, by default watches for <em>mtime</em> changes with
87 unmodified lines
380 connect.bodyDecoder()381);382</code></pre>383372<h3 id="Request-header-key-defaultValue-">Request#header(key[, defaultValue])</h3>384<h3 id="req-header-key-defaultValue-">req.header(key[, defaultValue])</h3>385386<p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>387388<pre><code>req.header('Host');389req.header('host');390req.header('Accept', '*/*');391</code></pre>392381<h3 id="Request-accepts-type-">Request#accepts(type)</h3>393<h3 id="req-accepts-type-">req.accepts(type)</h3>394395<p>Check if the <em>Accept</em> header is present, and includes the given <em>type</em>.</p>396397<p>When the <em>Accept</em> header is not present <em>true</em> is returned. Otherwise
16 unmodified lines
414req.accepts('png');415// =&gt; false416</code></pre>417406<h3 id="Request-param-name-">Request#param(name)</h3>418<h3 id="req-param-name-">req.param(name)</h3>419420<p>Return the value of param <em>name</em> when present.</p>421422<ul>
6 unmodified lines
429<p>To utilize urlencoded request bodies, <em>req.body</em>430should be an object. This can be done by using431the <em>connect.bodyDecoder</em> middleware.</p>432421<h3 id="Request-flash-type-msg-">Request#flash(type[, msg])</h3>433<h3 id="req-flash-type-msg-">req.flash(type[, msg])</h3>434435<p>Queue flash <em>msg</em> of the given <em>type</em>.</p>436437<pre><code>req.flash('info', 'email sent');
10 unmodified lines
448req.flash();449// =&gt; { error: ['email delivery failed'], info: [] }450</code></pre>451440<h3 id="Request-isXMLHttpRequest">Request#isXMLHttpRequest</h3>452<h3 id="req-isXMLHttpRequest">req.isXMLHttpRequest</h3>453454<p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header455to see if it was issued by an <em>XMLHttpRequest</em>:</p>456457<pre><code>req.xhr458req.isXMLHttpRequest459</code></pre>460449<h3 id="Response-header-key-val-">Response#header(key[, val])</h3>461<h3 id="res-header-key-val-">res.header(key[, val])</h3>462463<p>Get or set the response header <em>key</em>.</p>464465<pre><code>res.header('Content-Length');
5 unmodified lines
471res.header('Content-Length');472// =&gt; 123473</code></pre>474463<h3 id="Response-contentType-type-">Response#contentType(type)</h3>475<h3 id="res-contentType-type-">res.contentType(type)</h3>476477<p>Sets the <em>Content-Type</em> response header to the given <em>type</em>.</p>478479<pre><code> var filename = 'path/to/image.png';480 res.contentType(filename);481 // res.headers['Content-Type'] is now "image/png"482</code></pre>483472<h3 id="Response-attachment-filename-">Response#attachment([filename])</h3>484<h3 id="res-attachment-filename-">res.attachment([filename])</h3>485486<p>Sets the <em>Content-Disposition</em> response header to "attachment", with optional <em>filename</em>.</p>487488<pre><code> res.attachment('path/to/my/image.png');489</code></pre>490479<h3 id="Response-sendfile-path-">Response#sendfile(path)</h3>491<h3 id="res-sendfile-path-">res.sendfile(path)</h3>492493<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>494495<pre><code>res.sendfile('path/to/my.file');
1 unmodified line
497498<p><strong>NOTE</strong>: this is <em>not</em> a replacement for Connect's <em>staticProvider</em> middleware,499nor does it perform any security checks, use with caution when using in a dynamic manor.</p>500489<h3 id="Response-download-file-filename-">Response#download(file[, filename])</h3>501<h3 id="res-download-file-filename-">res.download(file[, filename])</h3>502503<p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>504505<pre><code>res.download('path/to/image.png');
5 unmodified lines
511<pre><code>res.attachment(file);512res.sendfile(file);513</code></pre>514503<h3 id="Response-send-body-status-headers-status-status-">Response#send(body|status[, headers|status[, status]])</h3>515<h3 id="res-send-body-status-headers-status-status-">res.send(body|status[, headers|status[, status]])</h3>516517<p>The <code>res.send()</code> method is a high level response utility allowing you to pass518objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status519code based responses. The following are all valid uses:</p>
9 unmodified lines
529<p>By default the <em>Content-Type</em> response header is set, however if explicitly530assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>531it will not be set again.</p>532521<h3 id="Response-redirect-url-status-">Response#redirect(url[, status])</h3>533<h3 id="res-redirect-url-status-">res.redirect(url[, status])</h3>534535<p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>536537<pre><code>res.redirect('/', 301);
6 unmodified lines
544<p>Express supports "redirect mapping", which by default provides <em>home</em>, and <em>back</em>.545The <em>back</em> map checks the <em>Referrer</em> and <em>Referer</em> headers, while <em>home</em> utilizes546the "home" setting and defaults to "/".</p>547536<h3 id="Server-redirect-name-val-">Server#redirect(name, val)</h3>548<h3 id="app-set-name-val-">app.set(name[, val])</h3>549550<p>Apply an application level setting <em>name</em> to <em>val</em>, or551get the value of <em>name</em> when <em>val</em> is not present:</p>552553<pre><code>app.set('reload views', 200);554app.set('reload views');555// =&gt; 200556</code></pre>557558<h3 id="app-enable-name-">app.enable(name)</h3>559560<p>Enable the given setting <em>name</em>:</p>561562<pre><code>app.enable('some arbitrary setting');563app.set('some arbitrary setting');564// =&gt; true565</code></pre>566567<h3 id="app-disable-name-">app.disable(name)</h3>568569<p>Disable the given setting <em>name</em>:</p>570571<pre><code>app.disable('some setting');572app.set('some setting');573// =&gt; false574</code></pre>575576<h3 id="app-configure-env-function-function-">app.configure(env|function[, function])</h3>577578<p>Define a callback function for the given <em>env</em> (or all environments) with callback <em>function</em>:</p>579580<pre><code>app.configure(function(){581 // executed for each env582});583584app.configure('development', function(){585 // executed for 'development' only586});587</code></pre>588589<h3 id="app-redirect-name-val-">app.redirect(name, val)</h3>590591<p>For use with <code>res.redirect()</code> we can map redirects at the application level as shown below:</p>592593<pre><code>app.redirect('google', 'http://google.com');594</code></pre>
26 unmodified lines
modified:docs/guide.md+56 added-13 removed
62 unmodified lines
63 app.disable('some feature');64 // same as app.set('some feature', false);65 });6667To alter the environment we can set the _CONNECT_ENV_ environment variable,68or more specifically _EXPRESS_ENV_, for example:6970 $ EXPRESS_ENV=production node app.js7172### Settings7374Express supports the following settings out of the box:7576 * _env_ Application environment set internally, use _app.set('env')_ to utilize77 * _home_ Application base path used with _res.redirect()_78 * _views_ Root views directory defaulting to **CWD/views**79 * _view engine_ Default view engine name for views rendered without extensions80 * _reload views_ Reloads altered views, by default watches for _mtime_ changes with
79 unmodified lines
160 connect.logger(),161 connect.bodyDecoder()162 );163158### Request#header(key[, defaultValue])164### req.header(key[, defaultValue])165166Get the case-insensitive request header _key_, with optional _defaultValue_:167168 req.header('Host');169 req.header('host');170 req.header('Accept', '*/*');171166### Request#accepts(type)172### req.accepts(type)173174Check if the _Accept_ header is present, and includes the given _type_.175176When the _Accept_ header is not present _true_ is returned. Otherwise
15 unmodified lines
192 req.accepts('image/png');193 req.accepts('png');194 // => false195190### Request#param(name)196### req.param(name)197198Return the value of param _name_ when present.199200 - Checks route placeholders, ex: /user/:id
3 unmodified lines
204To utilize urlencoded request bodies, _req.body_205should be an object. This can be done by using206the _connect.bodyDecoder_ middleware.207202### Request#flash(type[, msg])208### req.flash(type[, msg])209210Queue flash _msg_ of the given _type_.211212 req.flash('info', 'email sent');
9 unmodified lines
222223 req.flash();224 // => { error: ['email delivery failed'], info: [] }225220### Request#isXMLHttpRequest226### req.isXMLHttpRequest227228Also aliased as _req.xhr_, this getter checks the _X-Requested-With_ header229to see if it was issued by an _XMLHttpRequest_:230231 req.xhr232 req.isXMLHttpRequest233228### Response#header(key[, val])234### res.header(key[, val])235236Get or set the response header _key_.237238 res.header('Content-Length');
4 unmodified lines
243244 res.header('Content-Length');245 // => 123246241### Response#contentType(type)247### res.contentType(type)248249Sets the _Content-Type_ response header to the given _type_.250251 var filename = 'path/to/image.png';252 res.contentType(filename);253 // res.headers['Content-Type'] is now "image/png"254249### Response#attachment([filename])255### res.attachment([filename])256257Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.258259 res.attachment('path/to/my/image.png');260255### Response#sendfile(path)261### res.sendfile(path)262263Used by `res.download()` to transfer an arbitrary file. 264265 res.sendfile('path/to/my.file');266267**NOTE**: this is _not_ a replacement for Connect's _staticProvider_ middleware,268nor does it perform any security checks, use with caution when using in a dynamic manor.269264### Response#download(file[, filename])270### res.download(file[, filename])271272Transfer the given _file_ as an attachment with optional alternative _filename_.273274 res.download('path/to/image.png');
3 unmodified lines
278279 res.attachment(file);280 res.sendfile(file);281276### Response#send(body|status[, headers|status[, status]])282### res.send(body|status[, headers|status[, status]])283284The `res.send()` method is a high level response utility allowing you to pass285objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status286code based responses. The following are all valid uses:
8 unmodified lines
295By default the _Content-Type_ response header is set, however if explicitly296assigned through `res.send()` or previously with `res.header()` or `res.contentType()`297it will not be set again.298293### Response#redirect(url[, status])299### res.redirect(url[, status])300301Redirect to the given _url_ with a default response _status_ of 302.302303 res.redirect('/', 301);
5 unmodified lines
309Express supports "redirect mapping", which by default provides _home_, and _back_.310The _back_ map checks the _Referrer_ and _Referer_ headers, while _home_ utilizes311the "home" setting and defaults to "/".312307### Server#redirect(name, val)313### app.set(name[, val])314315Apply an application level setting _name_ to _val_, or316get the value of _name_ when _val_ is not present:317318 app.set('reload views', 200);319 app.set('reload views');320 // => 200321322### app.enable(name)323324Enable the given setting _name_:325326 app.enable('some arbitrary setting');327 app.set('some arbitrary setting');328 // => true329330### app.disable(name)331332Disable the given setting _name_:333334 app.disable('some setting');335 app.set('some setting');336 // => false337338### app.configure(env|function[, function])339340Define a callback function for the given _env_ (or all environments) with callback _function_:341342 app.configure(function(){343 // executed for each env344 });345346 app.configure('development', function(){347 // executed for 'development' only348 });349350### app.redirect(name, val)351352For use with `res.redirect()` we can map redirects at the application level as shown below:353354 app.redirect('google', 'http://google.com');355
17 unmodified lines
modified:docs/index.html+1 added
122 unmodified lines
123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 padding: 1px 0;128 list-style: none;129 }130 #toc li a {131 font-size: 11px;
97 unmodified lines
modified:docs/migrate.html+1 added
122 unmodified lines
123 background: rgba(0,0,0,0.2);124 border-right: 1px solid rgba(255,255,255,0.05);125 }126 #toc li {127 padding: 1px 0;128 list-style: none;129 }130 #toc li a {131 font-size: 11px;
267 unmodified lines
modified:examples/helloworld/app.js+1 added-1 removed
9 unmodified lines
10app.get('/', function(req, res){11 res.send('Hello World');12});1314app.listen(3000);14app.listen(3000);
modified:support/toc.js+1 added-1 removed
9 unmodified lines
10 if (js.indexOf('id="toc"') < 0) {11 headers.forEach(function(header){12 var captures = header.match(/id="(.*?)">(.*?)</),13 id = captures[1],14 title = captures[2].replace(/\(.*?\)/, '');14 title = captures[2].replace(/\(.*?\)/, '()');15 toc.push('<li><a href="#' + id + '">' + title + '</a></li>');16 });17 toc.push('</ul>');18 js = js.replace('<div id="container">', '<div id="container">' + toc.join('\n'));
3 unmodified lines