最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure&#3

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Mar 8, 2014 at 4:44 msrameshpmsrameshp 6362 gold badges13 silver badges33 bronze badges 1
  • 1 express 4.x version is completely different from the older versions. So all posts about express will send you in the wrong direction. I would suggest that you stick with an older version for now. npm install [email protected] – Mukesh Soni Commented Mar 8, 2014 at 4:52
Add a comment  | 

2 Answers 2

Reset to default 10

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.

For convenience I added the code example below. In the examples below you can replace "set" with "use".

Version 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

// 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.

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论