![](/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.