Skip to content
Myr

guide.md

This file

Path

docs/guide.md

627 lines · 18.2 KiB · Markdown

Last changed by

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

History of this file

Take it

Started guideTj Holowaychukbefore adoption9e3a0c6

line 1why, one step back
1

Install docsTj Holowaychukbefore adoption63d02f1

lines 2–3why, one step back
2### Installation
3

Updated curl install docsTj Holowaychukbefore adoption3ceb0de

lines 4–7why, one step back
4curl (or similar):
56 $ curl -# http://expressjs.com/install.sh | sh7

Install docsTj Holowaychukbefore adoption63d02f1

lines 8–9why, one step back
8npm:
9

Updated install docsTj Holowaychukbefore adoption193c4a9

line 10why, one step back
10 $ npm install connect

Install docsTj Holowaychukbefore adoption63d02f1

lines 11–12why, one step back
11 $ npm install express
12

Updated install docsTj Holowaychukbefore adoption193c4a9

line 13why, one step back
13git clone, first update the submodules:

Install docsTj Holowaychukbefore adoption63d02f1

line 14why, one step back
14

Updated install docsTj Holowaychukbefore adoption193c4a9

line 15why, one step back
15 $ git submodule update --init

Install docsTj Holowaychukbefore adoption63d02f1

line 16why, one step back
16 $ make install

Updated install docsTj Holowaychukbefore adoption193c4a9

line 17why, one step back
17 $ make install-support

Install docsTj Holowaychukbefore adoption63d02f1

line 18why, one step back
18

Removed annoying padding transitionTj Holowaychukbefore adoption346b2a2

line 19why, one step back
19### Creating An Application

Added configuration sectionTj Holowaychukbefore adoption83d2555

lines 20–21why, one step back
20
21The _express.Server_ now inherits from _http.Server_, however

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 22–23why, one step back
22follows the same idiom by providing _express.createServer()_ as shown below. This means
23that you can utilize Express server's transparently with other libraries.

Added configuration sectionTj Holowaychukbefore adoption83d2555

lines 24–32why, one step back
24
25 var app = require('express').createServer();26 27 app.get('/', function(req, res){28 res.send('hello world');29 });30 31 app.listen(3000);32

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 33–43why, one step back
33### Configuration
3435Express supports arbitrary environments, such as _production_ and _development_. Developers36can use the _configure()_ method to setup needs required by the current environment. When37_configure()_ is called without an environment name it will be run in _every_ environment 38prior to the environment specific callback.3940In the example below we only _dumpExceptions_, and respond with exception stack traces41in _development_ mode, however for both environments we utilize _methodOverride_ and _bodyDecoder_.4243 app.configure(function(){

Updated docsTj Holowaychukbefore adoptioncacada8

lines 44–45why, one step back
44 app.use(connect.methodOverride());
45 app.use(connect.bodyDecoder());

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 46–48why, one step back
46 });
47 48 app.configure('development', function(){

Updated docsTj Holowaychukbefore adoptioncacada8

line 49why, one step back
49 app.use(connect.errorHandler({ dumpExceptions: true, showStack: true }));

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 50–52why, one step back
50 });
51 52 app.configure('production', function(){

Updated docsTj Holowaychukbefore adoptioncacada8

line 53why, one step back
53 app.use(connect.errorHandler());

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 54–69why, one step back
54 });
5556For internal and arbitrary settings Express provides the _set(key[, val])_, _enable(key)_, _disable(key)_ methods:5758 app.configure(function(){59 app.set('views', __dirname + '/views');60 app.set('views');61 // => "... views directory ..."62 63 app.enable('some feature');64 // same as app.set('some feature', true);65 66 app.disable('some feature');67 // same as app.set('some feature', false);68 });69

More docsTj Holowaychukbefore adoptionde81ee7

lines 70–74why, one step back
70To alter the environment we can set the _CONNECT_ENV_ environment variable,
71or more specifically _EXPRESS_ENV_, for example:7273 $ EXPRESS_ENV=production node app.js74

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 75–78why, one step back
75### Settings
7677Express supports the following settings out of the box:78

More docsTj Holowaychukbefore adoptionde81ee7

line 79why, one step back
79 * _env_ Application environment set internally, use _app.set('env')_ to utilize

Install docsTj Holowaychukbefore adoption63d02f1

line 80why, one step back
80 * _home_ Application base path used with _res.redirect()_

Moved config docs upTj Holowaychukbefore adoption6e8413f

lines 81–82why, one step back
81 * _views_ Root views directory defaulting to **CWD/views**
82 * _view engine_ Default view engine name for views rendered without extensions

Added more setting docsTj Holowaychukbefore adoption38281e6

line 83why, one step back
83 * _reload views_ Reloads altered views, by default watches for _mtime_ changes with

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

line 84why, one step back
84 with a 5 minute interval. Example: _app.set('reload views', 60000);_

Moved config docs upTj Holowaychukbefore adoption6e8413f

line 85why, one step back
85

Started guideTj Holowaychukbefore adoption9e3a0c6

lines 86–89why, one step back
86### Routing
8788Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.89For example we may want to render a user's account for the path _/user/12_, this

Route passing docsTj Holowaychukbefore adoption0ace97c

lines 90–91why, one step back
90can be done by defining the route below. The values associated to the named placeholders,
91are passed as the _third_ argument, which here we name _params_.

Started guideTj Holowaychukbefore adoption9e3a0c6

lines 92–135why, one step back
92
93 app.get('/user/:id', function(req, res, params){94 res.send('user ' + params.id);95 });9697A route is simple a string which is compiled to a _RegExp_ internally. For example98when _/user/:id_ is compiled, a simplified version of the regexp may look similar to:99100 \/user\/([^\/]+)\/?101102Literal regular expressions may also be passed for complex uses:103104 app.get(/^\/foo(bar)?$/, function(){});105106Below are some route examples, and the associated paths that they107may consume:108109 "/user/:id"110 /user/12111112 "/users/:id?"113 /users/5114 /users115116 "/files/*"117 /files/jquery.js118 /files/javascripts/jquery.js119120 "/file/*.*"121 /files/jquery.js122 /files/javascripts/jquery.js123 124 "/user/:id/:operation?"125 /user/1126 /user/1/edit127 128 "/products.:format"129 /products.json130 /products.xml131132 "/products.:format?"133 /products.json134 /products.xml135 /products

Route passing docsTj Holowaychukbefore adoption0ace97c

lines 136–151why, one step back
136
137### Passing Route Control138139We may pass control to the next _matching_ route, by calling the _fourth_ parameter,140the _next()_ function. When a match cannot be made, control is passed back to Connect.141142 app.get('/users/:id?', function(req, res, params){143 if (params.id) {144 // do something145 } else {146 next();147 }148 });149 150 app.get('/users', function(req, res, params){151 // do something else

Added configuration sectionTj Holowaychukbefore adoption83d2555

lines 152–166why, one step back
152 });
153154### Middleware155156The Express _Plugin_ is no more! middleware via [Connect](http://github.com/extjs/Connect) can be157passed to _express.createServer()_ as you would with a regular Connect server. For example:158159 var connect = require('connect'),160 express = require('express');161162 var app = express.createServer(163 connect.logger(),164 connect.bodyDecoder()165 );166

Error handling docsTj Holowaychukbefore adoption9fbb9fa

lines 167–168why, one step back
167Alternatively we can _use()_ them which is useful when adding middleware within _configure()_ blocks:
168

Updated docsTj Holowaychukbefore adoptioncacada8

line 169why, one step back
169 app.use(connect.logger({ format: ':method :uri' }));

Error handling docsTj Holowaychukbefore adoption9fbb9fa

lines 170–215why, one step back
170
171### Error Handling172173Express provides the _app.error()_ method which receives exceptions thrown within a route,174or passed to _next(err)_. Below is an example which serves different pages based on our175ad-hoc _NotFound_ exception:176177 function NotFound(msg){178 this.name = 'NotFound';179 Error.call(this, msg);180 Error.captureStackTrace(this, arguments.callee);181 }182183 sys.inherits(NotFound, Error);184185 app.get('/404', function(req, res){186 throw new NotFound;187 });188189 app.get('/500', function(req, res){190 throw new Error('keyboard cat!');191 });192193We can call _app.error()_ several times as shown below.194Here we check for an instanceof _NotFound_ and show the195404 page, or we pass on to the next error handler.196197 app.error(function(err, req, res, next){198 if (err instanceof NotFound) {199 res.render('404.jade');200 } else {201 next(err);202 }203 });204205Here we assume all errors as 500 for the simplicity of206this demo, however you can choose whatever you like207208 app.error(function(err, req, res){209 res.render('500.jade', {210 locals: {211 error: err212 } 213 });214 });215

More error handling docsTj Holowaychukbefore adoptioncea401c

lines 216–219why, one step back
216Our apps could also utilize the Connect _errorHandler_ middleware
217to report on exceptions. For example if we wish to output exceptions 218in "development" mode to _stderr_ we can use:219

Updated docsTj Holowaychukbefore adoptioncacada8

line 220why, one step back
220 app.use(connect.errorHandler({ dumpExceptions: true }));

More error handling docsTj Holowaychukbefore adoptioncea401c

lines 221–224why, one step back
221
222Also during development we may want fancy html pages to show exceptions223that are passed or thrown, so we can set _showStack_ to true:224

Updated docsTj Holowaychukbefore adoptioncacada8

line 225why, one step back
225 app.use(connect.errorHandler({ showStack: true, dumpExceptions: true }));

More error handling docsTj Holowaychukbefore adoptioncea401c

lines 226–229why, one step back
226
227The _errorHandler_ middleware also responds with _json_ if _Accept: application/json_228is present, which is useful for developing apps that rely heavily on client-side JavaScript.229

Added more view docsTj Holowaychukbefore adoption2f96506

lines 230–247why, one step back
230### View Rendering
231232View filenames take the form _NAME_._ENGINE_, where _ENGINE_ is the name233of the module that will be required. For example the view _layout.ejs_ will234tell the view system to _require('ejs')_, the module being loaded must (currently)235export the method _exports.render(str, options)_ to comply with Express, however 236with will likely be extensible in the future.237238Below is an example using [Haml.js](http://github.com/visionmedia/haml.js) to render _index.html_,239and since we do not use _layout: false_ the rendered contents of _index.html_ will be passed as 240the _body_ local variable in _layout.haml_.241242 app.get('/', function(req, res){243 res.render('index.haml', {244 locals: { title: 'My Site' }245 });246 });247

Docs for "view engine" settingTj Holowaychukbefore adoption1810c9b

lines 248–265why, one step back
248The new _view engine_ setting allows us to specify our default template engine,
249so for example when using [Jade](http://github.com/visionmedia/jade) we could set:250251 app.set('view engine', 'jade');252253Allowing us to render with:254255 res.render('index');256257vs:258259 res.render('index.jade');260261When _view engine_ is set, extensions are entirely optional, however we can still262mix and match template engines:263264 res.render('another-page.ejs');265

Added more view docsTj Holowaychukbefore adoption2f96506

lines 266–283why, one step back
266### View Partials
267268The Express view system has built-in support for partials and collections, which are269sort of "mini" views representing a document fragment. For example rather than iterating270in a view to display comments, we would use a partial with collection support:271272 partial('comment.haml', { collection: comments });273274To make things even less verbose we can assume the extension as _.haml_ when omitted,275however if we wished we could use an ejs partial, within a haml view for example.276277 partial('comment', { collection: comments });278279And once again even further, when rendering a collection we can simply pass280an array, if no other options are desired:281282 partial('comments', comments);283

Added partial magic var docs. Closes #342Tj Holowaychukbefore adoptionbe85701

lines 284–290why, one step back
284When using the partial collection support a few "magic" variables are provided
285for free:286287 * _firstInCollection_ True if this is the first object288 * _indexInCollection_ Index of the object in the collection289 * _lastInCollection _ True if this is the last object290

Added more view docsTj Holowaychukbefore adoption2f96506

lines 291–298why, one step back
291### Template Engines
292293Below are a few template engines commonly used with Express:294295 * [Jade](http://github.com/visionmedia/jade) haml.js successor296 * [Haml](http://github.com/visionmedia/haml.js) indented templates297 * [EJS](http://github.com/visionmedia/ejs) Embedded JavaScript298

More docsTj Holowaychukbefore adoptionde81ee7

line 299why, one step back
299### req.header(key[, defaultValue])

More docsTj Holowaychukbefore adoptiondfecbe5

lines 300–306why, one step back
300
301Get the case-insensitive request header _key_, with optional _defaultValue_:302303 req.header('Host');304 req.header('host');305 req.header('Accept', '*/*');306

More docsTj Holowaychukbefore adoptionde81ee7

line 307why, one step back
307### req.accepts(type)

More docsTj Holowaychukbefore adoptiondfecbe5

lines 308–330why, one step back
308
309Check if the _Accept_ header is present, and includes the given _type_.310311When the _Accept_ header is not present _true_ is returned. Otherwise312the given _type_ is matched by an exact match, and then subtypes. You313may pass the subtype such as "html" which is then converted internally314to "text/html" using the mime lookup table.315316 // Accept: text/html317 req.accepts('html');318 // => true319320 // Accept: text/*; application/json321 req.accepts('html');322 req.accepts('text/html');323 req.accepts('text/plain');324 req.accepts('application/json');325 // => true326327 req.accepts('image/png');328 req.accepts('png');329 // => false330

More docsTj Holowaychukbefore adoptionde81ee7

line 331why, one step back
331### req.param(name)

More docsTj Holowaychukbefore adoptiondfecbe5

lines 332–342why, one step back
332
333Return the value of param _name_ when present.334335 - Checks route placeholders, ex: /user/:id336 - Checks query string params, ex: ?id=12337 - Checks urlencoded body params, ex: id=12338339To utilize urlencoded request bodies, _req.body_340should be an object. This can be done by using341the _connect.bodyDecoder_ middleware.342

More docsTj Holowaychukbefore adoptionde81ee7

line 343why, one step back
343### req.flash(type[, msg])

More docsTj Holowaychukbefore adoptiondfecbe5

lines 344–360why, one step back
344
345Queue flash _msg_ of the given _type_.346347 req.flash('info', 'email sent');348 req.flash('error', 'email delivery failed');349 req.flash('info', 'email re-sent');350 // => 2351352 req.flash('info');353 // => ['email sent', 'email re-sent']354355 req.flash('info');356 // => []357358 req.flash();359 // => { error: ['email delivery failed'], info: [] }360

More docsTj Holowaychukbefore adoptionde81ee7

line 361why, one step back
361### req.isXMLHttpRequest

More docsTj Holowaychukbefore adoptiondfecbe5

lines 362–368why, one step back
362
363Also aliased as _req.xhr_, this getter checks the _X-Requested-With_ header364to see if it was issued by an _XMLHttpRequest_:365366 req.xhr367 req.isXMLHttpRequest368

More docsTj Holowaychukbefore adoptionde81ee7

line 369why, one step back
369### res.header(key[, val])

More docs :)Tj Holowaychukbefore adoption0c5fe61

lines 370–381why, one step back
370
371Get or set the response header _key_.372373 res.header('Content-Length');374 // => undefined375376 res.header('Content-Length', 123);377 // => 123378379 res.header('Content-Length');380 // => 123381

More docsTj Holowaychukbefore adoptionde81ee7

line 382why, one step back
382### res.contentType(type)

More docs :)Tj Holowaychukbefore adoption0c5fe61

lines 383–389why, one step back
383
384Sets the _Content-Type_ response header to the given _type_.385386 var filename = 'path/to/image.png';387 res.contentType(filename);388 // res.headers['Content-Type'] is now "image/png"389

More docsTj Holowaychukbefore adoptionde81ee7

line 390why, one step back
390### res.attachment([filename])

Docs for res.attachment()Tj Holowaychukbefore adoptioneb235e1

lines 391–395why, one step back
391
392Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.393394 res.attachment('path/to/my/image.png');395

More docsTj Holowaychukbefore adoptionde81ee7

line 396why, one step back
396### res.sendfile(path)

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 397–401why, one step back
397
398Used by `res.download()` to transfer an arbitrary file. 399400 res.sendfile('path/to/my.file');401

Better docs for res.sendfile()Tj Holowaychukbefore adoption8a337f1

lines 402–405why, one step back
402This is _not_ a substitution for Connect's _staticProvider_ middleware, it does not
403support HTTP caching, and does not perform any security checks. This method is utilized404by _res.download()_ to transfer static files, and allows you do to so from outside of405the public directory, so suitable security checks should be applied.

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

line 406why, one step back
406

More docsTj Holowaychukbefore adoptionde81ee7

line 407why, one step back
407### res.download(file[, filename])

Docs for new res methodsTj Holowaychukbefore adoptionb08dab9

lines 408–418why, one step back
408
409Transfer the given _file_ as an attachment with optional alternative _filename_.410411 res.download('path/to/image.png');412 res.download('path/to/image.png', 'foo.png');413414This is equivalent to:415416 res.attachment(file);417 res.sendfile(file);418

More docsTj Holowaychukbefore adoptionde81ee7

line 419why, one step back
419### res.send(body|status[, headers|status[, status]])

Docs for res.send()Tj Holowaychukbefore adoption5a48248

lines 420–435why, one step back
420
421The `res.send()` method is a high level response utility allowing you to pass422objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status423code based responses. The following are all valid uses:424425 res.send(new Buffer('wahoo'));426 res.send({ some: 'json' });427 res.send('<p>some html</p>');428 res.send('Sorry, cant find that', 404);429 res.send('text', { 'Content-Type': 'text/plain' }, 201);430 res.send(404);431432By default the _Content-Type_ response header is set, however if explicitly433assigned through `res.send()` or previously with `res.header()` or `res.contentType()`434it will not be set again.435

More docsTj Holowaychukbefore adoptionde81ee7

line 436why, one step back
436### res.redirect(url[, status])

Added configuration sectionTj Holowaychukbefore adoption83d2555

line 437why, one step back
437

More docsTj Holowaychukbefore adoptionbedff32

line 438why, one step back
438Redirect to the given _url_ with a default response _status_ of 302.

Configuration docsTj Holowaychukbefore adoptioncb04364

line 439why, one step back
439

More docsTj Holowaychukbefore adoptionbedff32

lines 440–449why, one step back
440 res.redirect('/', 301);
441 res.redirect('/account');442 res.redirect('http://google.com');443 res.redirect('home');444 res.redirect('back');445446Express supports "redirect mapping", which by default provides _home_, and _back_.447The _back_ map checks the _Referrer_ and _Referer_ headers, while _home_ utilizes448the "home" setting and defaults to "/".449

More view docsTj Holowaychukbefore adoption1c8ff48

lines 450–460why, one step back
450### res.render(view[, options[, fn]])
451452Render _view_ with the given _options_ and optional callback _fn_.453When a callback function is given a response will _not_ be made454automatically, however otherwise a response of _200_ and _text/html_ is given.455456 Most engines accept one or more of the following options,457 both [haml](http://github.com/visionmedia/haml.js) and [jade](http://github.com/visionmedia/jade) accept all:458459 - _context|scope_ Template evaluation context (_this_)460 - _locals_ Object containing local variables

Cleaning up view docsTj Holowaychukbefore adoption25c8883

line 461why, one step back
461 - _cache_ Cache intermediate JavaScript in memory (the default in _production_ mode)

More view docsTj Holowaychukbefore adoption1c8ff48

lines 462–463why, one step back
462 - _debug_ Output debugging information
463

In depth partial docsTj Holowaychukbefore adoption793943f

lines 464–501why, one step back
464### res.partial(view[, options])
465466Render _view_ partial with the given _options_. This method is always available467to the view as a local variable.468469- _as_ Variable name for each _collection_ value, defaults to the view name.470 * as: 'something' will add the _something_ local variable471 * as: this will use the collection value as the template context472 * as: global will merge the collection value's properties with _locals_473474- _collection_ Array of objects, the name is derived from the view name itself. 475 For example _video.html_ will have a object _video_ available to it.476477The following are equivalent, and the name of collection value when passed478to the partial will be _movie_ as derived from the name.479480 partial('movie.jade', { collection: movies });481 partial('movie.jade', movies);482 partial('movie', movies);483 // In view: movie.director484485To change the local from _movie_ to _video_ we can use the "as" option:486487 partial('movie', { collection: movies, as: 'video' });488 // In view: video.director489490Also we can make our movie the value of _this_ within our view so that instead491of _movie.director_ we could use _this.director_.492493 partial('movie', { collection: movies, as: this });494 // In view: this.director495496Another alternative is to "explode" the properties of the collection item into497pseudo globals (local variables) by using _as: global_, which again is syntactic sugar:498499 partials('movie', { collection: movies, as: global });500 // In view: director501

More docsTj Holowaychukbefore adoptionde81ee7

lines 502–539why, one step back
502### app.set(name[, val])
503504Apply an application level setting _name_ to _val_, or505get the value of _name_ when _val_ is not present:506507 app.set('reload views', 200);508 app.set('reload views');509 // => 200510511### app.enable(name)512513Enable the given setting _name_:514515 app.enable('some arbitrary setting');516 app.set('some arbitrary setting');517 // => true518519### app.disable(name)520521Disable the given setting _name_:522523 app.disable('some setting');524 app.set('some setting');525 // => false526527### app.configure(env|function[, function])528529Define a callback function for the given _env_ (or all environments) with callback _function_:530531 app.configure(function(){532 // executed for each env533 });534535 app.configure('development', function(){536 // executed for 'development' only537 });538539### app.redirect(name, val)

More docsTj Holowaychukbefore adoptionbedff32

lines 540–561why, one step back
540
541For use with `res.redirect()` we can map redirects at the application level as shown below:542543 app.redirect('google', 'http://google.com');544545Now in a route we may call:546547 res.redirect('google');548549We may also map dynamic redirects:550551 app.redirect('comments', function(req, res, params){552 return '/post/' + params.id + '/comments';553 });554555So now we may do the following, and the redirect will dynamically adjust to556the context of the request. If we called this route with _GET /post/12_ our557redirect _Location_ would be _/post/12/comments_.558559 app.get('/post/:id', function(req, res){560 res.redirect('comments');561 });

Error handling docsTj Holowaychukbefore adoption9fbb9fa

lines 562–564why, one step back
562
563### app.error(function)564

More error docsTj Holowaychukbefore adoption6227f5c

lines 565–567why, one step back
565Adds an error handler _function_ which will receive the exception as the first parameter as shown below.
566Note that we may set several error handlers by making several calls to this method, however the handler567should call _next(err)_ if it does not wish to deal with the exception:

Error handling docsTj Holowaychukbefore adoption9fbb9fa

lines 568–571why, one step back
568
569 app.error(function(err, req, res, next){570 res.send(err.message, 500);571 });

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 572–574why, one step back
572
573### app.helpers(obj)574

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

lines 575–590why, one step back
575Registers static view helpers.
576577 app.helpers({578 name: function(first, last){ return first + ', ' + last },579 firstName: 'tj',580 lastName: 'holowaychuk'581 });582583Our view could now utilize the _firstName_ and _lastName_ variables,584as well as the _name()_ function exposed.585586 <%= name(firstName, lastName) %>587588### app.dynamicHelpers(obj)589590Registers dynamic view helpers. Dynamic view helpers

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

line 591why, one step back
591are simply functions which accept _req_, _res_, and _params_, and are

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

line 592why, one step back
592evaluated against the _Server_ instance before a view is rendered. The _return value_ of this function

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 593–594why, one step back
593becomes the local variable it is associated with.
594

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

line 595why, one step back
595 app.dynamicHelpers({

Added app.helpers() docsTj Holowaychukbefore adoption7eb088b

lines 596–600why, one step back
596 session: function(req, res, params){
597 return req.session;598 }599 });600

Docs for Server#{helpers,dynamicHelpers}()Tj Holowaychukbefore adoption78008d1

lines 601–603why, one step back
601All views would now have _session_ available so that session data can be accessed via _session.name_ etc:
602603 <%= session.name %>

Server#listen() docsTj Holowaychukbefore adoptionf3803c4

lines 604–612why, one step back
604
605### app.listen([port[, host]])606607Bind the app server to the given _port_, which defaults to 3000. When _host_ is omitted all608connections will be accepted via _INADDR_ANY_.609610 app.listen();611 app.listen(3000);612 app.listen(3000, 'n.n.n.n');

Unix domain socket docsTj Holowaychukbefore adoption2fa7907

lines 613–627why, one step back
613
614The _port_ argument may also be a string representing the path to a unix domain socket:615616 app.listen('/tmp/express.sock');617618Then try it out:619620 $ telnet /tmp/express.sock621 GET / HTTP/1.1622623 HTTP/1.1 200 OK624 Content-Type: text/plain625 Content-Length: 11626 627 Hello World