简体   繁体   English

TypeError:对象函数(req,res,next){app.handle(req,res,next); 没有方法'配置'

[英]TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure'

Can anyone point out why am I getting this error when I am trying to run the following code ? 任何人都可以指出为什么我在尝试运行以下代码时出现此错误?

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

I am using node.js with the express 4.x version. 我使用带有快速4.x版本的node.js。

Tom in his blog post new-features-node-express-4 provides examples of how to convert from using app.configure in express version 3.x to removing it in express version 4.0. Tom在他的博客文章new-features-node-express-4中提供了如何在Express版本3.x中使用app.configure转换为在Express 4.0版中删除它的示例。

For convenience I added the code example below. 为方便起见,我在下面添加了代码示例。 In the examples below you can replace "set" with "use". 在下面的示例中,您可以将“set”替换为“use”。

Version 3.x 版本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');
})

Version 4.0 版本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 does not have configure method. Express 4.x没有配置方法。

https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x

Also, it doesn't have express.logger and express.bodyParser had been deprecated ages ago. 此外,它没有express.loggerexpress.bodyParser很久以前已被弃用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM