![](/img/trans.png)
[英]Object function router(req, res, next) { router.handle(req, res, next); } has no method
[英]TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure'
任何人都可以指出为什么我在尝试运行以下代码时出现此错误?
var express = require('express');
var login = require('./routes/login');
var app = express();
//all environments
app.configure(function () {
app.use(express.logger('dev'));
app.use(express.bodyParser());
});
app.post('/loginUser',login.loginUser);
app.listen(3000);
console.log("Listening on port 3000...");
我使用带有快速4.x版本的node.js。
Tom在他的博客文章new-features-node-express-4中提供了如何在Express版本3.x中使用app.configure转换为在Express 4.0版中删除它的示例。
为方便起见,我在下面添加了代码示例。 在下面的示例中,您可以将“set”替换为“use”。
版本3.x
// all environments
app.configure(function(){
app.set('title', 'Application Title');
})
// development only
app.configure('development', function(){
app.set('mongodb_uri', 'mongo://localhost/dev');
})
// production only
app.configure('production', function(){
app.set('mongodb_uri', 'mongo://localhost/prod');
})
版本4.0
// all environments
app.set('title', 'Application Title');
// development only
if ('development' == app.get('env')) {
app.set('mongodb_uri', 'mongo://localhost/dev');
}
// production only
if ('production' == app.get('env')) {
app.set('mongodb_uri', 'mongo://localhost/prod');
}
Express 4.x没有配置方法。
https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x
此外,它没有express.logger
和express.bodyParser
很久以前已被弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.