First thing we need to do is to install nodejs, you can find the installation steps and archives from the official website here. It is recommended to use the LTS version of node to avoid any kind of interruptions.
- Install
curl
sudo apt update
sudo apt upgrade
sudo apt install curl
- Get
nodejs
PPA Switch to root directory
cd ~
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
- Run the script under sudo:
sudo bash nodesource_setup.sh
- Install nodejs
sudo apt install nodejs
- In order for some npm packages to work (those that require compiling code from source, for example), you will need to install the build-essential package:
sudo apt install build-essential
-
Get the installation package or archive from the official website here
-
If you have downloaded the ubuntu-archive, then you might set the path. Open up your terminal and edit
.bashrc
file and add the below line at the end of the file.
gedit .bashrc
Note: .bashrc will be located at your home directory
- The above command will open up text-editor with
.bashrc
file, add the following line by replacing the path with path of yournodejs
installation directory.
export PATH=<NODEJS-INSTALLATION-PATH>/bin:$PATH
Ex:
export PATH=/usr/local/node-v12.16.2-linux-x64/bin:$PATH
In case you face any issues, refer official docs
a. Import the public key used by the package management system.
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
b. Create a list file for MongoDB
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
c. Reload local package database.
sudo apt-get update
d. Install the MongoDB packages
sudo apt-get install -y mongodb-org
e. Optional. Although you can specify any available version of MongoDB
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
a. Create a directory to store data
sudo mkdir /data
sudo mkdir /data/db
b. Grant required permissions
sudo chown -R `id -un` /data/db
# start mongodb service
sudo service mongod start
# Check status of the service
sudo service mongod status
sudo mongod
The above command will start a MongoDB
instance running on your local machine. I will pick a port to run the database, possibly it will be 27017
, so your db will be hosted at
mongodb://localhost:27017/
Here you can execute your db queries. Initialize the shell by following command
mongo
- Install the required dependencies by the following command
npm install
- Setup public & private keys for
Access
andRefresh
tokens Open your terminal and type the below commands to create secure private key and extracting public key from the private key.
Creating private key for access token
openssl genrsa -out private.pem 2048
Expected output:
Generating RSA private key, 2048 bit long modulus (2 primes)
....................................................+++++
.+++++
Extracting public key for access token
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Expected output:
writing RSA key
Creating private key for refresh token
openssl genrsa -out privater.pem 2048
Expected output:
Generating RSA private key, 2048 bit long modulus (2 primes)
....................................................+++++
.+++++
Extracting public key for refresh token
openssl rsa -in privater.pem -outform PEM -pubout -out publicr.pem
Expected output:
writing RSA key
and place these 4 files inside keys
directory in root of the project
For more info on openssl, click here
- Setup environment variables
Rename the
.env.example
as.env
and fill up your details there.
Create an account at SendGrid SendGrid.
Create a new API Key here
Verify a sender email and use that email in the .env
file, to verify click here
- Place your application's Database credentials inside the
.env
file, then inside theconfig.js
file, setup db-names just liketodo-test, todo-dev, todo-prod
.
Refer below config as example:
const prod = {
name: 'prod', // name of the environment
app: {
port: process.env.PORT || 9000 // this will be the port where app will listen
},
db: {
name: 'todo', // db name
host: process.env.DB_HOST, // db host
port: process.env.DB_PORT, // db port, in case you are running in localhost, default port will be: 27017
username: process.env.DB_USERNAME, // db username
password: process.env.DB_PASSWORD // db password
}
};
- Run the project with nodemon
npm run dev
or Run as normal project
npm start