Skip to main content

How to Install MongoDB/ExpressJS/ReactJS/Node (MERN) Stack on Ubuntu 20.04 LTS

 The MERN Stack is made from four components: MongoDB, Express, React, and Node. It provides a bundle of JavaScript technologies used for building dynamic JS websites.

MongoDB is an open-source and most widely used NoSQL database system used for developing robust web applications. Express.js is a Node.js web application framework used for developing hybrid web-based applications. React.js is an open-source JavaScript framework used to create a front-end interface for mobile applications. Node.js is a JavaScript environment that allows developers to run codes on the server.

In this guide, we will show you how to install the MERN stack on Ubuntu 20.04.

First, update the system packages to the updated version by running the following command:

apt-get update -y 

Once all the packages are updated, you can proceed to the next step.

Install MongoDB Server

By default, the latest version of MongoDB is not included in the Ubuntu 20.04 default repository. So you will need to add the MongoDB repository to your system.
First, install all the required dependencies using the following command:

apt-get install gnupg2 wget curl unzip git -y

After installing all the dependencies, add the MongoDB GPG key with the following command:

wget -qO- https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -


Next, add the MongoDB repository with the following command:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Next, update the repository and install the MongoDB server using the following command:

apt-get update -y
apt-get install mongodb-org -y

 

Once MongoDB has been installed, start the MongoDB service and enable it to start at system reboot:

systemctl start mongod
systemctl enable mongod

 

Next, verify the status of the MongoDB service using the following command:

systemctl status mongod
 

You should see the following output:

? mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-23 12:21:17 UTC; 5s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 8774 (mongod)
     Memory: 58.8M
     CGroup: /system.slice/mongod.service
             ??8774 /usr/bin/mongod --config /etc/mongod.conf

Jul 23 12:21:17 ubuntu systemd[1]: Started MongoDB Database Server.
Next, verify the MongoDB installation with the following command:

mongo --eval 'db.runCommand({ connectionStatus: 1 })'

 

You should get the following output:

MongoDB shell version v4.4.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("59c89093-9e9d-413b-aafa-ae0a4ddda087") }
MongoDB server version: 4.4.7
{
    "authInfo" : {
        "authenticatedUsers" : [ ],
        "authenticatedUserRoles" : [ ]
    },
    "ok" : 1
}

 

Create MongoDB Admin User

First, connect to the MongoDB instance with the following command:

mongo
Once you are connected, change the database to admin with the following command:

> use admin
Next, create an admin user and set a password with the following command:

> db.createUser({user: "admin" , pwd: passwordPrompt() , roles: [{ role: "userAdminAnyDatabase" , db: "admin"}]})
Enter password:

You should get the following output:

Successfully added user: {
    "user" : "admin",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}

Next, exit from the MongoDB shell with the following command:

> quit()

 

Install Node.js

By default, the latest version of Node.js is not included in the Ubuntu default repository. So you will need to add the Node source repository to your system.

To add the Node source repository, run the following command:

curl -sL https://deb.nodesource.com/setup_14.x | bash -
Once the repository is added, install the Node.js with the following command:

apt-get install nodejs -y
After the installation, verify the Node.js version with the following command:

node --version
You should see the following output:

v14.17.2
You can also verify the NPM version using the following command:

npm --version
You should see the following output:

6.14.13
 

Install React.js

First, you will need to install a create-react-app tool to create a React.js application.

You can install it with the following command:

npm install -g create-react-app
After the installation, create a React.js application with the following command:

create-react-app myapp
You should see the following output:

Success! Created myapp at /root/myapp


Install Express.js

First, install the express-generator with the following command:

npm install -g express-generator
After the installation, create a new project with the following command:

express myproject
You should get the following output:

  warning: the default view engine will not be jade in future releases
  warning: use `--view=jade' or `--help' for additional options


   create : myproject/
   create : myproject/public/
   create : myproject/public/javascripts/
   create : myproject/public/images/
   create : myproject/public/stylesheets/
   create : myproject/public/stylesheets/style.css
   create : myproject/routes/
   create : myproject/routes/index.js
   create : myproject/routes/users.js
   create : myproject/views/
   create : myproject/views/error.jade
   create : myproject/views/index.jade
   create : myproject/views/layout.jade
   create : myproject/app.js
   create : myproject/package.json
   create : myproject/bin/
   create : myproject/bin/www


   change directory:
     $ cd myproject

   install dependencies:
     $ npm install

   run the app:
     $ DEBUG=myproject:* npm start
Now, change the directory to your project and install all NPM dependencies using the following command:

cd myproject
npm install

Now, start the Express web server using the following command:

npm start 0.0.0.0
Now, open your web browser and access the Express application using the URL http://your-server-ip:3000.

Comments

  1. You can solely deposit together with your debit card and the wagering requirements are set at 75x. There are many free spins offers, both as a standalone bonus or in a welcome package deal that includes a|that options 코인카지노 a} deposit bonus. Each PS1 that you deposit on your initial deposit will get you 1 free spin.

    ReplyDelete

Post a Comment

Popular posts from this blog

Cara Disable Antimalware Service Executable di Windows 10

Disadari atau tidak, Windows 10 (dan juga windows-windows lainnya) hadir dengan banyak sekali aplikasi bloatware (aplikasi yang tidak perlu-perlu amat dimiliki oleh end user). Contohnya, adalah aplikasi yang seharusnya sudah tergantikan fungsinya oleh antivirus, seperti Antimalware Service Executable . Aplikasi ini dicurigai membuat Windows 10 mengalami inefisiensi memori/RAM, memakan resource yang tinggi, dengan Load yang tinggi (tanpa limit terkadang). Nah, berikut adalah cara men-disable nya: Tekan tombol Windows + I untuk membuka apliaksi Windows Setting. Pilih icon menu Update and Security Pilih lagi menu disamping kiri Windows Security Pada jendela baru yang muncul, ada pilihan Virus & Threat protection Klik ini Lalu matikan proses Real-time protection tersebut. Dengan Regedit. Buka dialog regedit, Windows + R dan ketik ‘regedit’ Cari Folder regedit ini HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Buat sebuah DWORD baru dengan klik kanan

Setup Debian 11 Official Repository In sources.list (/etc/apt/sources.list)

When you install Debian 11 using a DVD, the OS installer sets the DVD as the source for getting packages for your system if you didn't choose to scan for network mirrors. Due to this reason, the system would ask you to insert a DVD if the disc is not present in the DVD drive when you try to install any software.  Also, the packages on DVD may not be the latest release.  So, we need to get the packages from the Internet. Media change: please insert the disc labeled 'Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04' in the drive '/media/cdrom/' and press [Enter] The /etc/apt/sources.list file with DVD as a source would look something like below. # deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb http://security.debian.org/debian-security bullseye-security

Cara Berlangganan ke Akun OnlyFans

Ada dua jenis akun di OnlyFans: akun pengguna dan akun pembuat konten. Jika Anda berlangganan akun OnlyFans, maka Anda adalah pengguna. Sementara beberapa akun pembuat OnlyFans tidak mengenakan biaya untuk melihat konten mereka, yang lain dapat mengenakan biaya bulanan $50. Dalam artikel ini, kami akan menunjukkan cara berlangganan akun OnlyFans di berbagai perangkat. Kami juga akan membahas proses berlangganan akun OnlyFans tanpa kartu kredit atau debit. Cara Berlangganan Akun OnlyFans Tanpa Menggunakan Kartu Kredit Pribadi Anda Sebagai salah satu platform paling populer di industri hiburan dewasa, OnlyFans memiliki 130 juta pelanggan dan 2 juta kreator. Meskipun ada sedikit kontroversi seputar aplikasi ini, ada akun pengguna baru yang dibuat setiap hari. Jika Anda ingin membuat akun pengguna, Anda harus melakukannya di situs OnlyFans. Ingatlah bahwa Anda harus berusia minimal 18 tahun untuk membuat akun OnlyFans.