Search code examples
node.jsexpressportws

express-ws: How to avoid typing the port on the request url?


I've successfully created a WS Server using Node.js and wxpress-ws. The problem is that I don't know which port to use to not type it in the request URL. So, instead of using ws://mysite.com::xxxx/, I need to be able to type only ws://mysite.com/

I've tried to listen port 80, 8080, without success.


Solution

  • If your application is listening on port XXXX then you will need to access it via indicating the port in your url ws://myapp.com:XXXX/.

    If you want to use ws://myapp.com/, you will need to listen to the port 80, two solutions for you :

    • Launch your application with sudo node myapp.js privileges and make it listen on port 80. I don't recommend this approach since it might introduce some vulnerabilities because the app is running with admin privileges.
    • Set up some reverse proxy like nginx that will listen on port 80 and that will redirect the traffic to your application listening on port XXXX. You can find a lot of tutorials online