Skip to the content.

CI Testing code style: prettier license

mern-logo

MERN Stack with Docker

MongoDB - Express - React - Redux - React Native - NodeJS

MERN stack is intended to provide a starting point for building full-stack JavaScript applications, including dynamic web and mobile apps. The stack is made of MongoDB, Express, React, Redux, React Native and NodeJS.

mern-workflow

Demo

Project Breakdown

1. API Server

NOTE: The full API documentation can be found here

2. React Client

3. React Native - Mobile

4. Nginx Proxy

5. CI and CD

Getting started

1. Clone the mern-stack repository

If you want to use Expo for developing mobile app, please check out the expo branch and see instructions here

git clone https://github.com/t-ho/mern-stack.git
cd mern-stack
cp .env.example .env
cp client/.env.example client/.env
cp mobile/.env.example mobile/.env
# Edit all three .env files to meet your requirements

2. Install package dependencies

In the root directory, run:

yarn install

3. Start development servers

To start server, client, and mobile, run:

# In the root directory (mern):
yarn start
# Server API is running at http://localhost:SERVER_PORT (http://localhost:8861 by default)
# Web client is running at http://localhost:PORT (http://localhost:3000 by default)
# Mobile - Expo DevTools is running at http://localhost:19002

NOTE:

To restart yarn process (If you don’t start the mobile development process, ignore this step):

# In your current terminal, press Ctrl + C to exit. Then run
yarn start # start server, client and mobile dev process
# or
yarn run server:mobile # start server and mobile dev process

Or to start server and client only, run:

# In the root directory (mern):
yarn run server:client
# Server API is running at http://localhost:SERVER_PORT (http://localhost:8861 by default)
# Web client is running at http://localhost:PORT (http://localhost:3000 by default)

Or to start server and mobile only, run:

# In the root directory (mern):
yarn run server:mobile
# Server API is running at http://localhost:SERVER_PORT (http://localhost:8861 by default)

4. Run the mobile app in your emulator/simulator

cd mobile
npx react-native run-android
# or
npx react-native run-ios

5. Run the mobile app on your mobile devices

6. Debug mobile app with react-native-debugger

7. Debug web app with Redux DevTools

8. Docker

You can start the MERN stack (server and client only) using docker-compose:

Development mode

git clone https://github.com/t-ho/mern-stack.git
cd mern-stack
cp .env.example .env
cp client/.env.example client/.env

# Edit the .env file to meet your requirements
docker-compose up
# The mongoDB service listen on port 27018

The nginx-proxy server will listen on port 8080 (NGINX_PROXY_PORT) by default.

Production mode

git clone https://github.com/t-ho/mern-stack.git
cd mern-stack
cp .env.example .env.prod

# Edit the .env.prod file to meet your requirements
docker-compose -f docker-compose.prod.yml  --env-file ./.env.prod up -d

Testing

In the root (mern-stack) directory, run:

npm run test

Testing frameworks: