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’

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

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": "18.108.034.119",
"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')

http.createServer(function(req,res){
res.writeHead(200,'Content-Type: text/html')
res.end("HI")

}).listen(80)

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

SELINUX=enforcing

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).

https://downloads.faltutech.com/MEAN.sh

To run this script use below command in shell

bash MEAN.sh

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.