A small Node/Express example web server used to demonstrate CI/CD with GitHub Actions, Docker, and deployment to Render.
- Simple Node/Express server that responds to GET / with an HTML page.
- Dockerfile to build a container image.
- Tests (Jest + Supertest) that verify the server returns 200 and contains "web server".
- GitHub Actions workflows:
.github/workflows/ci-pipeline.yml— runs on pull requests tostagingandmain(install, test, build)..github/workflows/cd-pipeline.yml— runs on pushes tostagingand on releases; builds a Docker image, pushes to Docker Hub, and triggers Render deploy hooks.
- dotenv support for environment variables.
- Name:
ci-cd-tutorial(package.json) - Author: Saqib Shah
- License: ISC
- Main entry:
index.js - Scripts:
npm start— starts the servernpm test— runs tests with Jest
- Key dependencies:
express,cors,dotenv - Dev dependencies:
jest,supertest,@jest/globals,@types/jest
- Node.js (v18 recommended)
- npm
- Docker (if using the Dockerfile)
- For CI/CD: GitHub repository secrets for Docker Hub (DOCKER_USER, DOCKER_PASSWORD) and Render deploy hooks if using the CD workflow
- Clone the repository: git clone https://github.com/SaqibShah-dev/learn-ci-cd.git
- Install dependencies: npm install
The app reads PORT from environment variables. If not set, it defaults to 5000 in code.
Start: npm start
To run on port 5001 (used in CI and the Docker setup), set the env var: PORT=5001 npm start
The server responds to: GET / — returns a small HTML page (title: "Node Js Web Server" and body containing "Hello world! I'm a Node/Express Js web server...").
Build the image: docker build -t : .
Run the container (example binding port 5001): docker run -e PORT=5001 -p 5001:5001 :
Note: The Dockerfile exposes port 5001. The app defaults to PORT=5000 unless you pass PORT at runtime or via environment.
This project uses Jest and Supertest.
Run: npm test
Tests are located in __tests__/index.test.js and check:
- GET / returns HTTP 200
- Response body contains "web server"
-
CI pipeline (
.github/workflows/ci-pipeline.yml):- Triggers on pull requests to
stagingandmain. - Steps: checkout,
npm ci,npm test, and a build step (runsnpm run build --if-present).
- Triggers on pull requests to
-
CD pipeline (
.github/workflows/cd-pipeline.yml):- Triggers on push to
staging, workflow_dispatch, and releases. - Steps: test, then build image, authenticate to Docker Hub (requires
DOCKER_USERandDOCKER_PASSWORDsecrets), push the image, and call Render deploy hooks on staging/release using repository secretsRENDER_STAGING_DEPLOY_HOOKandRENDER_PRODUCTION_DEPLOY_HOOK. - The workflow tags images using a repository
IMAGEvariable and${{ github.sha }}.
- Triggers on push to
- PORT — port the server listens on (defaults to 5000 if not set)
- The project uses
dotenv(index.jscalls config()), so you can place env vars in a.envfile during local development.
- Open issues or PRs.
- Tests should pass (
npm test) before merging. - For CI/CD changes, add/update workflows under
.github/workflows/.
ISC
Repository: https://github.com/SaqibShah-dev/learn-ci-cd Author: Saqib Shah