How to fix Error: listen EADDRINUSE while using nodejs?

前端 未结 30 4051
执念已碎
执念已碎 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

    While killing the NODE_PORT, it might kill your chrome process or anything that is listening to the same port, and that's annoying.

    This shell script may be helpful - in my case the port is 1337 but you can change it anytime

    # LOGIC
    
    CHROME_PIDS=`pidof chrome`
    PORT_PIDS=`lsof -t -i tcp:1337`
    
    for pid in $PORT_PIDS
    do
    
    if [[ ${CHROME_PIDS} != *$pid* ]];then
    
        # NOT FOUND IN CHROME PIDS
    
        echo "Killing $pid..."
        ps -p "$pid"
    
        kill -kill "$pid"
        fi
    
    done
    
    sails lift
    # OR 'node app' OR whatever that starts your node
    
    exit
    

提交回复
热议问题