- shivani singh
- January 19, 2022
Steps to Setup & Configure MEAN Stack on Ubuntu 20.04 LTS
Hello, here we are discussing about for MEAN Stack. MEAN Stack is a free,open-source & JavaScript application. MEAN stands for MongoDB, Express, Angular & Node.js. It is used for developing back end & front end application. MongoDB,Express & Node.js are used for back end development & Angular is used for front end development.
There are some steps to setup MEAN Stack on Ubuntu:
Prerequisitcs:
- Ubuntu 20.04 with sudo privileges.
Step 1: Update the system.
apt-get update
Step 2: Install MongoDB on system.
apt install mongodb
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# apt install mongodb
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5 libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.6
mongo-tools mongodb-clients mongodb-server mongodb-server-core
The following NEW packages will be installed:
libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-program-options1.71.0 libgoogle-perftools4 libpcrecpp0v5 libsnappy1v5 libtcmalloc-minimal4 libyaml-cpp0.6
mongo-tools mongodb mongodb-clients mongodb-server mongodb-server-core
0 upgraded, 13 newly installed, 0 to remove and 32 not upgraded.
Need to get 56.8 MB of archives.
After this operation, 234 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
- Start and enable MongoDB.
systemctl start mongodb
systemctl enable mongodb
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# systemctl start mongodb
root@ip-172-31-38-118:/home/ubuntu# systemctl enable mongodb
Synchronizing state of mongodb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mongodb
Step 3: Install Node.JS and Dependencies on system.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
## Installing the NodeSource Node.js 14.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
## Confirming "focal" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_14.x/dists/focal/Release'
## Adding the NodeSource signing key to your keyring...
.....
- Run the following commands:
apt install nodejs gcc g++ make git
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# apt install nodejs gcc g++ make git
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version (1:2.25.1-1ubuntu3.2).
git set to manually installed.
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 g++-9 gcc-9 gcc-9-base libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev
libctf-nobfd0 libctf0 libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-9-locales g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib glibc-doc
libstdc++-9-doc make-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 g++ g++-9 gcc gcc-9 gcc-9-base libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev
libctf-nobfd0 libctf0 libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev nodejs
0 upgraded, 33 newly installed, 0 to remove and 32 not upgraded.
Need to get 67.0 MB of archives.
After this operation, 306 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
- Install yarn and gulp.
npm install -g yarn
&&
npm install -g gulp
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# npm install -g yarn
> [email protected] preinstall /usr/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
/usr/bin/yarn -> /usr/lib/node_modules/yarn/bin/yarn.js
/usr/bin/yarnpkg -> /usr/lib/node_modules/yarn/bin/yarn.js
+ [email protected]
added 1 package in 0.704s
root@ip-172-31-38-118:/home/ubuntu# npm install -g gulp
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/gulp/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ [email protected]
added 324 packages from 220 contributors in 17.953s
Step 4: Download the MEAN Stack using Git.
git clone https://github.com/meanjs/mean
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# git clone https://github.com/meanjs/mean
Cloning into 'mean'...
remote: Enumerating objects: 10869, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 10869 (delta 63), reused 40 (delta 27), pack-reused 10777
Receiving objects: 100% (10869/10869), 4.84 MiB | 24.42 MiB/s, done.
Resolving deltas: 100% (5564/5564), done.
- Change the directory.
cd mean
- Install dependencies.
yarn install
- Here is the command output.
root@ip-172-31-38-118:/home/ubuntu# cd mean
root@ip-172-31-38-118:/home/ubuntu/mean# yarn install
yarn install v1.22.17
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/5] Validating package.json...
[2/5] Resolving packages...
warning acl > mongodb > mongodb-core > [email protected]: Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details
warning aws-sdk > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning aws-sdk > url > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning aws-sdk > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning gulp > glob-watcher > [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning gulp > glob-watcher > chokidar > [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning gulp > glob-watcher > anymatch > micromatch > snapdragon > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
warning gulp > glob-watcher > anymatch > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning gulp > glob-watcher > anymatch > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated
warning gulp > glob-watcher > anymatch > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
warning gulp-angular-templatecache > [email protected]: Security vulnerability surrounding event-stream, do *NOT* use.
warning gulp-angular-templatecache > [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
warning gulp-angular-templatecache > gulp-footer > [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
Step 5: Open server.js file for testing.
vim server.js
- Add the following lines:
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const app = express();
app.use('/', (req, res) => {
MongoClient.connect("mongodb://localhost:27017/test", function(err, db){
db.collection('Example', function(err, collection){
collection.insert({ pageHits: 'pageHits' });
db.collection('Example').count(function(err, count){
if(err) throw err;
res.status(200).send('Page Hits: ' + Math.floor(count/2));
});
});
});
});
app.listen(3000);
console.log('Server running at http://localhost:3000/');
module.exports = app;
- Start the server.
gulp
Step 6: Open Web Page using the following URL.
http://server-ip:3000
- Here is the output.
- Here we can see Number of Page Hits.
- Refresh the Page & it will be increasing the number of Page hits.This verifies the MEAN stack is working properly.