Nodejs应用程序错误:使用pm2部署时绑定EADDRINUSE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18687877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:33:11  来源:igfitidea点击:

Nodejs application Error: bind EADDRINUSE when use pm2 deploy

node.jsmongodbdeploymentexpresscluster-computing

提问by lidashuang

Express application deploy with pm2

使用pm2快速部署应用程序

database is mongodb

数据库是mongodb

when run app with command:

使用命令运行应用程序时:

NODE_ENV=production pm2 start app.js -i max

NODE_ENV=production pm2 start app.js -i max

aften has Error: bind EADDRINUSE, this is logs, when error,

aften 有错误:绑定 EADDRINUSE,这是日志,当错误时,

[app err (l0)] js:1073:26
[app err (l1)]     at Object.30:1 (cluster.js:587:5)
[app err (l2)]     at handleResponse (cluster.js:171:41)
[app err (l3)]     at respond (cluster.js:192:5)
[app err (l4)]     at handleMessage (cluster.js:202:5)
[app err (l5)]     at process.EventEmitter.emit (events.js:117:20)
[app err (l6)]     at handleMessage (child_process.js:318:10)
[app err (l7)]     at child_process.js:392:7
[app err (l8)]     at process.handleConversion.net.Native.got (child_process.js:91:7)Error: bind EADDRINUSE
[app err (l9)]     at errnoException (net.js:901:11)
[app err (l10)]     at net.js:1073:26
[app err (l11)]     at Object.31:1 (cluster.js:587:5)
[app err (l12)]     at handleResponse (cluster.js:171:41)
[app err (l13)]     at respond (cluster.js:192:5)
[app err (l14)]     at handleMessage (cluster.js:202:5)
[app err (l15)]     at process.EventEmitter.emit (events.js:117:20)
[app err (l16)]     at handleMessage (child_process.js:318:10)
[app err (l17)]     at child_process.js:392:7
[app err (l18)]     at process.handleConversion.net.Native.got (child_process.js:91:7)

This causes app is slow, How to solve this problem, thanks very much

这导致应用程序很慢,如何解决这个问题,非常感谢

回答by Sandro Munda

I don't know the port used by your application. It depends on your code. In this example, I will assume the port is 3000.

我不知道您的应用程序使用的端口。这取决于您的代码。在这个例子中,我假设端口是3000.

You need to verify if the port is already took on your system. To do that:

您需要验证该端口是否已在您的系统上使用。要做到这一点:

  • On linux: sudo netstat -nltp | grep 3000
  • On OSX: sudo lsof -i -P | grep 3000
  • 在 Linux 上: sudo netstat -nltp | grep 3000
  • 在 OSX 上: sudo lsof -i -P | grep 3000

If you have a result, you need to kill the process (kill <pid>).

如果有结果,则需要终止进程 ( kill <pid>)。

You should check if pm2 listreturns 0 process. In addition, when you do a pm2 stopAll, the socket is not released. Don't forget to do a pm2 killto be sure the daemon is killed.

您应该检查是否pm2 list返回 0 进程。此外,当您执行 a 时pm2 stopAll,不会释放套接字。不要忘记执行 apm2 kill以确保守护进程已被杀死。

$ pm2 kill
Daemon killed

回答by Lukas Liesis

OS X

操作系统

Cmd+Space -> enter: Activity Monitor -> find your app and terminate it.

Cmd+Space -> 输入:Activity Monitor -> 找到你的应用并终止它。

enter image description here

在此处输入图片说明