How to fix Error: listen EADDRINUSE while using nodejs?

前端 未结 30 3198
执念已碎
执念已碎 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条回答
  • There is a way to terminate the process using Task Manager:

    Note that this solution is for Windows only

    1. Go to the Task Manager (or using the shortcut Ctrl + Shift + Esc)

    2. On "Background Processes", find "Node.js" processes and terminate them (Right-click them and choose "End Task")

    1. Now you should be able to start again
    0 讨论(0)
  • 2020-11-22 07:12

    This error comes when you have any process running on a port on which you want to run your application.

    how to get which process running on that port=> command: sudo netstat -ap | grep :3000

    output : you will get the process information which is using that port

    tcp 0 0 IPaddress:3000 : LISTEN 26869/node

    Now you can kill that process sudo kill -9 26869

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

    I have seen this error before (in node) with http.client, and as I recall, the problem had to do with not initializing the httpClient or setting bad options in the httpClient creation and/or in the url request.

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

    Error reason: You are trying to use the busy port number

    Two possible solutions for Windows/Mac

    1. Free currently used port number
    2. Select another port number for your current program


    1. Free Port Number

    Windows

    1. netstat -ano | findstr :4200
    2. taskkill /PID 5824 /F
    

    Mac

    You can try netstat

    netstat -vanp tcp | grep 3000
    

    For OSX El Capitan and newer (or if your netstat doesn't support -p), use lsof

    sudo lsof -i tcp:3000
    

    if this does not resolve your problem, Mac users can refer to complete discussion about this issue Find (and kill) process locking port 3000 on Mac


    2. Change Port Number?

    Windows

    set PORT=5000
    

    Mac

    export PORT=5000
    
    0 讨论(0)
  • 2020-11-22 07:14

    In my case I use a web hosting but it´s the same in local host, I used:

    ps -aef | grep 'node' 
    

    for watch the node process then, the console shows the process with PID. for kill the process you have to use this command:

    kill -9 PID
    

    where PID is the process id from the command above.

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

    Another thing that can give this error, is two HTTP servers in the same node code. I was updating some Express 2 to Express 3 code, and had this...

    http.createServer(app).listen(app.get('port'), function(){            
      console.log('Express server listening on port ' + app.get('port')); 
    });        
    
    // tons of shit.
    
    http.createServer(app).listen(app.get('port'), function(){            
      console.log('Express server listening on port ' + app.get('port')); 
    });                                                                   
    

    And, it triggered this error.

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