how to release localhost from Error: listen EADDRINUSE

前端 未结 28 2045
孤独总比滥情好
孤独总比滥情好 2020-11-28 17:53

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

Error: listen EADDRINUSE
         


        
相关标签:
28条回答
  • 2020-11-28 18:21

    The aforementioned killall -9 node, suggested by Patrick works as expected and solves the problem but you may want to read the edit part of this very answer about why kill -9 may not be the best way to do it.

    On top of that you might want to target a single process rather than blindly killing all active processes.

    In that case, first get the process ID (PID) of the process running on that port (say 8888):

    lsof -i tcp:8888
    

    This will return something like:

    COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    node     57385   You   11u  IPv6 0xac745b2749fd2be3      0t0  TCP *:ddi-tcp-1
    

    (LISTEN) Then just do (ps - actually do not. Please keep reading below):

    kill -9 57385
    
    0 讨论(0)
  • 2020-11-28 18:21

    I have solved this issue by adding below in my package.json for killing active PORT - 4000 (in my case) Running on WSL2/Linux/Mac

    "scripts": {
        "dev": "nodemon app.js",
        "predev":"fuser -k 4000/tcp && echo 'Terminated' || echo 'Nothing was running on the PORT'",
      }
    

    Source

    0 讨论(0)
  • 2020-11-28 18:22

    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.

    0 讨论(0)
  • 2020-11-28 18:22

    To anyone who has tried all of the above, but still can't find the rouge process, try them all again but make sure you include "sudo" in front of the commands.

    0 讨论(0)
  • 2020-11-28 18:23

    In window, please execute this command:

    taskkill /F /PID 1952
    
    0 讨论(0)
  • 2020-11-28 18:24

    If you like UI more, find the process Node.js in windows task manager and kill it.

    0 讨论(0)
提交回复
热议问题