[Node.js] 学习笔记 - express 3中的 app.use(app.router)

在学习一些express相关项目时,github project source中的example常常还是以
express 3.X为基础来举例的, 而其中的
app.use(app.router)有点没头没尾,让人有点困惑。

Express 4

Express 4.0 removes app.router. All middleware (app.use) and routes (app.get et al) are now processed in precisely the order in which they are added.

[quote]
All routing methods will be added in the order in which they appear. You should not do app.use(app.router). This eliminates the most common issue with Express.

In other words, mixing app.use() and app[VERB]() will work exactly in the order in which they are called.

app.get('/', home);
app.use('/public', require('st')(process.cwd()));
app.get('/users', users.list);
app.post('/users', users.create);[/quote]
Express 2 and 3
Note that if you don't explicitly use the router, it is implicitly added by Express at the point you define a route (which is why your routes still worked even though you commented out app.use(app.router)).


详见:
http://stackoverflow.com/questions/12695591/node-js-express-js-how-does-app-router-work
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值