-
Create New Backend Project
- Begin by creating a new backend project.
- Add simple routes to your project.
- Push the project to GitHub.
-
Create and Setup New Virtual Machine (VM)
- Set up a new VM for your project.
-
SSH Login to VM
- Use the standard username and password to SSH into your VM. For instance:
ssh root@123.123.123.123
- Use the standard username and password to SSH into your VM. For instance:
-
Run Ubuntu Update
- Update Ubuntu using the following commands:
sudo apt update && sudo apt upgrade
- Update Ubuntu using the following commands:
-
Install Node.js
- Install Node.js using the following commands:
cd ~ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash sudo apt install nodejs -y
- Install Node.js using the following commands:
-
Clone Repository to VM and Install Dependencies
- Clone your GitHub repository to the VM.
- Run
npm install
to install project dependencies.
-
Configure GitHub Actions
- Navigate to your repository on GitHub.
- Go to the Actions tab.
- Choose Node.js.
- Write the workflow, referring to
.github/workflows/node.js.yml
for guidance.
-
Setup Environment Variables
- Navigate to Settings.
- Go to Secrets and variables, then Actions.
- Click New repository secret.
- Create three variables: HOST, PASSWORD, and USERNAME, using details from your VM.
- Re-run the workflow.
-
Install PM2 and Start Application
- Log in to your VM via SSH.
- Install PM2 globally using
npm install pm2 -g
. - Navigate to your project folder.
- Start your application with the following command:
pm2 start index.js --watch
-
Add More Routes and Monitor
- Experiment by adding more routes to your application.
- Optionally, run
pm2 monit
to monitor the processes.
-
Customize Port (Optional)
- If you wish to run the app on a custom port, install
ufw
. - Allow the custom port using
ufw
. - and setup nginx for reverse proxy
- If you wish to run the app on a custom port, install
Follow these steps to set up your backend project efficiently, ensuring smooth development and deployment processes.