节点/Express:EADDRINUSE,地址已在使用中

编程入门 行业动态 更新时间:2024-10-27 02:18:44
本文介绍了节点/Express:EADDRINUSE,地址已在使用中-终止服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用connect在node.js中运行的简单服务器:

I have a simple server running in node.js using connect:

var server = require('connect').createServer(); //actions... server.listen(3000);

在我的代码中,我有实际的处理程序,但这就是基本思想.我一直遇到的问题是

In my code I have actual handlers, but thats the basic idea. The problem I keep getting is

EADDRINUSE, Address already in use

在先前崩溃或错误后再次运行我的应用程序时,我收到此错误.因为我没有打开终端的新实例,所以我用ctr + z关闭了该过程.

I receive this error when running my application again after it previously crashed or errors. Since I am not opening a new instance of terminal I close out the process with ctr + z.

我可以肯定,我要做的就是关闭服务器或连接.我试过在process.on('exit', ...);中打电话给server.close()并没有运气.

I am fairly certain all I have to do is close out the server or connection. I tried calling server.close() in process.on('exit', ...); with no luck.

推荐答案

首先,您想知道哪个进程正在使用port 3000

First, you would want to know which process is using port 3000

sudo lsof -i :3000

这将列出在此端口上侦听的所有 PID ,一旦您拥有 PID ,就可以使用以下命令终止该端口:

this will list all PID listening on this port, once you have the PID you can terminate it with the following:

kill -9 {PID}

更多推荐

节点/Express:EADDRINUSE,地址已在使用中

本文发布于:2023-08-07 03:33:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已在   节点   地址   EADDRINUSE   Express

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!