Express没有方法configuration错误

我正在尝试开始使用MEAN堆栈。 我正在学习这个教程: 链接

我已经做了,直到testing我们的服务器部分。 这里

// modules ================================================= var express = require('express'); var app = express(); var mongoose= require('mongoose'); // configuration =========================================== // config files var db = require('./config/db'); var port = process.env.PORT || 8080; // set our port mongoose.connect(db.url); // connect to our mongoDB database (uncomment after you enter in your own credentials in config/db.js) app.configure(function() { app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users app.use(express.logger('dev')); // log every request to the console app.use(express.bodyParser()); // have the ability to pull information from html in POST app.use(express.methodOverride()); // have the ability to simulate DELETE and PUT }); // routes ================================================== require('./app/routes')(app); // configure our routes // start app =============================================== app.listen(port); // startup our app at http://localhost:8080 console.log('Magic happens on port ' + port); // shoutout to the user exports = module.exports = app; // expose app 

当我跑步

 nodemon server.js 

我得到这个错误

 app.configure(function() { ^ TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure' at Object.<anonymous> (C:\Users\Yuksel\Desktop\node\test\server.js:14:5) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3 5 Mar 17:27:20 - [nodemon] app crashed - waiting for file changes before startin g... 

它只是说,应用程序没有方法configuration(我猜)。 但是,当我删除configuration部分,再次运行,它的工作原理(这意味着应用程序有.listen方法,所以它是一个明确的对象。)

我已经尝试了节点和nodemon。 而我无法弄清楚。 感谢您的时间。

从版本4.0.0(包括4.0.0-rc2)已经删除了configure方法。 请参阅https://github.com/strongloop/express/blob/master/History.md#400–2014-04-09上的更新日&#x5FD7;

Tom在他的博客文章中提供了新特性 – 节点 – expression – 4的示例,说明如何从express.v3.x使用app.configure转换为Express 4.0。

为了方便,我添加了下面的代码示例。

版本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'); }