Skip to main content
In this guide, we’ll walk through running and testing a Solar System Node.js application on your local (or virtual) machine. We’ll cover:
  • Cloning the repository
  • Inspecting package.json
  • Reviewing application code (app.js, controllers, client)
  • Executing unit tests and enforcing coverage
  • Containerizing with Docker
  • Exploring OpenAPI specs
  • Running the app and demoing endpoints
  • Automating everything with Jenkins pipelines

Prerequisites

Ensure you have these versions installed:
Install project dependencies:
Run a quick test:

Repository Overview

The Solar System app uses:
  • Express for the REST API
  • Mongoose for MongoDB integration
  • Mocha & Chai for testing
  • nyc for code coverage
  • serverless-http for AWS Lambda support
The image shows a GitHub repository page for a project titled "Solar System NodeJS Application," featuring a list of files and their commit history. The repository primarily uses JavaScript, HTML, and Dockerfile.

Project Structure

1. Clone the Repository

2. Inspect package.json

Open package.json to review scripts and dependencies:
Key points:
  • test runs Mocha with JUnit output.
  • coverage enforces ≥ 90% line coverage via nyc.
  • serverless-http enables AWS Lambda compatibility.

3. Application Entry Point (app.js)

This file initializes Express, connects to MongoDB, and exports the app for tests and serverless:

4. Controller & Routes (app.controller.js)

Define the Mongoose schema and API endpoints:

5. Frontend Logic (client.js)

Fetch and display the hostname from /os:

6. Unit Tests (app-test.js)

Validate endpoints with Mocha, Chai, and chai-http:

7. Dockerfile

Build an Alpine-based Node.js container:

8. OpenAPI Spec (openapi.yaml)

Define three endpoints for probes and host info:

9. Run Locally

  1. Install dependencies:
  2. Export MongoDB credentials or hard-code for quick tests:
If MONGO_URI isn’t set, npm test will fail. Use:
  1. Run tests and coverage:
  2. Add a listener in app.js to start the server:
  3. Start the application:

10. Explore in Browser

Navigate to http://<VM-IP>:3000 to view and search planets:
The image shows a stylized representation of the solar system with planets orbiting the sun, accompanied by a search interface for exploring the planets.
Search for ID “3” (Earth):
The image shows a stylized depiction of Earth with a description about the planet, set against a space-themed background. It includes a "Solar System" header and a search feature for planets.
Test the JSON endpoints:

In the next lesson, we’ll automate cloning, building, testing, coverage enforcement, and deployment with Jenkins pipelines.

Watch Video