Most MEAN teams we audit have a CI pipeline that only runs npm test on the API. The Angular build breaks on Friday, a Mongoose change ships without an integration run, and nobody notices that the lockfile drifted. This tutorial builds a GitHub Actions pipeline for a two-package MEAN repo (Angular 22 client, Express 5 API, MongoDB 8, Node 24) that is fast, cached, and catches the failures that matter. Adapt the YAML for GitLab or Azure DevOps; the structure carries over.
Repo layout
repo/
api/ # Express 5 + Mongoose 8
web/ # Angular 22
.github/workflows/ci.yml
Step 1: pin the runtime once
Put 24 in a .nvmrc at the repo root and let every job read it, so local, CI and Docker agree.
Step 2: the workflow
name: ci
on:
pull_request:
push:
branches: [main]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
api:
runs-on: ubuntu-latest
services:
mongo:
image: mongo:8.0
ports: ['27017:27017']
options: >-
--health-cmd "mongosh --quiet --eval 'db.runCommand({ping:1})'"
--health-interval 5s --health-retries 10
defaults:
run:
working-directory: api
env:
MONGODB_URI: mongodb://localhost:27017/ci
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: api/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm test
- run: npm audit --omit=dev --audit-level=high
web:
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: web/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm test -- --watch=false
- run: npm run build -- --configuration production
- uses: actions/upload-artifact@v4
with:
name: web-dist
path: web/dist
retention-days: 7
Things worth noting:
concurrencycancels superseded runs on the same branch, which saves a surprising amount of runner time.permissions: contents readfollows least privilege; grant more per job only when needed.- The MongoDB service has a health check, so tests never race a database that is still starting.
npm ci(nevernpm install) fails ifpackage.jsonand the lockfile disagree. That is the point.- The production build step catches template type errors and budget overruns that
ng testdoes not.
Step 3: contract check between the layers
A common MEAN failure is the API changing a response shape while the client still expects the old one. If you generate an OpenAPI document from the API, add a job that regenerates it and fails when it differs from the committed file:
contract:
runs-on: ubuntu-latest
needs: api
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: api/package-lock.json
- run: npm ci
working-directory: api
- run: npm run openapi:generate
working-directory: api
- run: git diff --exit-code api/openapi.json
A drift now fails the pull request instead of production.
Step 4: an end-to-end smoke test
Unit tests do not prove the two halves talk to each other. After both jobs pass, start the API against the Mongo service, serve the built client, and run a handful of Playwright checks (log in, create a record, reload and see it). Keep this suite to five to ten critical journeys; a slow flaky suite gets ignored.
Step 5: deploy only from main, with a gate
deploy:
if: github.ref == 'refs/heads/main'
needs: [api, web, contract]
runs-on: ubuntu-latest
environment: production
steps:
- run: echo "build the image, push, roll out"
Setting environment: production lets you require a manual approval in GitHub's environment settings and scope secrets to that environment only. Never expose production secrets to pull request workflows, especially from forks.
Keeping it fast
- Cache npm via
setup-node, as above, rather than hand-rolled cache keys. - Run the
apiandwebjobs in parallel; they are independent. - Fail fast on lint and typecheck before the slow tests.
- Track total pipeline time. When it passes ten minutes, developers start batching changes and risk climbs.
Checklist
- One Node version, read from
.nvmrc. npm ci, lint, typecheck and tests on both packages.- Real MongoDB 8 service, not mocks, for API tests.
- Production Angular build on every pull request.
- Contract drift check.
- Approval-gated deploy from
main.
If your pipeline is slow, flaky, or missing these gates, our team can review it as part of a MEAN Stack Testing or consulting engagement.