var express = require('express'); var util = require('util'); var app = express.createServer(); var pagehits = 0; app.configure('dev', function() { app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure(function() { app.use(express.logger('dev')); app.use(express.favicon()); app.use(app.router); /* empty, next() would lead us here */ }); app.get('/*', function(req, res, next) { pagehits++; /* look at app.use*, app.router brings us here since we have a GET match here, * we need to call next() so we pass control to whoever is next */ next(); }); app.get('/info', function(req, res) { res.send('page hits: ' + pagehits + '\n'); }); app.get('/user/:id([0-9]+)', function(req, res) { res.send('user ' + req.params.id); }); app.get('/', function(req, res) { res.send('hello, world!\n'); }); app.use(function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.write('resorting to connect! could do my original routing\n'); res.end(); }); app.listen(8081);