Remove port number from Mean.js app?

Posted August 6, 2015 12.3k views

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

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.

Submit an Answer
2 answers

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;


    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

by Mitchell Anicas
Node.js is an open source Javascript runtime environment for easily building server-side and networking applications. The platform runs on Linux, OS X, FreeBSD, and Windows, and its applications are written in JavaScript. Node.js applications can be run at the command line but we will...

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