A CI/CD pipeline helps you automatically test and deliver your Express app updates quickly and safely.
CI/CD pipeline for Express apps
name: Express CI/CD Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npm test
- run: npm run build
- name: Deploy
run: |
echo "Deploy commands here"This example uses GitHub Actions syntax for a CI/CD pipeline.
Replace npm run build and deploy commands with your app's specific commands.
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm teston:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm run build
- run: scp -r ./dist user@server:/var/www/appThis pipeline runs on pushes to the main branch. It installs dependencies, runs tests, builds the app, then copies files to a server and restarts the app process.
name: Express CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build app
run: npm run build
- name: Deploy to server
run: |
scp -r ./dist user@yourserver.com:/var/www/express-app
ssh user@yourserver.com 'pm2 restart express-app'
Make sure your server allows SSH access and you have keys set up for deployment.
Use environment variables to keep secrets like server user and IP safe.
Test your pipeline with a small change before relying on it fully.
A CI/CD pipeline automates testing and deployment for your Express app.
It saves time and reduces errors by running steps automatically on code changes.
Use tools like GitHub Actions to create simple pipelines with steps for install, test, build, and deploy.