Home > Web Front-end > JS Tutorial > Why Am I Getting 'Error: listen EADDRINUSE' When Running a NodeJS Server and Making an XMLHttpRequest?

Why Am I Getting 'Error: listen EADDRINUSE' When Running a NodeJS Server and Making an XMLHttpRequest?

Barbara Streisand
Release: 2024-11-14 20:06:02
Original
666 people have browsed it

Why Am I Getting

Resolving "Error: listen EADDRINUSE" while Utilizing NodeJS

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);
Copy after login

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();
Copy after login

Solution:
To resolve this issue, consider terminating the nodejs process using:

killall -9 node
Copy after login

Note that this command will abruptly end a system process. To verify the termination, execute:

ps ax
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template