Help Center

React + Express + MySQL

React for the frontend, Express on Node.js for the API, and MySQL as the relational database.

This is the MERN stack variant for when data has clear relationships and a schema with referential integrity and SQL queries is preferable.

Services included

In addition to your application, the Stack brings up MySQL, an nginx that receives traffic on port 80, an automatic backups service, and the web file manager.

Project structure

text
.
β”œβ”€β”€ .docker
β”‚   └── docker-compose.yaml
β”œβ”€β”€ backend
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ config.js
β”‚   β”‚   β”œβ”€β”€ database.js
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   └── server.js
β”‚   β”œβ”€β”€ test
β”‚   β”‚   └── sample.js
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ LICENSE
β”‚   β”œβ”€β”€ healthcheck.js
β”‚   β”œβ”€β”€ package-lock.json
β”‚   └── package.json
β”œβ”€β”€ backup
β”‚   └── backup-runner.sh
β”œβ”€β”€ frontend
β”‚   β”œβ”€β”€ public
β”‚   β”‚   β”œβ”€β”€ favicon.ico
β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   β”œβ”€β”€ logo192.png
β”‚   β”‚   β”œβ”€β”€ logo512.png
β”‚   β”‚   β”œβ”€β”€ manifest.json
β”‚   β”‚   └── robots.txt
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ App.css
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   β”œβ”€β”€ App.test.js
β”‚   β”‚   β”œβ”€β”€ index.css
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ logo.svg
β”‚   β”‚   β”œβ”€β”€ serviceWorker.js
β”‚   β”‚   β”œβ”€β”€ setupProxy.js
β”‚   β”‚   └── setupTests.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-mysql
cd /root/stack/javascript/react-express-mysql
docker compose up -d

Then replace the example application with yours, from Git, via 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.
DB_NAME example Database name.
DB_USER root Database user.
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 retained.
MARIADB_VERSION 10.6.4-focal Version of the corresponding image.

After changing it, apply the changes with docker compose up -d.

Useful commands

bash
docker compose ps          # see running containers
docker compose logs -f     # view live logs
docker compose restart     # restart services
docker compose down        # stop and remove containers
Guide g.0296 Β· Source version 1 Β· en