DEV Community

Discussion on: Explain me this like I'm five

Collapse
 
sroehrl profile image
neoan

Servers are responding to external requests. The ports you want to focus on are 80 (http) and 443 (https). NodeJS servers (like express) usually use ports beyond 1024 due to permissions, most commonly 3000 or 8080.

Now, in production, you will need to serve over http(s) for a browser to reach your app. While you have multiple options to achieve that, using Apache or Nginx is a good option as you probably also want to serve static files and assets.

I will make the following assumptions:

  • you are using a linux system in production
  • your app runs on port 3000

Your Nginx config could then look like this:

server {
    listen 443;
    server_name your_app.com;
    client_max_body_size 50M;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location /static {
        root /var/www/your_app;
    }

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

NOTE: be aware that you will need to look into an ssl certificate as well to serve over 443. "certbot" is what you want to google for!

Collapse
 
kevinhch profile image
Kevin

Thanks for your answer, I will save this config :D