Skip to main content
Learn how to run and test the Solar System Node.js application locally before integrating it into a GitLab CI/CD pipeline. The source code is hosted on GitLab.
The image shows a GitLab repository page for a project named "Solar-System," displaying the project files and their last commit details. The interface includes options for managing, planning, and deploying the project.

Prerequisites

  • Node.js and npm
  • A running MongoDB instance or Atlas cluster
  • Git installed on your machine
To verify Node.js and npm:

Clone the Repository

Project Structure and Key Files

This repository includes:
  • package.json: Defines metadata, scripts, dependencies, and coverage thresholds
  • app.js: Backend Express.js server
  • client.js: Frontend script to fetch planet data
  • Dockerfile: Build instructions for a Docker image
  • deployment.yaml & service.yaml: Kubernetes manifests

package.json

Application Backend (app.js)

Ensure you add your REST API route handlers in app.js (for example, a GET /os endpoint) before testing.

Frontend Controller (client.js)

Dockerfile

Kubernetes Manifests

Install Dependencies

You may see notices:

Running the Server Locally

After dependencies are installed:
Open http://localhost:3000 in your browser:
The image shows a digital illustration of the solar system with planets orbiting the sun, accompanied by a user interface for searching planets. The background is a starry space theme with text describing the solar system.
You can search by ID (e.g., 3 for Earth, 6 for Saturn). Data is fetched from your MongoDB.
The image shows a webpage about the solar system, specifically focusing on Saturn, with a stylized illustration of the planet and its rings on a starry background. There is a description of Saturn and a search feature for exploring planets.

Testing the Application

Run the test suite:
If environment variables are missing, you will see:
Tests will fail without MONGO_URI, MONGO_USERNAME, and MONGO_PASSWORD. Set these before running npm test.

Temporary Local Credentials

For a quick local demo, hard-code your MongoDB URI in app.js:
Re-run tests:
A test_results.xml file is generated for CI/CD:

Coverage Report

Generate coverage:
A non-zero exit code will signal coverage failures in CI pipelines.

Watch Video