Node.js服务器将不会启动,但似乎已连接到DB
我有一个节点应用程序不工作,尽管它在大约2小时前工作过(没有代码更改)。同样,没有对服务器进行任何更改,我只在同一端口上运行了另一个节点应用程序,但该进程已被终止 启动节点的命令Node.js服务器将不会启动,但似乎已连接到DB,node.js,Node.js,我有一个节点应用程序不工作,尽管它在大约2小时前工作过(没有代码更改)。同样,没有对服务器进行任何更改,我只在同一端口上运行了另一个节点应用程序,但该进程已被终止 启动节点的命令节点服务器 server.js var app = require('./server/index'); app.set('port', process.env.PORT || 3000); var server = app.listen(8080, function() { console.log('Expre
节点服务器
server.js
var app = require('./server/index');
app.set('port', process.env.PORT || 3000);
var server = app.listen(8080, function() {
console.log('Express server listening on port ' + server.address().port);
});
app.js(精简版)
启动节点进程时的输出
(node:4341) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:4341) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
MongoDB has connected successfully.
解决了这个问题,似乎使用
节点服务器
直接进入我的服务器目录并运行app.js
文件注意我想要的服务器.js
文件。相反,我必须运行node server.js
mongo只显示警告,这不是问题,但为什么要为node.js使用2个端口:app.set('port',process.env.port | 3000)
和var server=app.listen(8080…
您不能在同一端口上运行两个进程,如果您想为一个节点应用运行两个不同的进程,请使用process.env.port
(环境变量$port)更改第二个端口,但首先您应该修复server=app/.listen(端口,…)
,不要使用硬代码8080
@huynhsamha我有0个进程正在运行…我想这很清楚…你使用的是什么操作系统?Linux、Windows还是OSX?如果你使用的是Linux,请尝试sudo kill$(sudo lsof-t-I:8080)
杀死运行在操作系统上的进程8080
,然后请确保更改应用程序。听(8080)
到应用程序。侦听(端口)
并终止在端口端口上运行的进程(如果未在环境中设置端口
,则可能是3000
)
(node:4341) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:4341) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
MongoDB has connected successfully.