Report this

What is the reason for this report?

Remove port number from Mean.js app?

Posted on August 6, 2015

After using the one-click Mean.js deployment and adding a domain name, how does one remove the :3000 port number from the address?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

When starting the server set the port NODE_ENV=production PORT=80 node server

In order to bind a program to port 80 or any port under 1024, it needs to have root privileges. Running an app as root is usually a bad idea so what is usually done is running a reverse proxy such as nginx or HAProxy on port 80 that forwards all incoming requests to the MEAN app on port 3000.

First, install nginx:

sudo apt-get update
sudo apt-get install nginx

Then, replace the default server block in /etc/nginx/sites-available/default with the following:

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Finally, restart nginx:

sudo service nginx restart

Nginx should now be listening on port 80 and forwarding all requests to the MEAN app that is running on port 3000.

If you’re running the app in production, you will need to set it up so that it automatically starts on boot and restarts when it crashes. Take a look at the Install PM2 and Manage Application with PM2 sections in the following tutorial:

How To Set Up a Node.js Application for Production on Ubuntu 14.04

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.