how to release localhost from Error: listen EADDRINUSE

前端 未结 28 2048
孤独总比滥情好
孤独总比滥情好 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:29

    you can change your port in app.js or in ur project configuration file.

    default('port', 80)

    and to see if port 80 is already in use you can do

    netstat -antp |grep 80

    netstat -antp |grep node

    you might wanna see if node process is already running or not.

    ps -ef |grep node

    and if you find its already running, you can kill it using

    killall node

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

    On Linux (Ubuntu derivatives at least)

    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:

    kill -9 <pid>
    
    0 讨论(0)
  • 2020-11-28 18:34

    Error: listen EADDRINUSE to solve it in Ubuntu run in terminal netstat -nptl and after this kill -9 {process-number} this command is to kill node process and now you can try to run again node server.js command

    Ex

    listen EADDRINUSE :::8080

    netstat -nptl

    tcp6 0 0 :::9000 :::* LISTEN 9660/java
    tcp6 0 0 :::5800 :::* LISTEN -
    tcp6 0 0 :::5900 :::* LISTEN -
    tcp6 0 0 :::8080 :::* LISTEN 10401/node
    tcp6 0 0 :::20080 :::* LISTEN 9660/java
    tcp6 0 0 :::80 :::* LISTEN -
    tcp6 0 0 :::22 :::* LISTEN -
    tcp6 0 0 :::10137 :::* LISTEN 9660/java

    kill -9 10401

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

    [SOLVED]

    It's might be too late but it's working like a charm.

    You need pm2 to be installed

    npm install -g pm2
    

    To stoping the current running server (server.js):

    pm2 stop -f server.js
    
    0 讨论(0)
  • 2020-11-28 18:36

    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>
    
    0 讨论(0)
  • 2020-11-28 18:37

    This works on Mac:

    Step 1.

    sudo lsof -i tcp:3000 (or whatever port you want to kill)
    

    Above command will give you the Process Id(s) currently holding the port.

    Step 2.

    Kill -9 <pid>
    
    0 讨论(0)
提交回复
热议问题