Project Solution: Node.js Application
Explore how to build a scalable Node.js quiz app using Docker with MongoDB and NGINX. Understand the build process, environment setup, database interactions, and client-side functionality. Gain practical skills in deploying and debugging web applications with Docker.
Node.js build process
Client-side files in the src directory are processed using npm scripts and output to a static directory. This is shared as a Docker volume so NGINX can serve HTML, CSS, and JavaScript requests without Express.js processing.
Production mode build
Production environment build scripts are defined in the package.json "scripts" section:
npm run build is executed when the Docker image is built. This processes src files using pug, PostCSS, and Rollup.js to create optimized HTML, CSS, and JavaScript files in the static directory.
Development mode watch and build
Development mode watch scripts are also defined in the package.json "scripts" section:
The watch options in the pug, PostCSS, and Rollup.js are used to monitor files and rebuild when necessary. Similarly, Nodemon watches for Node.js application file changes and restarts accordingly.
npm run debug is executed by Docker Compose. This launches concurrently, which executes all npm watch:* scripts in parallel.
Node.js Express.js application
The primary index.js application uses dotenv to parse database settings in the .env file and define environment variables:
// main application
'use strict';
// load environment
require('dotenv').config();
The ...