How to fix Error: listen EADDRINUSE while using nodejs?

前端 未结 30 3197
执念已碎
执念已碎 2020-11-22 06:44

If I run a server with the port 80, and I try to use xmlHTTPrequest i get this error: Error: listen EADDRINUSE

Why is it problem for nodejs, if I want t

相关标签:
30条回答
  • 2020-11-22 07:03

    In below command replace your portNumber

    sudo lsof -t -i tcp:portNumber | xargs kill -9
    
    0 讨论(0)
  • 2020-11-22 07:04

    In my case Apache HTTP Server was run on port 80 I solved it by issue the command as root

    sudo killall httpd

    Update

    If Jenkin is installed and running on your Mac;

    1. You can check it with sudo lsof -i tcp:8080
    2. If Yes, and You want to stop Jenkins only once, run: sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
    0 讨论(0)
  • 2020-11-22 07:06

    I have the same problem too,and I simply close the terminal and open a new terminal and run

    node server.js
    

    again. that works for me, some time just need to wait for a few second till it work again.

    But this works only on a developer machine instead of a server console..

    0 讨论(0)
  • 2020-11-22 07:07

    For other people on windows 10 with node as localhost and running on a port like 3500, not 80 ...

    What does not work:

    killall    ?  command not found
    ps -aux | grep 'node'     ?     ps:  user x unknown 
    

    What shows information but still not does work:

     ps -aef | grep 'node'
     ps ax
     kill -9 61864
    

    What does work:

    Git Bash or Powershell on Windows

      net -a -o | grep 3500   (whatever port you are looking for) 
    

    Notice the PID ( far right )
    I could not get killall to work... so

    1. Open your task manager
    2. On processes tab , right click on Name or any column and select to include PID
    3. Sort by PID, then right click on right PID and click end task.

    Now after that not so fun exercise on windows, I realized I can use task manager and find the Node engine and just end it.

    FYI , I was using Visual Studio Code to run Node on port 3500, and I use Git Bash shell inside VS code. I had exited gracefully with Ctrl + C , but sometimes this does not kill it. I don't want to change my port or reboot so this worked. Hopefully it helps others. Otherwise it is documentation for myself.

    0 讨论(0)
  • 2020-11-22 07:09

    Under a controller env, you could use:

    pkill node before running your script should do the job.

    Bear in mind this command will kill all the node processes, which might be right if you have i.e a container running only one instance, our you have such env where you can guarantee that.

    In any other scenario, I recommend using a command to kill a certain process id or name you found by looking for it programmatically. like if your process is called, node-server-1 you could do pkill node-server-1.

    This resource might be useful to understand: https://www.thegeekstuff.com/2009/12/4-ways-to-kill-a-process-kill-killall-pkill-xkill/

    0 讨论(0)
  • 2020-11-22 07:10

    Try both commands and it will stop all node process.

    killall 9 node
    pkill node
    npm start 
    
    0 讨论(0)
提交回复
热议问题