Project Solution: An Overview
Let’s take a bird’s eye view of the project’s solution.
Solution overview
An overview of the solution is provided below. More details will be discussed in the coming lessons.
MongoDB database (mongodb
container)
This container should use a Docker volume (quizdata
) for question storage and expose the database on port 27017
. Create a collection named quiz
in the quiz
database that is accessed with the user ID quizuser
and password quizpass
.
Node.js application (nodejs
container)
The Node.js container has two functions:
-
index.js
should launch an Express.js application exposed on port8000
, which:-
Fetches questions and answers from the Open Trivia Database API on start-up. These should be formatted and stored in the MongoDB database.
-
Provides a single
/question
endpoint. This should query the database and return the details of the next question as JSON-encoded data.
During development, any changes to the Node.js files trigger an application restart using Nodemon.
-
-
Client-side HTML, CSS, and JavaScript implement the application logic to fetch questions and keep score. Source code contained in the
src
directory is built using npm scripts, which run pug, PostCSS, and Rollup.js. The resulting files are output to astatic
directory (a shared Docker volume).In production, this processing occurs when the Docker image is built. During development, changes to
src
files in the host’s project directory trigger astatic
file rebuild and source maps are appended.
NGINX reverse proxy (nginx
container)
An NGINX web server container serves files from the shared static
volume. This is more efficient than serving via Express.js.
Other HTTP requests (such as the /question
endpoint) are forwarded to the nodejs
container. NGINX acts as a reverse proxy.
Project file structure
The project root directory contains:
Get hands-on with 1400+ tech skills courses.