Bird
Raised Fist0
Expressframework~10 mins

CI/CD pipeline for Express apps - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - CI/CD pipeline for Express apps
Code Commit to Repo
↓
Trigger CI Pipeline
↓
Run Tests
↓
Build App
↓
Deploy to Staging
↓
Run Staging Tests
↓
Deploy to Production
This flow shows how code changes trigger automated tests, build, and deployment steps for an Express app.
Execution Sample
Express
git push origin main
# triggers CI pipeline
npm test
npm run build
# deploy to staging
npm run deploy-staging
# after tests
npm run deploy-prod
This sequence pushes code, runs tests, builds the app, deploys to staging, tests again, then deploys to production.
Execution Table
StepActionResultNext Step
1Push code to main branchCode pushed successfullyTrigger CI pipeline
2Run npm testAll tests passedBuild app
3Run npm run buildBuild completedDeploy to staging
4Deploy to staging environmentStaging deployment successfulRun staging tests
5Run staging testsStaging tests passedDeploy to production
6Deploy to production environmentProduction deployment successfulPipeline complete
💡 Pipeline stops after successful production deployment
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
code_statusnot pushedpushedpushedpushedpushedpushed
test_statusnot runpassedpassedpendingpassedpassed
build_statusnot builtnot builtbuiltbuiltbuiltbuilt
deploy_staging_statusnot deployednot deployednot deployeddeployeddeployeddeployed
deploy_prod_statusnot deployednot deployednot deployednot deployednot deployeddeployed
Key Moments - 3 Insights
Why does the pipeline stop if tests fail at step 2?
Because the tests ensure code quality; failing tests (step 2) prevent build and deployment to avoid broken apps, as shown in the execution_table where only passing tests proceed.
What happens if staging tests fail after deployment?
The pipeline stops before production deployment to prevent faulty code reaching users, as the flow shows deployment to production only after staging tests pass.
Why do we deploy to staging before production?
Staging is a safe place to test the app in a production-like environment, catching issues early. The flow and variable_tracker show staging deployment and tests before final production deployment.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of step 3?
ATests passed
BBuild completed
CCode pushed successfully
DDeployment failed
💡 Hint
Check the 'Result' column for step 3 in the execution_table
At which step does the pipeline deploy to the staging environment?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look at the 'Action' column in the execution_table for deployment steps
If tests fail at step 2, what happens next?
APipeline stops and reports failure
BPipeline continues to build
CDeploys to staging anyway
DDeploys directly to production
💡 Hint
Refer to the key_moments section and execution_table logic about test failures
Concept Snapshot
CI/CD pipeline for Express apps:
- Code push triggers pipeline
- Run automated tests (stop if fail)
- Build app if tests pass
- Deploy to staging and test
- Deploy to production if staging tests pass
- Automates safe, fast delivery
Full Transcript
This visual execution shows a CI/CD pipeline for Express apps. When code is pushed to the main branch, it triggers the pipeline. First, tests run to check code quality. If tests pass, the app builds successfully. Then the app deploys to a staging environment where more tests run. If staging tests pass, the app deploys to production. If any tests fail, the pipeline stops to prevent bad code from reaching users. Variables like code status, test status, build status, and deployment status update step-by-step to track progress. This flow ensures safe, automated delivery of Express apps.

Practice

(1/5)
1. What is the main purpose of a CI/CD pipeline for an Express app?
easy
A. To automate testing and deployment when code changes
B. To write the Express app code manually
C. To create a user interface for the app
D. To store data in a database

Solution

  1. Step 1: Understand CI/CD pipeline role

    A CI/CD pipeline automates repetitive tasks like testing and deployment to save time and reduce errors.
  2. Step 2: Identify pipeline purpose for Express app

    For an Express app, the pipeline runs tests and deploys the app automatically when code changes.
  3. Final Answer:

    To automate testing and deployment when code changes -> Option A
  4. Quick Check:

    CI/CD automates testing and deployment [OK]
Hint: CI/CD means automatic test and deploy on code change [OK]
Common Mistakes:
  • Thinking CI/CD writes code
  • Confusing deployment with UI design
  • Assuming CI/CD manages databases
2. Which of the following is the correct syntax to run tests in a GitHub Actions workflow for an Express app?
easy
A. execute: npm test
B. run npm test
C. run: npm test
D. command: npm test

Solution

  1. Step 1: Review GitHub Actions syntax for commands

    In GitHub Actions, commands run under a step use the key 'run:' followed by the command string.
  2. Step 2: Identify correct command format for tests

    To run tests with npm, the correct syntax is 'run: npm test'. Other options miss the colon or use wrong keys.
  3. Final Answer:

    run: npm test -> Option C
  4. Quick Check:

    GitHub Actions uses 'run:' before commands [OK]
Hint: GitHub Actions commands start with 'run:' [OK]
Common Mistakes:
  • Omitting colon after 'run'
  • Using 'execute' or 'command' instead of 'run'
  • Writing commands without quotes or colon
3. Given this GitHub Actions step in a CI/CD pipeline for an Express app:
  - name: Install dependencies
    run: npm install
  - name: Run tests
    run: npm test

What happens if the tests fail?
medium
A. The pipeline stops and deployment does not happen
B. The pipeline ignores test failures and continues deployment
C. The pipeline retries the tests automatically
D. The pipeline skips installation and runs tests again

Solution

  1. Step 1: Understand default GitHub Actions behavior on failure

    If a step like 'npm test' fails (returns error), the pipeline stops by default and does not proceed to next steps.
  2. Step 2: Apply this to deployment step

    Since deployment usually comes after tests, if tests fail, deployment will not run to avoid deploying broken code.
  3. Final Answer:

    The pipeline stops and deployment does not happen -> Option A
  4. Quick Check:

    Failed test stops pipeline by default [OK]
Hint: Failed test stops pipeline unless configured otherwise [OK]
Common Mistakes:
  • Assuming pipeline continues after test failure
  • Thinking tests auto-retry without setup
  • Confusing install step with test step
4. You wrote this GitHub Actions workflow snippet for your Express app:
jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run npm test
      - name: Deploy
        run: npm run deploy

What is the error in this snippet?
medium
A. Wrong command 'npm run deploy' for deployment
B. Missing colon after 'run' in the Run tests step
C. Install dependencies step should use 'npm ci' instead of 'npm install'
D. Steps should be inside a job, not directly under steps

Solution

  1. Step 1: Check syntax of each step

    In GitHub Actions, each step's command must use 'run:' with a colon. The 'Run tests' step misses the colon after 'run'.
  2. Step 2: Verify other steps

    'npm run deploy' is a valid command if defined in package.json scripts. 'npm install' is acceptable.
  3. Final Answer:

    Missing colon after 'run' in the Run tests step -> Option B
  4. Quick Check:

    GitHub Actions commands need 'run:' with colon [OK]
Hint: Check colons after 'run' in each step [OK]
Common Mistakes:
  • Forgetting colon after 'run'
  • Assuming 'npm run deploy' is invalid
  • Confusing job structure with step syntax
5. You want to add a deployment step to your Express app's GitHub Actions pipeline that only runs when tests pass and on the main branch. Which is the best way to configure this?
hard
A. Put deploy step before tests to speed up pipeline
B. Add 'run: npm deploy' without conditions
C. Use 'if: failure()' to deploy only if tests fail
D. Use 'if: github.ref == "refs/heads/main" && success()' before the deploy step

Solution

  1. Step 1: Understand conditional deployment needs

    Deployment should run only on main branch and only if tests succeed to avoid deploying broken code or on wrong branches.
  2. Step 2: Use GitHub Actions condition syntax

    The 'if:' condition can check branch with 'github.ref == "refs/heads/main"' and check success with 'success()' function.
  3. Final Answer:

    Use 'if: github.ref == "refs/heads/main" && success()' before the deploy step -> Option D
  4. Quick Check:

    Conditional deploy uses 'if:' with branch and success check [OK]
Hint: Use 'if:' with branch and success() to control deploy [OK]
Common Mistakes:
  • Deploying without branch or success check
  • Deploying before tests run
  • Using failure() to deploy on test failure
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard