Express没有方法配置错误 [英] Express has no method configure error

查看:161
本文介绍了Express没有方法配置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用MEAN堆栈。我正在关注本教程:链接

I'm trying to get started with the MEAN stack. And I'm following this tutorial: link

我直到测试我们的服务器部分。这里

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

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

It simply says app has no method configure(I guess). But when I delete the configure part and run it again, it works.(This mean app has .listen method, so it is an express object.)

我已经尝试过节点和nodemon。我无法想像出来。谢谢你的时间。

I have tried with both node and nodemon. And I couldn't figure it out. Thank you for your time.

推荐答案

配置方法已从4.0.0版本的快速移除(包括4.0.0 -rc2)。请参阅 https:// github上的更改日志。 com / strongloop / express / blob / master / History.md#400--2014-04-09

The configure method has been removed from express as of version 4.0.0 (including 4.0.0-rc2). See the changelog at https://github.com/strongloop/express/blob/master/History.md#400--2014-04-09

这篇关于Express没有方法配置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆