Skip to content
Myr

Ordering 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 334a18a · Browse files · 1 file+25 added−25 removed
This commit

State

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

Diff stats

1 file+25 added−25 removed

  • other:+25 added−25 removed

1 file+25 added−25 removed

modified:docs/guide.md+25 added-25 removed
168 unmodified lines
169 app.get('/users', function(req, res){170 // do something else171 });172173### Middleware174175Middleware via [Connect](http://github.com/senchalabs/connect) can be176passed to _express.createServer()_ as you would with a regular Connect server. For example:177178 var express = require('express');179180 var app = express.createServer(181 express.logger(),182 express.bodyDecoder()183 );184185Alternatively we can _use()_ them which is useful when adding middleware within _configure()_ blocks:186187 app.use(express.logger({ format: ':method :uri' }));188189Typically with connect middleware you would _require('connect')_ like so:190191 var connect = require('connect');192 app.use(connect.logger());193194This is somewhat annoying, so express re-exports these middleware properties, however they are _identical_:195196 app.use(express.logger());197198### Route Middleware199200Routes 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.201
105 unmodified lines
307 console.log(req.body.user);308 res.redirect('back');309 });310286### Middleware287288Middleware via [Connect](http://github.com/senchalabs/connect) can be289passed to _express.createServer()_ as you would with a regular Connect server. For example:290291 var express = require('express');292293 var app = express.createServer(294 express.logger(),295 express.bodyDecoder()296 );297298Alternatively we can _use()_ them which is useful when adding middleware within _configure()_ blocks:299300 app.use(express.logger({ format: ':method :uri' }));301302Typically with connect middleware you would _require('connect')_ like so:303304 var connect = require('connect');305 app.use(connect.logger());306307This is somewhat annoying, so express re-exports these middleware properties, however they are _identical_:308309 app.use(express.logger());310311### Error Handling312313Express provides the _app.error()_ method which receives exceptions thrown within a route,314or passed to _next(err)_. Below is an example which serves different pages based on our
599 unmodified lines