Introduction to MEAN Stack
This article will take you through the installation of MEAN stack on your Linux virtual server based on CentOS 7.
MEAN is a JavaScript software stack that contains Node.JS, Angular.JS, and Express.JS. It uses MongoDB as the default database. In order to install the stack, it is necessary to have root permissions. However, if you do not have the root permissions, ensure that your commands start with “sudo”.
Getting Started
The first step is setting up your Machine for the installation. Before any installation begins, ensure that your machine has the following
- Git. Confirm that you have GIT installed in your system. To confirm the installation run the command
# git --version
on the terminal. - Ensure that dependencies are installed. Run the following commands
# gem install sass
# yum install gcc-c++ make git fontconfig bzip2 libpng-devel ruby ruby-devel
Installing MongoDB
Special Note: Consult with Hostadvice’s Best MongoDB hosting page to find the top MongoDB hosting services. .
.MongoDB is a NoSQL database system that saves data in JSON format thereby supporting server-side JavaScript execution. Since it is not listed on the official CentOS repository, we will need to create one to download the latest stable version. Type the following to create a new file with your text editor
# nano /etc/yum.repos.d/mongodb.repo
This will open a new text file. Paste the following code and save it, then exit the editor.
[mongodb-org-3.6] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
Install MongoDB by running the following command:
# yum install mongodb-org
Once the installation is complete, start and enable the database service with the following commands:
# systemctl start mongod #systemctl enable mongod
To verify that the service is running, run the following command
# systemctl status mongod
Installing Node JS.
Special Note: Consult with Hostadvice’s Best Node.js hosting page to find the top Node.js hosting services.
Node JS is a JavaScript execution environment that acts as a server-side. Installing Node.js is done by adding the repository of a stable branch. This is done by running this command:
# curl -sL https://rpm.nodesource.com/setup_9.x | bash
The next step is installing Node JS and NPM
# yum install -y nodejs
Check whether the installation was successful by running
# npm version # node version
Installing Bower and Gulp
These are components of the mean stack. Bower is a package manager for the front-end apps, while gulp automates tasks. The installation of both must be global so that they are available system-wide.
Run the following command to install bower and gulp respectively.
# npm install -g bower # npm install -g gulp
Verify the installation was successful by running these commands
# npm list -g --depth=0
This should yield the following
/usr/lib
├── bower@1.8.4
├── gulp@4.0.0
└── npm@5.8.0
Installing MEAN
Now that are the prerequisite installations are done, it is time to install Mean boilerplate. This is done by cloning it from github.
# git clone https://github.com/meanjs/mean.git
With the boilerplate on your home directory, you need to install the project references by accessing the directory. Run;
# cd mean
To install mean run:
# npm install
This might take a few minutes but once install front-end resources by typing;
# bower install --allow-root
Running the First Application
To start MEAN stack project, use the commands below:
# npm start
At first you might experience the following error
Error output
[12:56:49] ‘lint’ errored after 702 ms
[12:56:49] Error in plugin ‘run-sequence’
Message:
An error occurred in task ‘sass’
Correct the errors by running these commands:
# rm -rf node_modules # npm cache clean # npm install # npm start
To access the MEAN application, type the link below on your browser:
http://your_server_ip:3000
It should yield a page like the one below.
You can start building and deploying your applications.
Check out the top 3 Dedicated server hosting services:
- Get answer to all of your queries about best VPS hosting by clicking here.