Express基于Connect中间件。
Express的路由功能由
router您的应用程序提供,您可以自由地将自己的中间件添加到应用程序中。
var app = express.createServer();// Your own super cool functionvar logger = function(req, res, next) { console.log("GOT REQUEST !"); next(); // Passing the request to the next handler in the stack.}app.configure(function(){ app.use(logger); // Here you add your logger to the stack. app.use(app.router); // The Express routes handler.});app.get('/', function(req, res){ res.send('Hello World');});app.listen(3000);就这么简单。
(PS:如果您只想进行一些日志记录,则可以考虑使用Connect提供的记录器)



