当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

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

发表于: 2014-04-26   作者:cute.spring   来源:转载   浏览次数:
摘要: 在学习一些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 (
在学习一些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.

引用

    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);

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

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

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
Error: Most middleware (like bodyParser) is no longer bundled with Express and m ust be insta
Error: Most middleware (like bodyParser) is no longer bundled with Express and m ust be insta
Error: Most middleware (like bodyParser) is no longer bundled with Express and m ust be insta
1.我选择了eclipse。 当然可能更多的人喜欢用webstorm,这都不是关键 首先在eclipse中安装一下node
1.HelloWorld 方法1,直接运行 安装好node js后,在cmd命令窗口输入node. 然后你可以直接输入:cons
这几天便便都昏昏沉沉的,无意间发现有一个《七天学会NodeJS》的博文,平时便便一律认为神马《21天
http://howtonode.org/how-to-install-nodejs http://www.mcclean-cooper.com/valentino/cygwin_ins
三、使用Node.js进行Web开发   1.安装Express     Express是官方推荐的Web开发框架,功能十分
公司项目告一段落,终于有闲工夫静下心来认真学习了。 最近Node.js吵得火热,身为前端也不得不去了
Node.js[5] connect & express简介 Node.js[4] 第一个模块 Node.js[3] 俯瞰API (整理中) Node.js[
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号