0
0
Expressframework~30 mins

CI/CD pipeline for Express apps - Mini Project: Build & Apply

Choose your learning style9 modes available
CI/CD Pipeline for Express Apps
📖 Scenario: You are a developer working on a simple Express.js web application. You want to automate the process of testing and deploying your app whenever you make changes. This project will guide you through setting up a basic Continuous Integration and Continuous Deployment (CI/CD) pipeline using GitHub Actions.
🎯 Goal: Build a CI/CD pipeline that automatically installs dependencies, runs tests, and deploys the Express app when code is pushed to the main branch.
📋 What You'll Learn
Create a basic Express.js app with a test script
Add a GitHub Actions workflow configuration file
Configure the workflow to install dependencies and run tests
Add a deployment step that runs only on the main branch
💡 Why This Matters
🌍 Real World
Automating testing and deployment saves time and reduces errors when updating web applications.
💼 Career
CI/CD pipelines are essential skills for developers and DevOps engineers to ensure reliable software delivery.
Progress0 / 4 steps
1
Create a basic Express app with a test script
Create a file called app.js with a simple Express server that listens on port 3000 and responds with "Hello World" at the root URL. Also, create a package.json file with a test script that runs echo \"Test passed!\".
Express
Need a hint?

Use express() to create the app and app.get('/', ...) to handle the root route. The test script in package.json should just echo a success message.

2
Add GitHub Actions workflow file
Create a file called .github/workflows/nodejs.yml with a workflow that triggers on push events to any branch. Define a job called build that runs on ubuntu-latest.
Express
Need a hint?

The workflow file should start with name and on: [push]. Define a job named build that runs on ubuntu-latest.

3
Configure workflow to install dependencies and run tests
In the build job of nodejs.yml, add steps to check out the code, set up Node.js version 18, install dependencies with npm install, and run tests with npm test.
Express
Need a hint?

Use actions/checkout@v3 to get the code, actions/setup-node@v3 with node-version: '18' to set Node.js, then run npm install and npm test.

4
Add deployment step for main branch
In the build job of nodejs.yml, add a step that runs only when the branch is main. This step should print Deploying app... using echo command.
Express
Need a hint?

Add a step with name: Deploy and use if: github.ref == 'refs/heads/main' to run only on main branch. The command should be echo "Deploying app...".