Skip to content

Instantly share code, notes, and snippets.

@Chinmay1743
Last active April 15, 2024 08:10
Show Gist options
  • Save Chinmay1743/414fd509484564a886c30da2406532ab to your computer and use it in GitHub Desktop.
Save Chinmay1743/414fd509484564a886c30da2406532ab to your computer and use it in GitHub Desktop.
setup-mern-stack.md

Purge existing packages installed via package manager

sudo apt purge nodejs npm mongodb; sudo apt autoremove;

Install Node (original source: https://github.com/nodejs/help/wiki/Installation):

Download NodeJs from website: https://nodejs.org/dist/v20.12.2/node-v20.12.2-linux-x64.tar.xz

Edit version number below and keep it same as your downloaded file name. The snippet also exports path:

VERSION=v20.12.2
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
. ~/.profile

Above snippet modifies also PATH. Those who wish to create a symlink instead can follow this:

VERSION=v20.12.2
DISTRO=linux-x64
sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npm /usr/bin/npm
sudo ln -s /usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin/npx /usr/bin/npx

Check if installed components output normally:

node -v
npm
npx -v


Install packages via npm

npm install express cors dotenv mongoose

  • Express:
  • cors:
  • dotenv:
  • mongoose:

text


Install MongoDB

Import the MongoDB public GPG key

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor

Create a List file for your version of Ubuntu. You can run neofetch to find which version of ubuntu you are currently running:

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Update Repository:

sudo apt update

Install MongoDB:

sudo apt install -y mongodb-org

Run MongoDB:

sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod

You can connect to mongoDB port using command mongosh. Default port and url is localhost and 27017 respectively.


Install MongoDB Compass to interact with database through GUI

Download .deb file from here: https://www.mongodb.com/try/download/compass Go to downloads folder, open terminal there and type:

sudo apt install ./mongodb-compass*.deb


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment