React + Express + MongoDB
The classic MERN stack: React for the frontend, Express on Node.js for the API and MongoDB as the document database.
Itβs the right combination when the data model is flexible or changes often, because MongoDB doesnβt enforce a fixed schema and stores documents similar to the objects you already handle in JavaScript.
Included services
Besides your application, the Stack brings up MongoDB, an nginx that receives traffic on port 80, an automatic backups service and the web file manager.
Project structure
.
βββ backend
β βββ config
β β βββ config.js
β β βββ config.json
β β βββ messages.js
β βββ db
β β βββ index.js
β βββ logs
β β βββ .gitkeep
β βββ models
β β βββ ...
β βββ routes
β β βββ index.js
β βββ utils
β β βββ ...
β βββ Dockerfile
β βββ package-lock.json
β βββ package.json
β βββ server.js
βββ backup
β βββ backup-runner.sh
βββ frontend
β βββ public
β β βββ favicon.ico
β β βββ index.html
β β βββ logo192.png
β β βββ logo512.png
β β βββ manifest.json
β β βββ robots.txt
β βββ src
β β βββ ...
β β βββ App.js
β β βββ App.scss
β β βββ App.test.js
β β βββ custom.scss
β β βββ index.css
β β βββ index.js
β β βββ logo.svg
β β βββ serviceWorker.js
β βββ Dockerfile
β βββ package-lock.json
β βββ package.json
βββ nginx
β βββ default.conf
βββ .env.example
βββ compose.yaml
Getting started
Install the Stack and bring it up:
docker-deploy-stack --stack javascript/react-express-mongodb
cd /root/stack/javascript/react-express-mongodb
docker compose up -d
Then replace the example application with yours, from Git, by SFTP or from the web file manager, following how-do-i-deploy-an-application-on-a-stack.md. Your code goes in the app/ folder.
Each time you update the code, apply the changes:
docker compose up -d --build
Configuration
Editable values are in the Stackβs .env file:
| Variable | Default | Purpose |
|---|---|---|
APP_ENV |
development |
Application environment. |
BACKUP_ENABLED |
1 |
Automatic backups: 1 enabled, 0 disabled. |
BACKUP_INTERVAL_SECONDS |
86400 |
How many seconds between backups. |
BACKUP_RETENTION_DAYS |
7 |
How many days backups are kept. |
MONGO_VERSION |
4.2.0 |
Version of the corresponding image. |
After changing it, apply changes with docker compose up -d.
Useful commands
docker compose ps # view running containers
docker compose logs -f # view live logs
docker compose restart # restart the services
docker compose down # stop and remove the containers