我刚刚安装了node和express。当我运行命令 node app.js
时,它给出以下错误。
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
/var/www/nodeexpress/nodetest1/app.js:38
console.log("Express server listening on port %d in %s mode", app.address().
^
TypeError: undefined is not a function
at Server.<anonymous> (/var/www/nodeexpress/nodetest1/app.js:38:69)
at Server.g (events.js:196:16)
at Server.EventEmitter.emit (events.js:101:17)
at net.js:1159:10
at process._tickCallback (node.js:339:11)
at Function.Module.runMain (module.js:492:11)
at startup (node.js:124:16)
at node.js:803:3
我的 app.js 看起来像
var express = require('express')
, routes = require('./routes');
//var app = module.exports = express.createServer();
var app = express();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: 'your secret here' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.listen(8080, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
express 似乎没有被初始化。我的 Node 版本是 v0.11.13-pre
并且我使用 package.json 作为 3.4.4
安装了 v0.11.13-pree 的 Express 版本
使用this.address().port而不是app.address().port
address() 是应用了 listen 函数的 http 对象的函数属性
来自连接 proto.js:
app.listen = function(){
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};
至于 connect.multipart() 警告,请检查此答案:How to get rid of Connect 3.0 deprecation alert?
我是一名优秀的程序员,十分优秀!