Skip to content

Update db.js

Update db.js #26

Workflow file for this run

name: Deploy Node.js App
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20.X'
- name: Install dependencies
run: npm i
- name: Build the app (optional)
run: npm run start # Make sure to use a valid build command if necessary
- name: Deploy to AWS EC2
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
VM_IP: ${{ secrets.VM_IP }}
SSH_USER: "ubuntu"
MONGODB_URI: ${{ secrets.MONGODB_URL }} # MongoDB URI secret
run: |
echo "$SSH_PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
# Copy application files to the EC2 instance
scp -r -o StrictHostKeyChecking=no * ubuntu@$VM_IP:/home/ubuntu/apps
# SSH into the EC2 instance and run commands to install dependencies and start the app
ssh -tt -o StrictHostKeyChecking=no ubuntu@$VM_IP << 'EOF'
cd /home/ubuntu/apps
npm install
pm2 restart igm || pm2 start server.js --name "igm" -- run start:prod
EOF