简体   繁体   English

为什么使用端口80在node.js中给出错误?

[英]Why does using port 80 give error in node.js?

I am new to node.js. 我是node.js的新手。 I am trying to run sudo node server.js using port 80. but I get Error: listen EADDRINUSE: address already in use :::80. 我正在尝试使用端口80运行sudo node server.js 。但出现Error: listen EADDRINUSE: address already in use :::80. But when check process running using command sudo lsof -i :80 . 但是当使用命令sudo lsof -i :80检查进程运行时。 Nothing is shown. 什么也没显示。 What may be the issue. 可能是什么问题。

I will assume your app crashed or didn't exit cleanly. 我会假设您的应用程序崩溃了或没有干净退出。

Check if your node is already running with: 检查您的节点是否已经在运行:

ps aux | grep node

Should list out all running node processes, you can then kill -9 PID to ensure everything closes. 应该列出所有正在运行的节点进程,然后可以kill -9 PID以确保一切都关闭。

您必须将sudolsof一起使用

sudo lsof -i:80 -t

In your case it can be the possibility that the port number you are trying to access is already in use in the background by some another process or server. 在您的情况下,您尝试访问的端口号可能已被某些其他进程或服务器在后台使用。 So in order to get access to that port, you should try to kill the process that is using port 80. Kill all will kill all the node apps running. 因此,为了获得对该端口的访问权限,您应该尝试终止使用端口80的进程。全部杀死将终止所有正在运行的节点应用程序。 You might not want to do that. 您可能不想这样做。 With this command you can kill only the one app that is listening on a known port. 使用此命令,您只能杀死正在已知端口上监听的一个应用程序。

If using unix try this command: 如果使用unix,请尝试以下命令:

sudo fuser -k 80/tcp 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM