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.

  



原文地址:https://www.cnblogs.com/sddai/p/9388338.html

时间: 2024-11-11 05:36:47

How to fix Error: listen EADDRINUSE while using nodejs的相关文章

nodejs出现events.js:72中抛出错误 Error: listen EADDRINUSE

<pre>events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE at errnoException (net.js:901:11) at Server._listen2 (net.js:1039:14) at listen (net.js:1061:10) at Server.listen (net.js:1127:5) at Object.<anonymous> (./server

关于“Error: listen EADDRINUSE: address already in use 127.0.0.1:3000”

今天在做一个Vue小项目的时候,遇到了这样一个bug,终端输入npm run dev指令,本来按照我在package.json文件中配置的命令:"dev": "webpack-dev-server --open --port 3000 --hot",应该会运行webpack工具打包代码后,自动打开浏览器,监听3000端口,但是此时却在终端命令行提示出错,错误信息如下: PS C:\Users\LXD\Desktop\my-vue\vue-cms> npm ru

解决运行nodejs代码Error: listen EADDRINUSE

解决运行nodejs代码Error: <wbr>listen <wbr>EADDRINUSE 错误listen EADDRINUSE 是比较常见的错误.'EADDRINUSE',借助有道的翻译,意思是:错误地址使用.'EADDRINUSE'应该是'error address in use'的缩写.后来借助google找到了合理的解释,说是你监听的端口已经被使用了! 在网上找解决方法,绝大部分是绕道而行--就是把端口改掉.无奈,我只能用80端口.但是怎么办? 在不懂nginx得情况下

npm Error: listen EADDRINUSE 127.0.0.1:8080

EADDRINUSE 解析: E: error ADDR : address INUSE : in use 翻译 error : address in use ; | 地址已使用,端口被占用 解决办法 : 1. sudo lsof -i 8080 : 查看端口使用情况 2. sudo kill -9 43021 : 杀死展示的PID 原文地址:https://www.cnblogs.com/noraZhang/p/12635365.html

vue项目npm run dev报错events.js:160 throw er; // Unhandled &#39;error&#39; event listen EADDRINUSE :::8002

出错情况,如下图: 报错原因: listen EADDRINUSE :::8002 意思是当前8002端口被占用 解决办法: 一:简单粗暴:关掉可能影响的相关程序,重新执行启动. 二: 1.Win+R,cmd查询使用的端口号是否被占用: 输入命令:netstat -aon|findstr "8002" 按回车显示占用8080端口对应的程序的PID号:如下图: 2.根据PID号找到对应的程序: 输入命令:tasklist|findstr "12452" 按回车后显示出

Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE) mac下错误记录

架好的环境运行不了,nginx报错,根据提示是80端口被占用. p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff } span.s1 { } ERROR: for eagledock_nginx_1  Cannot restart container affabde5053648c62dbadb0c0e2f44b371e3f0f0c5058e2

node启动时, listen EADDRINUSE 报错;

1.启动时, listen  EADDRINUSE 报错: 查看是因为 端口被占用了,换了端口 还是不行:      查看了 被占用的端口,端口没有为:4000: 突然想到,每次启动node服务后,都没有关闭: 于是,查看任务进程,把node.js进程关闭后,重新启动 node环境即可!

NodeJs在linux下监听端口时抛错Error: listen EACCES

[email protected]:~/nodejs/lesson$ node random.js Random Number Generator Running- events.js:72         throw er; // Unhandled 'error' event               ^ Error: listen EACCES     at errnoException (net.js:904:11)     at Server._listen2 (net.js:102

Fix error of &quot;you have been logged on with a temporary profile&quot;

You have been logged on with a temporary profile on windows2008 R2 After looking into this issue, I saw the following user profiles and I didn’t see my profile (ralin). C:\Users\TEMP.domainName.000 (first time to login) C:\Users\TEMP.domainName.001 (