gpt4 book ai didi

node.js - 应用程序未在 Node Express 中初始化

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:25 25 4
gpt4 key购买 nike

我刚刚安装了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?

关于node.js - 应用程序未在 Node Express 中初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com