Node js 监听简单 httpserver 的 EADDRINUSE 错误
我有简单的 Node js http 服务器。
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
如果我运行
node basicserver.js
,我会
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:642:11)
at Array.0 (net.js:743:26)
at EventEmitter._tickCallback (node.js:192:40)
看到 this 帖子,但该帖子似乎特定于 TCP 服务器而不是 http 服务器。有人可以帮忙吗?
I have simple node js http server.
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);
If I run
node basicserver.js
I get
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:642:11)
at Array.0 (net.js:743:26)
at EventEmitter._tickCallback (node.js:192:40)
I have seen this post, but that post seems to be specific to TCP server and not http server. Could anyone please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您正在侦听的端口已被另一个进程侦听。在这种情况下,我有一种感觉,那就是你自己。您可以执行 ps aux | grep node 然后使用
kill
终止您的节点进程。除此之外,您还可以尝试其他端口。--更新--
如果你想知道哪个进程正在监听,你可以使用
netstat -lpn
(-l
是找出监听端口,-p
是包含进程名和pid,-n
是不解析主机名,否则会很慢),找到正在监听不同的进程端口。如果太多,您可以执行netstat -lnp | grep :8888 。也可以使用,
fuser 8888/tcp
,它将显示进程 pid,并且添加-k
将杀死进程,这是有史以来最快的方法。我意识到这两个命令只能在 linux 中工作。
The port you are listening to is already being listened by another process. In this case I got a feeling that it is your self. You can do a
ps aux | grep node
and then usingkill <pid>
kill your node process. Beside that you can also try another port.--Update--
In case if you want to find which process is listening, you can use
netstat -lpn
(-l
is to find out the listening ports,-p
is to include the process name and pid,-n
is to not to resolve host names, or else it will be slow), to find the processes that are listening on different ports. If there was too many, you can donetstat -lnp | grep :8888
.Also can use,
fuser 8888/tcp
, which will show you the process pid and also adding-k
will kill the process, fastest way ever.I realized this two commands only work in linux.
杀死我机器上的所有实验......
To kill all the experiments on my machine...
您正在侦听的端口已被另一个进程侦听。
当我遇到这个错误时,我使用 Windows PowerShell 终止了该进程(因为我使用的是 Windows)
ps
然后您可以获得进程列表node
的进程code>,并注意Id
Stop-process
我认为这对 Windows 用户有帮助。
The port you are listening to is already being listened by another process.
When I faced to this error I killed the process using Windows PowerShell (because I used Windows)
ps
and then you can get list of processesnode
, and note theId
Stop-process <Id>
I think that it is help for windows users.
当您尝试运行服务器但没有 root 权限时,可能会出现同样的问题。
Same problem may occur when you try to run the server, but you don't have root privileges.
在我的
Linux Mint
上,仅通过PID
杀死对我有用:netstat -nltp | grep 8080
- 显示使用8080
端口的PID
,我的输出:tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 27599/ node
- 在我的例子中,节点开发服务器的PID
是27599
然后杀死:
kill -9
kill -9 27599
前言:
不知道什么是错误,但我像
npm run dev 一样启动我的 WebPack 开发服务器
:webpack-dev-server --hot --host int.loc --port 8080
当中断他时 - 在终端中按
Ctrl+C
并启动又来了——他造成了同样的结果错误错误:监听 EADDRINUSE 127.0.0.1:8080
,但在它工作之前一直都完美。killall 节点
没有帮助。On my
Linux Mint
only kill byPID
work for me:netstat -nltp | grep 8080
- showsPID
of using8080
port, my output:tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 27599/node
-PID
of node dev server is27599
in my caseand then kill:
kill -9 <PID>
kill -9 27599
Preamble:
Don't know what a bug, but I am start my WebPack dev server like
npm run dev
:webpack-dev-server --hot --host int.loc --port 8080
And when interrupt him - in terminal by
Ctrl+C
and start it again - he causing same errorError: listen EADDRINUSE 127.0.0.1:8080
, but all time before it work perfect.killall node
not helped.我在 EADDRINUSE 127.0.0.1 上也遇到了这个问题。检查节点进程后,我将服务器 IP 更改为“localhost”。这样做之后,它就开始了。希望这有帮助。
I also ran into this issue with EADDRINUSE 127.0.0.1. After checking for Node processes I changed the server ip to 'localhost'. After doing this it started right up. Hope this helps.
对于 Windows 用户:在 Powershell 中,您可以使用:
在本例中,
"ProcessName"
将为"node"
。更多信息请参见:如何终止 Windows 中的进程
For Windows users: in Powershell, you can use:
In this case
"ProcessName"
would be"node"
.More info here: How to kill a process in windows