.\" generated with Ronn/v0.6.6 .\" http://github.com/rtomayko/ronn/ . .TH "MIGRATE" "" "July 2010" "" "" . .SH "Migration Guide" Express 1\.x is written to run on\-top of the Connect \fIhttp://extjs\.github\.com/Connect\fR middlware framework, thus the \fBPlugin\fR has been replaced by Connect\'s middleware\. . .SS "Creating Applications" Previously due to legacy code implemented in the early days of node, Express unfortunately had some globals\. The DSL would previously be accessed as shown below: . .IP "" 4 . .nf require(\'express\'); configure(function(){ // app configuration }); get(\'/\', function(){ return \'hello world\'; }); . .fi . .IP "" 0 . .P Now we utilize the CommonJS module system appropriately, and introduce \fBexpress\.createServer()\fR which accepts the same arguments as \fBhttp\.createServer()\fR: . .IP "" 4 . .nf var express = require(\'express\'), app = express\.createServer(); app\.configure(function(){ // app configuration }); app\.get(\'/\', function(req, res){ res\.send(\'hello world\'); }); . .fi . .IP "" 0 . .P Express 1\.x does \fInot\fR allow returning of a string\. . .SS "Running Applications" Previously a global function \fBrun()\fR, was available: . .IP "" 4 . .nf run(); . .fi . .IP "" 0 . .P The new \fBexpress\.Server\fR has the same API as \fBhttp\.Server\fR, so we can do things like: . .IP "" 4 . .nf app\.listen(); app\.listen(3000); . .fi . .IP "" 0 . .SS "Route Parameters" Previously we could use \fBthis\.param()\fR to attempt fetching a route, query string, or request body parameter: . .IP "" 4 . .nf get(\'/user/:id\', function(){ this\.param(\'id\'); }); . .fi . .IP "" 0 . .P Now they (\fIroute params only\fR) are passed as the third argument: . .IP "" 4 . .nf app\.get(\'/user/:id\', function(req, res, params){ params\.id; }); . .fi . .IP "" 0 . .SS "Passing Route Control" Old express had a weak notion of route passing, which did not support async, and was never properly implemented for practical use: . .IP "" 4 . .nf get(\'/\', function(){ this\.pass(\'/foobar\'); }); . .fi . .IP "" 0 . .P Now Express has access to Connect\'s \fBnext()\fR function, which is passed as the fourth and final argument\. Calling \fBnext()\fR will pass control to the next \fImatching route\fR, or continue down the stack of Connect middleware\. . .IP "" 4 . .nf app\.get(\'/user/:id?\', function(req, res, params, next){ next(); }); app\.get(\'/user\', function(){ // \.\.\. respond }); . .fi . .IP "" 0 . .SS "View Rendering" View filenames no longer take the form \fINAME\fR\.\fITYPE\fR\.\fIENGINE\fR, the \fIContent\-Type\fR can be set via \fBServerResponse#contentType()\fR or \fBServerResponse#header()\fR\. For example what was previously \fIlayout\.html\.haml\fR, should now be \fIlayout\.haml\fR\. . .P Previously a view render looked something like this: . .IP "" 4 . .nf get(\'/\', function(){ this\.render(\'index\.html\.haml\', { locals: { title: \'My Site\' } }); }); . .fi . .IP "" 0 . .P We now have \fBServerResponse#render()\fR, however the options passed to haml \fIhttp://github\.com/visionmedia/haml\.js\fR, jade \fIhttp://github\.com/visionmedia/jade\fR, and others remain the same\. . .IP "" 4 . .nf app\.get(\'/\', function(req, res){ res\.render(\'index\.haml\', { locals: { title: \'My Site\' } }); }); . .fi . .IP "" 0 . .P Previously rendering of a collection via \fBpartial()\fR would look something like this: . .IP "" 4 . .nf this\.partial(\'comment\.html\.haml\', { collection: comments }); . .fi . .IP "" 0 . .P Although this worked just fine, it was generally to verbose, the similar but new API looks like this, as \fBpartial()\fR is \fIalways\fR passed as a local variable: . .IP "" 4 . .nf partial(\'comment\.haml\', { collection: comments }); . .fi . .IP "" 0 . .P To make things even less verbose we can assume the extension when ommitted: . .IP "" 4 . .nf partial(\'comment\', { collection: comments }); . .fi . .IP "" 0 . .P And once again even further, when rendering a collection we can simply pass an array, if no other options are desired: . .IP "" 4 . .nf partial(\'comments\', comments); . .fi . .IP "" 0