Skip to content
Myr

app.js

This file

Path

examples/error/app.js

49 lines · 1.1 KiB · JavaScript

Last changed by

Merge branch 'integration'TJ Holowaychukbefore adoption0ae024a

History of this file

Take it

The walk stopped after 200 commits: lines older than 26c62a6 point at it.

Added app.locals.use() testTj Holowaychukbefore adoption26c62a6

lines 1–5why, one step back
1
2/**3 * Module dependencies.4 */5

mergedTj Holowaychukbefore adoption547d18c

line 6why, one step back
6var express = require('../../')

Merge branch 'integration'TJ Holowaychukbefore adoption0ae024a

line 7why, one step back
7 , app = module.exports = express();

Added app.locals.use() testTj Holowaychukbefore adoption26c62a6

line 8why, one step back
8

Merge branch 'integration'TJ Holowaychukbefore adoption0ae024a

lines 9–10why, one step back
9if ('test' != process.env.NODE_ENV)
10 app.use(express.logger('dev'));

mergedTj Holowaychukbefore adoption547d18c

line 11why, one step back
11app.use(app.router);

Added app.locals.use() testTj Holowaychukbefore adoption26c62a6

line 12why, one step back
12

mergedTj Holowaychukbefore adoption547d18c

lines 13–26why, one step back
13// the error handler is strategically
14// placed *below* the app.router; if it15// were above it would not receive errors16// from app.get() etc 17app.use(error);1819// error handling middleware have an arity of 420// instead of the typical (req, res, next),21// otherwise they behave exactly like regular22// middleware, you may have several of them,23// in different orders etc.2425function error(err, req, res, next) {26 // log it

Merge branch 'integration'TJ Holowaychukbefore adoption0ae024a

lines 27–28why, one step back
27 if ('test' != process.env.NODE_ENV)
28 console.error(err.stack);

mergedTj Holowaychukbefore adoption547d18c

lines 29–33why, one step back
29
30 // respond with 500 "Internal Server Error".31 res.send(500);32}33

Added app.locals.use() testTj Holowaychukbefore adoption26c62a6

lines 34–40why, one step back
34app.get('/', function(req, res){
35 // Caught and passed down to the errorHandler middleware36 throw new Error('something broke!');37});3839app.get('/next', function(req, res, next){40 // We can also pass exceptions to next()

mergedTj Holowaychukbefore adoption547d18c

lines 41–43why, one step back
41 process.nextTick(function(){
42 next(new Error('oh no!'));43 });

Added app.locals.use() testTj Holowaychukbefore adoption26c62a6

lines 44–45why, one step back
44});
45

Merge branch 'integration'TJ Holowaychukbefore adoption0ae024a

lines 46–49why, one step back
46if (!module.parent) {
47 app.listen(3000);48 console.log('Express started on port 3000');49}