分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

How to fix Error: listen EADDRINUSE while using nodejs

发布时间:2023-09-06 02:06责任编辑:白小东关键词:jsnodejs

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 nodeBut this will kill a system process.Withps axyou can check if it worked.

  



How to fix Error: listen EADDRINUSE while using nodejs

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved