Setting up the MEAN stack

Setting up a development and production web server using MEAN stack....

4 months ago

Latest Post Wàn 萬 by Arsalan Lavang

So you want to build a website, and you want to use the MEAN stack, but there's a problem: you don't know how to get it to production.  This outline will guide you on how to setup a web server that will run your MEAN code securely.  We won't get into  much coding (there are already many courses on the topic), rather we'll get things ready for it and get the worry of serving content out of the way.


  1. Server prep
  2. MEAN stack
  3. Serving traffic on port 80/443
  4. Testing services

1 - Server Prep

There are many ways of setting up your server architecture, depending on your needs you may want your database to be on a seperate system, or have multiple front-end servers behind a load balancer.  However, for the purpose of this outline, we will use a single server setup, and show you how to get things ready.

We'll be using Ubuntu, but it's a similar process for other distributions of Linux.

Creating MEANapp user

You will want to create a user for your app, so that you're not running your code as root.

Securing Ports

It is recommended that you secure ports on your server so that only access to certain services are available.  Namely ports 22, 80, and 443 should be open.  There are several ways of doing this, but it involves using a firewall like ufw on the server or a network one provided by your service provider.

Get Started

sudo apt-get update
sudo apt-get install git
sudo apt-get install build-essential

2 - MEAN Stack

Installing MongoDB

MongoDB can be installed with a simple command, like the one bellow, but if you want the latest for your version of Ubuntu, follow this link.

sudo apt-get install -y mongodb

check that it is running and its version:

sudo systemctl status mongodb
mongo --eval 'db.runCommand({ connectionStatus: 1 }

Installing Node

curl -sL | bash -
sudo apt-get install nodejs

Installing NPM

sudo apt-get install npm

Installing Angular

sudo npm install -g @angular/cli

3 - Serving Traffic on port 80/443



4 - Testing services

Arsalan Lavang

Published 4 months ago

Subscribe to our newsletter

Recieve news directly to your email. © 2019.