Node.js websocket error “Error: listen EADDRNOTAVAIL Error: listen EADDRNOTAVAIL”

前端 未结 5 1559
萌比男神i
萌比男神i 2020-12-16 01:44

Application work fine on localhost .but when its connect to server it getting error.
I connect server through port 22

This is the error

Error:          


        
5条回答
  •  情话喂你
    2020-12-16 02:17

    I think you are using a Unix based OS, if that is the case then you can't use any port below 1024 without sudo access.

    Also before digging too deep check that the listening port is not being used by any other process.

    A quick fix (for development only):

    • sudo node file.js or
    • server.listen(3000); // any number > 1024

    For production (never run node on production with root access.)

    you have to map the listening port (ex:3000) to 80 using ip tables

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
    

提交回复
热议问题