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 c1a82bf · Browse files · 3 files·+274 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+274 added−1 removed
- other:+274 added−1 removed
Provenance
- Commit
1db2efa- Tree
faa50ac- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
c1a82bf
3 files changed+274 added−1 removed
modified:docs/migrate.1+123 added
75 unmodified lines76 .77 .fi78 .79 .IP "" 080+.81+.SS "req\.param(name[, defaultValue])"82+Previously only \fIname\fR was accepted, so some of you may have been doing the following:83+.84+.IP "" 485+.86+.nf87 88+ var id = req\.param(\'id\') || req\.user\.id;89+.90+.fi91+.92+.IP "" 093+.94+.P95+The new \fIdefaultValue\fR argument can handle this nicely:96+.97+.IP "" 498+.99+.nf100+101+ var id = req\.param(\'id\', req\.user\.id);102+.103+.fi104+.105+.IP "" 0106+.107+.SS "app\.helpers() / app\.locals()"108+\fIapp\.locals()\fR is now an alias of \fIapp\.helpers()\fR, as helpers makes more sense for functions\.109+.110+.SS "req\.accepts(type)"111+\fIreq\.accepts()\fR now accepts extensions:112+.113+.IP "" 4114+.115+.nf116+117+ // Accept: text/html118+ req\.accepts(\'html\');119+ req\.accepts(\'\.html\');120+ // => true121+122+ // Accept: text/*; application/json123+ req\.accepts(\'html\');124+ req\.accepts(\'text/*\');125+ req\.accepts(\'text/plain\');126+ req\.accepts(\'application/json\');127+ // => true128+129+ req\.accepts(\'image/png\');130+ req\.accepts(\'png\');131+ // => false132+.133+.fi134+.135+.IP "" 0136+.137+.SS "res\.download() / res\.sendfile()"138+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 \fIpath\fR and \fIstream\fR were passed, however now only an \fIerror\fR is passed, when no error has occurred the callback will be invoked indicating that the file transfer is complete\. The callback remains optional:139+.140+.IP "" 4141+.142+.nf143+144+ res\.download(\'/path/to/file\');145+146+ res\.download(\'/path/to/file\', function(err){147+ if (err) {148+ console\.error(err);149+ } else {150+ console\.log(\'transferred\');151+ }152+ });153+.154+.fi155+.156+.IP "" 0157+.158+.P159+The \fIstream threshold\fR setting was removed\.160+.161+.SS "View Engine Compliance"162+To comply with Express previously engines needed the following signature:163+.164+.IP "" 4165+.166+.nf167+168+ engine\.render(str, options, function(err){});169+.170+.fi171+.172+.IP "" 0173+.174+.P175+Now they must export a \fIcompile()\fR 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\.176+.177+.IP "" 4178+.179+.nf180+181+ var fn = engine\.compile(str, options);182+ fn(locals);183+.184+.fi185+.186+.IP "" 0187+.188+.SS "View Partial Lookup"189+Previously partials were loaded relative to the now removed \fIview partials\fR directory setting, or by default \fIviews/partials\fR, now they are relative to the view calling them, read more on view lookup \fIguide\.html#View\-lookup\fR\.190+.191+.SS "Mime Types"192+Express and Connect now utilize the \fImime\fR module in npm, so to add more use:193+.194+.IP "" 4195+.196+.nf197+198+ require(\'mime\')\.define({ \'foo/bar\': [\'foo\', \'bar\'] });199+.200+.fi201+.202+.IP "" 0203+modified:docs/migrate.html+78 added
238 unmodified lines239 res.render('user');240 });241 </code></pre>242 243+<h3 id="req-param-name-defaultValue-">req.param(name[, defaultValue])</h3>244+245+<p> Previously only <em>name</em> was accepted, so some of you may have been doing the following:</p>246+247+<pre><code> var id = req.param('id') || req.user.id;248+</code></pre>249+250+<p> The new <em>defaultValue</em> argument can handle this nicely:</p>251+252+<pre><code> var id = req.param('id', req.user.id);253+</code></pre>254+255+<h3 id="app-helpers-app-locals-">app.helpers() / app.locals()</h3>256+257+<p> <em>app.locals()</em> is now an alias of <em>app.helpers()</em>, as helpers makes more sense for functions.</p>258+259+<h3 id="req-accepts-type-">req.accepts(type)</h3>260+261+<p> <em>req.accepts()</em> now accepts extensions:</p>262+263+<pre><code> // Accept: text/html264+ req.accepts('html');265+ req.accepts('.html');266+ // => true267+268+ // Accept: text/*; application/json269+ req.accepts('html');270+ req.accepts('text/*');271+ req.accepts('text/plain');272+ req.accepts('application/json');273+ // => true274+275+ req.accepts('image/png');276+ req.accepts('png');277+ // => false278+</code></pre>279+280+<h3 id="res-download-res-sendfile-">res.download() / res.sendfile()</h3>281+282+<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>283+284+<pre><code> res.download('/path/to/file');285+286+ res.download('/path/to/file', function(err){287+ if (err) {288+ console.error(err);289+ } else {290+ console.log('transferred');291+ }292+ });293+</code></pre>294+295+<p> The <em>stream threshold</em> setting was removed.</p>296+297+<h3 id="View-Engine-Compliance">View Engine Compliance</h3>298+299+<p> To comply with Express previously engines needed the following signature:</p>300+301+<pre><code> engine.render(str, options, function(err){});302+</code></pre>303+304+<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>305+306+<pre><code> var fn = engine.compile(str, options);307+ fn(locals);308+</code></pre>309+310+<h3 id="View-Partial-Lookup">View Partial Lookup</h3>311+312+<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>313+314+<h3 id="Mime-Types">Mime Types</h3>315+316+<p> Express and Connect now utilize the <em>mime</em> module in npm, so to add more use:</p>317+318+<pre><code> require('mime').define({ 'foo/bar': ['foo', 'bar'] });319+</code></pre>320+321 </div>322 </div>323 </div>324 </body>1 unmodified linemodified:docs/migrate.md+73 added-1 removed
36 unmodified lines3738394041414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211336 unmodified lines }
app.get('/user/:id', loadUser, function(req, res){ res.render('user'); });No newline at end of file });
### req.param(name[, defaultValue])
Previously only _name_ was accepted, so some of you may have been doing the following: var id = req.param('id') || req.user.id;
The new _defaultValue_ argument can handle this nicely: var id = req.param('id', req.user.id);
### app.helpers() / app.locals()
_app.locals()_ is now an alias of _app.helpers()_, as helpers makes more sense for functions.
### req.accepts(type)
_req.accepts()_ now accepts extensions: // Accept: text/html req.accepts('html'); req.accepts('.html'); // => true // Accept: text/*; application/json req.accepts('html'); req.accepts('text/*'); req.accepts('text/plain'); req.accepts('application/json'); // => true req.accepts('image/png'); req.accepts('png'); // => false
### res.download() / res.sendfile()
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 _path_ and _stream_ were passed, however now only an _error_ is passed, when no error has occurred the callback will be invoked indicating that the file transfer is complete. The callback remains optional: res.download('/path/to/file');
res.download('/path/to/file', function(err){ if (err) { console.error(err); } else { console.log('transferred'); } });
The _stream threshold_ setting was removed.
### View Engine Compliance
To comply with Express previously engines needed the following signature: engine.render(str, options, function(err){});
Now they must export a _compile()_ 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. var fn = engine.compile(str, options); fn(locals);
### View Partial Lookup
Previously partials were loaded relative to the now removed _view partials_ directory setting, or by default _views/partials_, now they are relative to the view calling them, read more on [view lookup](guide.html#View-Lookup).
### Mime Types
Express and Connect now utilize the _mime_ module in npm, so to add more use: require('mime').define({ 'foo/bar': ['foo', 'bar'] });No newline at end of file