Prompt
I'm building a Node app and need auto deploys from GitHub
Latest observation
Oct 7, 2026
OpenAI APIWeb search: off
Here’s the simplest reliable way to get auto-deploys from GitHub for a Node app. I’ll give you a practical setup that works well on a VPS or cloud VM.
Recommended approach
Use:
- GitHub repo
- GitHub Actions to deploy on push
- A server running your Node app with either:
- PM2 to keep it running, or
- Docker if you prefer containers
Basic flow
- You push to
main - GitHub Actions runs tests/build
- It SSHes into your server
- Pulls the latest code
- Installs dependencies / builds
- Restarts the app
Option A: Deploy with SSH + PM2
1) Set up your Node app on the server
On your server:
git clone git@github.com:yourname/yourrepo.git
cd yourrepo
npm install
npm run build # if applicable
npm install -g pm2
pm2 start app.js --name my-app
pm2 save
pm2 startup
If you use npm start, then:
pm2 start npm --name my-app -- start
2) Add secrets to GitHub
In your GitHub repo go to:
Settings → Secrets and variables → Actions → New repository secret
Add:
SSH_HOST= your server IP/domainSSH_USER= server usernameSSH_KEY= private SSH keySSH_PORT=22or custom port
3) Create a GitHub Actions workflow
Create this file:
.github/workflows/deploy.yml
name: Deploy Node App
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build --if-present
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /var/www/yourrepo
git pull origin main
npm ci --omit=dev
npm run build --if-present
pm2 restart my-app --update-env
Option B: Deploy with Docker
If you already use Docker, build the image in GitHub Actions and push it to a registry (like GHCR), then pull and restart on the server.
This is better if you want:
- consistent environments
- easier rollbacks
- cleaner production setup
Good practices
- Use a production branch like
main - Add a
npm teststep before deploy - Keep environment variables in:
- GitHub Secrets
- server
.env
- Use a process manager like PM2
- Set up logs/monitoring
Important note
If your app needs:
- database migrations
- caching
- asset building
- restart on config changes
then include those in the deployment script.
Example:
git pull origin main
npm ci --omit=dev
npm run migrate
npm run build --if-present
pm2 restart my-app --update-env
If you want the easiest possible setup
Tell me which environment you’re using:
- VPS / Ubuntu server
- Docker
- Vercel / Render / Railway / Fly.io
- AWS / GCP / Azure
And I’ll give you an exact step-by-step deployment config for that platform.