Help Center

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

text
.
β”œβ”€β”€ 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:

bash
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:

bash
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

bash
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
Guide g.0295 Β· Source version 1 Β· en