Install a MEAN (MongoDB, Express JS, Angular JS, Node JS) Stack

Spread the love

We have used Centos 7.5 64bit to install the stack.

So, follow below steps as root user:

yum -y update

yum -y install epel-release

yum -y update

yum -y install node

NPM may not be installed try below command:

yum -y install npm

mkdir /home/web

cd /home/web
npm install express –save

vi /etc/yum.repos.d/mongodb-org-4.0.repo

Insert following in your editor by pressing ‘i’

name=MongoDB Repository

and save by pressing ‘ESC’ and then ‘:x’

yum install -y mongodb-org

sudo service mongod start

sudo chkconfig mongod on

Above steps of Mongo DB may be updated. Please go on the official site.

npm init

When you run the ‘npm init’ command the command line will ask you some questions to create a package.json file.

Mine looked like this (Of-course IP is not mine)

"name": "",
"version": "1.0.0",
"description": "chnoli",
"main": "index.js",
"scripts": {
"test": "node index.js"
"author": "Abnon",
"license": "ISC",
"dependencies": {
"express": "^4.16.3"

Create a server by writing following code in ‘index.js’

var http = require('http')

res.writeHead(200,'Content-Type: text/html')


Now install pm2 to run the node server permanently.

npm install pm2 -g

pm2 start index.js

To list and stop the JS running as daemon by pm2

pm2 list

pm2 index

Index will be shown when list command will be fired.

If problem occurs in connection with MongoDB then edit the file ‘/etc/selinux/config’ and change the line


with SELINUX=disabled

If already SELINUX have disabled value then there is some other error.

Your have to store your all files in ‘/home/web/’ directory as per the above installation procedure.

Alternatively you can download Shell Script file : Download Shell Script File. And use it to install all the required components (For CentOS 7).

To run this script use below command in shell


and After reboot cd to ‘/home/web’ and run command ‘pm2 start index.js’

TIP: For easy manipulation of records use Mongoose for node js.