How to fix Error: listen EADDRINUSE while using nodejs

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();


EADDRINUSE means that the port number which listen() tries to bind the server to is already in use.

So, in your case, there must be running a server on port 80 already.

If you have another webserver running on this port you have to put node.js behind that server and proxy it through it.

You should check for the listening event like this, to see if the server is really listening:

var http=require('http'); var server=http.createServer(function(req,res){ res.end('test'); }); server.on('listening',function(){ console.log('ok, server is running'); }); server.listen(80);


解决方案:
What really helped for me was:

killall -9 node
But this will kill a system process.

With

ps ax
you can check if it worked.

  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值