node.js 如何从错误中释放本地主机:听 EADDRINUSE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8553957/
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 14:54:45  来源:igfitidea点击:

how to release localhost from Error: listen EADDRINUSE

node.jswindows-7

提问by adam

i am testing a server written in nodejs on windows 7 and when i try to run the tester in the command line i get the following error

我正在 Windows 7 上测试用 nodejs 编写的服务器,当我尝试在命令行中运行测试器时,出现以下错误

Error: listen EADDRINUSE
at errnoException (net.js:614:11)
at Array.0 (net.js:704:26)
at EventEmitter._tickCallback (node.js:192:40)

how can I fix it without rebooting?

如何在不重新启动的情况下修复它?

采纳答案by fent

It means the address you are trying to bind the server to is in use. Try another port or close the program using that port.

这意味着您尝试将服务器绑定到的地址正在使用中。尝试另一个端口或关闭使用该端口的程序。

回答by Komposr

Run:

跑:

ps -ax | grep node

You'll get something like:

你会得到类似的东西:

60778 ??         0:00.62 /usr/local/bin/node abc.js

Then do:

然后做:

kill -9 60778

回答by WolfReporter

On Linux (Ubuntu derivatives at least)

在 Linux 上(至少是 Ubuntu 衍生版)

killall node

is easier than this form.

比这种形式更容易。

ps | grep <something>
kill <somepid>

Neither will work if you have a orphaned child holding the port. Instead, do this:

如果您有一个持有端口的孤儿,两者都不会起作用。相反,请执行以下操作:

netstat -punta | grep <port>

If the port is being held you'll see something like this:

如果端口被保留,您将看到如下内容:

tcp           0      0.0.0.0:<port>          0.0.0.*       LISTEN     <pid>/<parent>

Now kill by pid:

现在通过pid杀死:

kill -9 <pid>

回答by wcurtis

The following command will give you a list of node processes running.

以下命令将为您提供正在运行的节点进程列表。

ps | grep node

To free up that port, stop the process using the following.

要释放该端口,请使用以下命令停止该进程。

kill <processId>

回答by Benny Neugebauer

You are getting the error EADDRINUSEbecause the port, which your application wants to use, is occupied by another process. To release this port, you need to terminate the occupying process.

您收到错误EADDRINUSE是因为您的应用程序要使用的端口被另一个进程占用。要释放此端口,您需要终止占用进程。

Since you are on Windows, you can terminate the process using the command prompt (cmd). With the cmdyou can discover the process ID (PID) of the blocking application. You will need the PID in order to terminate / kill the process.

由于您在Windows 上,您可以使用命令提示符 ( cmd)终止进程。使用cmd可以发现阻塞应用程序的进程 ID (PID)。您将需要 PID 才能终止/终止进程。

Here is a step-by-step guide...

这是一个分步指南......

  1. Find all processes which are running on a specified port (in this example, Port is "3000"):

    netstat -ano | find ":3000 "

  2. The netstatcommand will list up all processes running on the specified port. In the last column of the netstatresults you can see the PIDs (in this example, PID is "8308"). You can find out more about a specific PIDby running the following command:

    tasklist /fi "pid eq 8308"

  3. If you want to terminate a process, you can do that with the following command by using its PID(in this example, PID is "8308"):

    taskkill /pid 8308 /f

  1. 查找在指定端口上运行的所有进程(在本例中,端口为“3000”):

    netstat -ano | 找到“:3000”

  2. netstat命令将列出在指定端口上运行的所有进程。在结果的最后一列中,netstat您可以看到PIDs(在本例中,PID 为“8308”)。您可以PID通过运行以下命令找到有关特定信息的更多信息:

    任务列表/fi“pid eq 8308”

  3. 如果你想终止一个进程,你可以使用它的以下命令来完成PID(在这个例子中,PID是“8308”):

    taskkill /pid 8308 /f

Screenshot

截屏

enter image description here

在此处输入图片说明

回答by swathy valluri

When you get an error Error: listen EADDRINUSE,

当你得到错误 Error: listen EADDRINUSE,

Try running the following shell commands:

尝试运行以下 shell 命令:

netstat -a -o | grep 8080
taskkill /F /PID 6204

I greped for 8080, because I know my server is running on port 8080. (statictells me when I start it: 'serving "." at http://127.0.0.1:8080'.) You might have to search for a different port.

greped 为 8080,因为我知道我的服务器在端口 8080 上运行。(static在我启动它时告诉我:'serving "." at http://127.0.0.1:8080'。)您可能需要搜索不同的港口。

回答by Arun Kasyakar

suppose your server is running on port 3000

假设您的服务器正在运行 port 3000

lsof -i tcp:3000
    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    node    11716 arun   11u  IPv6 159175      0t0  TCP *:3000 (LISTEN)

after that use kill -9 <pid>

在那次使用之后 kill -9 <pid>

in the above case sudo kill -9 11716

在上述情况下 sudo kill -9 11716

回答by Atta Ur Rahman

use below command to kill a process running at a certain port - 3000 in this example below

使用以下命令杀死在某个端口运行的进程 - 在下面的示例中为 3000

kill -9 $(lsof -t -i:3000)

回答by iloo

One possible solution that worked for me was simply to close the window in browser where I had the corresponding "http://localhost:3000/" script running.

对我有用的一种可能的解决方案是简单地关闭浏览器中运行相应“ http://localhost:3000/”脚本的窗口。

回答by Surender Kumar

Check the Process ID

检查进程 ID

sudo lsof -i:8081

须藤 lsof -i:8081

Than kill the particular Process

比杀死特定进程

sudo kill -9 2925

须藤杀-9 2925

enter image description here

在此处输入图片说明