All Projects → rmiyazaki6499 → mern-app

rmiyazaki6499 / mern-app

Licence: other
Basic MERN app template for AWS EC2 Deployment guide

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to mern-app

start-here
You should open this repo first
Stars: ✭ 86 (+186.67%)
Mutual labels:  github-actions
action-eslint
GitHub Action to run ESLint on files changed in current PR
Stars: ✭ 44 (+46.67%)
Mutual labels:  github-actions
aws-cdk-github-oidc
CDK constructs to use OpenID Connect for authenticating your Github Action workflow with AWS IAM
Stars: ✭ 59 (+96.67%)
Mutual labels:  github-actions
typescript-api-starter
🔰 Starter for Node.js express API in Typescript 🚀
Stars: ✭ 72 (+140%)
Mutual labels:  github-actions
goodfirstissues
A website that targets developers who want to contribute to open source software but do not know where or how to start.
Stars: ✭ 59 (+96.67%)
Mutual labels:  github-actions
nrwl-nx-action
A GitHub Action to wrap Nrwl Nx commands in your workflows.
Stars: ✭ 163 (+443.33%)
Mutual labels:  github-actions
hammertime
AWS EC2, ASG, RDS Power cycling
Stars: ✭ 12 (-60%)
Mutual labels:  aws-ec2
polynimbus
Multi-cloud infrastructure inventory and management tool, supporting AWS, Google Cloud, Azure, Oracle Cloud, Rackspace Cloud, Hetzner Cloud, Alibaba Cloud, e24cloud.com, Linode, Cloudflare, GoDaddy and Backblaze B2.
Stars: ✭ 70 (+133.33%)
Mutual labels:  aws-ec2
terraform-github-actions-demo
HashiCorp Terraform Github Actions Demo for Github Satellite 2020.
Stars: ✭ 40 (+33.33%)
Mutual labels:  github-actions
install-crystal
GitHub Action: Install Crystal programming language
Stars: ✭ 50 (+66.67%)
Mutual labels:  github-actions
discord-action
GitHub Action that sends a Discord message.
Stars: ✭ 66 (+120%)
Mutual labels:  github-actions
ghaction-chocolatey
GitHub Action for Chocolatey, the package manager for Windows
Stars: ✭ 58 (+93.33%)
Mutual labels:  github-actions
datadog-actions-metrics
Send GitHub Actions metrics to Datadog
Stars: ✭ 27 (-10%)
Mutual labels:  github-actions
phpstan-ga
GithubAction for PHPStan
Stars: ✭ 85 (+183.33%)
Mutual labels:  github-actions
algoliasearch-crawler-github-actions
Algolia Crawler Github action
Stars: ✭ 24 (-20%)
Mutual labels:  github-actions
gitactionboard
GitactionBoard - Ultimate Dashboard for GithubActions.
Stars: ✭ 30 (+0%)
Mutual labels:  github-actions
actions
Collection of repetitive GitHub Actions
Stars: ✭ 12 (-60%)
Mutual labels:  github-actions
cloudflare-dns-action
A GitHub action to set a DNS record using Cloudflare on push to the master branch.
Stars: ✭ 41 (+36.67%)
Mutual labels:  github-actions
gh-actions
A Github action for generating Terraform module documentation using terraform-docs and gomplate
Stars: ✭ 56 (+86.67%)
Mutual labels:  github-actions
jest-github-action
Jest action adding checks with annotations to your pull requests and coverage table as comments
Stars: ✭ 134 (+346.67%)
Mutual labels:  github-actions

MERN Logo

MERN App

This repository contains a simple MERN app as part of the Deploying a Production ready React-Express App on EC2 with CI/CD gist tutorial which you can find here

Table of Contents


Project Layout

Here is the project layout:

mern-app
 |__ client/ (React App Frontend)
    |__ public/
    |__ src/
 |__ scripts/
 |__ app.js (Express Backend)
 |__ package.json
 |__ Dockerfile
 |__ docker-compose.yml

Project Structure

The app simply displays the default React app components. However, I have added a simple API which the frontend calls to confirm that the API call is successfull.

I will be using a generic MERN (MongoDB, Express, React, Node.js) stack app which uses a proxy with the Express server.

What this means is that instead of having two separate servers running (One for the frontend (React) and the other for the backend (Express)) we will build our React project into a directory of static files which Express will then serve.

The benefit of this is this allows you to manage the project in one collective repo/project and it removes the barrier of having to deal with any CORS issues of your backend not recognizing the frontend requests.


Setting up the mern-app project

Start by cloning the project with the command:

$ git clone https://github.com/rmiyazaki6499/mern-app.git

Setting up the mern-app project with Docker

For those that are not interested in setting up the project manually or would simply not have to worry about downloading node.js and its dependencies, I have created a Dockerfile and docker-compose.yml file to help create a container with everything you would need to run the mern-app.

Install Docker

To make this as easy as possible, we will be using Docker Compose to creat our container.

$ docker-compose --version
docker-compose version 1.26.2, build eefe0d31
  • Go into the project directory to build and run the container with:
$ cd mern-app/
$ docker-compose up --build

This may take a few moments

Navigate to http://localhost:5000 to view the site on the local server. It should look something like this:

mern-app_react_success

Cleaning up the Container and Image

  • To stop the container from running, use <Ctrl-C> twice.
  • To close down the container use the command:
$ docker-compose down
  • Then to clean up the container and image which we are no longer using use the command:
$ docker system prune -fa
  • Confirm that the container and image is no longer there with:
$ docker system df -v

Setting up the mern-app project manually

  • If you either did not want to use Docker or was curious to build the mern-app manually follow the directions below.

  • Start by installing the dependencies for both Express and React:

$ cd mern-app/
$ npm install
$ cd client/
$ npm install

Let's first check to see what our React frontend looks like.

  • To run the React server use the command in client directory:
$ npm start

mern-app_react

The API is not working because well, we are not running our backend yet! Let's do that now.

  • In another terminal session run the command npm start at the root directory of the project as we did with the frontend. It should look something like this:

mern-app_run_server

You can see that we have the express server running on port 5000.

  • Now switch back to the http://localhost:3000 and refresh the page. You should see the Message at the bottom be updated!

mern-app_react_success

We have two servers running, one for the React frontend and one for the Express backend. If your project set up is essentially two separate projects between the frontend and backend this would be as far as we would need to check. However, I have set this project set up so that rather than running two servers, we run a reverse proxy for React through Express and will serve the frontend through the Express server.

Because we will not be running the React server for our project, go ahead and stop the React server.

  • In the client directory run the command:
$ npm run-script build

React then will create a build directory with a production build of your app which is where our Express server will use to serve the frontend.

Back to Table of Contents

Author

Created by:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].