Home > Article > Web Front-end > Why Am I Getting 'Error: listen EADDRINUSE' When Running a NodeJS Server and Making an XMLHttpRequest?
Problem Description:
When attempting to run a server on port 80 and simultaneously make an XMLHttpRequest request, the "Error: listen EADDRINUSE" is encountered. This is despite browsers being able to continue browsing the internet while the server is running.
Server Implementation:
net.createServer(function (socket) { socket.name = socket.remoteAddress + ":" + socket.remotePort; console.log('connection request from: ' + socket.remoteAddress); socket.destroy(); }).listen(options.port);
Request Implementation:
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();
Solution:
To resolve this issue, consider terminating the nodejs process using:
killall -9 node
Note that this command will abruptly end a system process. To verify the termination, execute:
ps ax
The above is the detailed content of Why Am I Getting 'Error: listen EADDRINUSE' When Running a NodeJS Server and Making an XMLHttpRequest?. For more information, please follow other related articles on the PHP Chinese website!