How to fix Error: listen EADDRINUSE while using nodejs?

前端 未结 30 3720
执念已碎
执念已碎 2020-11-22 06:44

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 t

30条回答
  •  时光取名叫无心
    2020-11-22 06:51

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

提交回复
热议问题