node/express 中的服务器不在 运行

Server not running in node/express

我的server.js代码是:

var express = require('express');

var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';

var app = express();

app.configure(function(){

    app.set('views', ___dirname + '/server/views');
    app.set('view engine', 'jade');
});

app.get('*', function(req, res){
    res.render('index');
});
var port = 3030;
app.listen(port);
console.log('listening on Port' + port + '....');

问题是:

TypeError: undefined is not a function
at Object.<anonymous> (F:\MeanSite\server.js:7:5)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

7 月 10 日 14:21:07 - [nodemon] 应用崩溃 - 等待文件更改 bef

您一定是从过时的文档或博客中复制了该代码,configure 方法已在 Express 4 中删除。

请参阅 Migrating to Express 4,具体请参阅

app.configure() has been removed. Use process.env.NODE_ENV or app.get('env') to detect the environment and configure the app accordingly.

快速修复: 更改

app.configure(function(){
    app.set('views', ___dirname + '/server/views');
    app.set('view engine', 'jade');
});

app.set('views', ___dirname + '/server/views');
app.set('view engine', 'jade');