How to fix Error: listen EADDRINUSE while using no

2018-12-31 10:22发布

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 to do a request, while I run a server on the port 80? For the webbrowsers it is not a problem: I can surf on the internet, while the server is running.

The server is:

  net.createServer(function (socket) {
    socket.name = socket.remoteAddress + ":" + socket.remotePort;
    console.log('connection request from: ' + socket.remoteAddress);
    socket.destroy();
  }).listen(options.port);

And the request:

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function() {
    sys.puts("State: " + this.readyState);

    if (this.readyState == 4) {
        sys.puts("Complete.\nBody length: " + this.responseText.length);
        sys.puts("Body:\n" + this.responseText);
    }
};

xhr.open("GET", "http://mywebsite.com");
xhr.send();

30条回答
其实,你不懂
2楼-- · 2018-12-31 11:04

pkill node before running your script should do the job.

查看更多
步步皆殇っ
3楼-- · 2018-12-31 11:04

Error: listen EADDRINUSE means the port which you want to assign/bind to your application server is already in use. You can either assign another port to your application.

Or if you want to assign the same port to the app. Then kill the application that is running at your desired port.

For a node application what you can try is, find the process id for the node app by :

ps -aux | grep node

After getting the process id, do

kill process_id
查看更多
余生请多指教
4楼-- · 2018-12-31 11:05

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.

查看更多
旧时光的记忆
5楼-- · 2018-12-31 11:05

Seems there is another Node ng serve process running. Check it by typing this in your console (Linux/Mac):

ps aux|grep node

and quit it with:

kill -9 <NodeProcessId>

OR alternativley use

ng serve --port <AnotherFreePortNumber>

to serve your project on a free port of you choice.

查看更多
唯独是你
6楼-- · 2018-12-31 11:05

Windows is always tricky with open source..

change the port simply it works

node-inspector --web-port=8099
查看更多
呛了眼睛熬了心
7楼-- · 2018-12-31 11:07

sudo kill $(sudo lsof -t -i:80)

for force kill

sudo kill -9 $(sudo lsof -t -i:80)

use above cmd to kill particular port and then run your server

查看更多
登录 后发表回答