I have a NodeJS application(NestJS Framework) which I am deploying on the Digital Ocean droplet using GitHub Actions.
On the droplet, I have already cloned the app, deployed it and started it with pm2 to make sure it works correctly without Github actions and it does, I can call the APIs using the droplet IP with port right now(Nginx is not set up yet)
I am a bit new to GitHub actions and now the part remains as to how I can every time I push to main, I want to update my application code with the main branch and refresh the pm2 app.
deploy.yml file
name: Varisht Prod Deployment
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: SSH into Droplet and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd varisht-backend
git pull origin main
npm install
npm run build
pm2 restart varisht-prod
So to explain a bit here as per my understanding:
- As all the steps need to happen in the droplet and not any local machine, I first do SSH to the droplet using
appleboy/ssh-action@master - I have correctly set the secrets where my DROPLET_IP is the IP address of the droplet, SSH_USERNAME is the
rootand SSH_PRIVATE_KEY is the private key. - After that, in the script I do all the necessary step required to deploy and update the app.
- Also, I am not setting the Nodejs setup, as it's already there in the droplet(below SS) along with the path.
- I have
workflow_dispatchso I can run the script from Git.
Now when I am running the deployment, it fails, and I get the below error. What am i missing here, npm should be there as NodeJS is already installed on the droplet. How I can debug this? Thanks!

