How to link node+express server to domain - node.js

I have a domain name pointing to my vps IP. But when I run my express server I have to set a port, usually I use 3000, so the only way to get in my website is specifying the port: www.mysite.com:3000.
How can I make my app run in my domain without adding any port? My first guess was setting also the port in my domain name provider (111.11.11.11:3000) but Godaddy doesn't let me to add the port.
How can I make it work?
Newbie question, I know, but i'm a first timer and haven't found any answer to this.

The correct way is to change the port its hosted on. The default port for http traffic is 80, the one for https is 443. I assume you are on linux, if so you need to give some special permissions as ports below 1024 are privileged ports.
TLDR: if running http, change your express config to 80, if https 443

If using express, you need to change express port from 3000 to 80 if you plan using HTTP or 443 if you plan using HTTPS.
This is assuming your VPS does not already use port 80 or 443 while running an HTTP server like apache or nginx.
If you are in this case you will need to set up a reverse proxy.

I went for Nginx solution, I could make the port forward really easy following this guide:
https://eladnava.com/binding-nodejs-port-80-using-nginx/
For those who face this problem, solution is much more easier than it could look at beginning.

Related

Which is best port to use for secure Chat server to allow general firewall bypass (port 443 is already occupied)

so I developed a public chat application which will run on a node server using secure socket.io.
That server, which only has a single IP address already has ports 80 / 443 occupied.
So I need to find the next best port to use for the chat server.
I wonder is there a recommended next best port that will allow most firwalls to communicate to? I know for example using ports like 21 (FTP) will normally be blocked.
And is it best to pick one above 1024 or below?
thanks
Sean.
In general 8443 will be the "alternative port for HTTPS", but you are still at risk of being filtered.
The proper solution should be to run proxy like nginx on port 443 and provide access to various applications based on the hostname, not the port. In example you can configure it to run your current app when user reaches https://example.com and chat app when user reaches https://chat.example.com.
Here is an example article showing how to do it https://www.manuelkruisz.com/blog/posts/nginx-multiple-domains-one-server
The idea is that each app runs on different internal port on the server, and proxy running on port 443 picks which app the request should be routed to based on the hostname.

Run node js application without port

I wants to run my application without assigning any port on my current IP address on port 80. How it will possible.
If your node.js application is a web server, you cannot remove the port. No port, no web server. Trying to make a web server without a port is like trying to make a locomotive with no railroad.
You can use the default port however. When users give browsers URLs without ports, they automatically apply the default port. For URLs like http://example.com/ or http://10.11.12.13/ the default port is 80. For https://example.com it's 443, and you need to use the https server class.
So, you can make your server listen on port 80.
In development you will run into a problem with this approach. On OSX, Linux, and other UNIX-derived OSs, only the privileged (root) user can run servers that use port numbers less than 1024. The typical development cycle of edit / run / test is a huge hassle, and a security hole, when you need privileges to run. That's why the node.js examples use port 3000.
In production, many people use nginx as a reverse proxy server to relay http requests from port 80 or https requests from port 443 to your node.js server at port 3000. You can read about how to do that; it's far beyond the scope of a Stack Overflow answer,

Make a subdomain to point on a specific port

I already checked some topic about it but didn't find any solutions (if it's possible). I have a domain that points on my server on the port 80, but, I have another important webservice running on the port 8080.
I want to know if it's possible to create a subdomain like (admin.example.com) which points on port 8080.
Thanks
The simple answer is no. The server name is resolved by a DNS query to a single IP, to which port the connection is made is between the application and the server. For HTTP the conventional default port is 80 and HTTPS 443, if you need to use another port, you need to include it in your URL.
SRV entries in a DNS record can be used so resolve a hostname to a specific port, but this works reliably only for a handful of protocols that mandate its use.
Currently the preferable way is to set up your server with a reverse proxy to direct traffic by a specific server name (your subdomain, carried in the request headers) to your admin service. This is quite easily done using e.g. nginx.

NodeJS: access using domain without port

I followed this tutorial to deploy NodeJS my app on the server.
My issue is that, I only can access the service using domain:port (example.com:1234) not domain name only (example.com).
How can I configure my app to access the service without adding the port to the address/domain name?
TCP connections always require you, the client, to specify a port. You're able to visit domain.com in your browser without specifying a port because your browser implicitly connects on the conventional ports: 80 for HTTP and 443 for HTTPS.
Your application server needs to bind to one of these ports in order to achieve what you're going for.
EDIT: Just skimmed the tutorial you linked to. Since your application is sitting behind a reverse proxy , you'll need NGINX to own 80/ 443 (which it should do by default). You can bind the app server to whatever port you want, so long as the reverse proxy config matches up with it.

How do IP addresses work on a VPS? Routing a domain name to Node.JS

This is an absolute newb question. But I'm buying my first VPS for the reason that I want to install and start creating applications in Node.JS.
I can't visualise in my mind how the server works and where all of the applications such as Apache, Node.JS and PHP sit. I'm so used to a GUI.
I want www.mydomain.com to point to node.JS on my server, let's say Node is listening to port 8080. Now I know that HTTP defaults to port 80 of the IP address, so I can't use that. How do I set the domain up to resolve at www.mydomain.com:8080 - I read this wasn't possible...
My brain is melting.
Thanks :)
You just point the domain to your ip address as you normally do. The issue you will have it that HTTP default to port 80, so either you manually add the port at the end of the host to get to the page or you setup Apache to proxy specific urls to 8080, which gets some of your Node stuff appearing to work under 80.
If you aren't using Apache for anything you can also have your Node app bind to port 80. You will probably need to setup authbind or something to give your node app permission to bind to port < 1024.

Resources