Skip to content

marcopestrin/MERN-boilerplate

Repository files navigation

MERN Boilerplate

MERN Boilerplate is a project made with the follow technologies:

  • Express JS
  • React JS
  • Redux
  • MongoDB / Mongoose
  • Typescript
  • NodeJs

Installation

set .env file in root with this template:

CLUSTER=
NODE_ENV=
PORT=
FRONTEND_URL=
ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
ACCESS_TOKEN_LIFE=
ADMIN_PASSWORD=
MAILER_HOST=
MAILER_PORT=
MAILER_USER=
MAILER_PASSWORD=
PUBLIC_URL=

set .env file in /client with this template:

REACT_APP_BASE_URL_SERVER=

run to CLI:

npm install
npm run dev / npm run start

Demonstrations

  • Authentication with JWT (Web JSON Token)
  • API documentation with Swagger model
  • Data typing with Typescript
  • User registration flow with MVC pattern (Model-View-Controller)
  • CORS management (Cross-Origin Resource Sharing)
  • Project tree with code subdivision
  • Detailed and generic management of HTTP call status codes
  • Personal data managed through environment variables
  • CRUD pattern on model (Create, Read, Update, Delete)
  • Input validated by a generic validator
  • Combine Express routes (Backend endpoint) and React routes (Frontend pages)

Demo

You can see the first deploy in Heroku here

Changelog by month

Month Description
March 2021
  • Authentication system
  • CRUD API on User Mode
  • First Deploy on Heroku
  • Creating frontend (login/signup/logout)
April 2021
  • Handle function http request
  • Frontend alias import
  • Split controller-services backend
  • Created custom token collection in DB
  • Added Joi Validator for endpoint input
May 2021
  • Added interceptors to manage token renewal
  • Frontend: Ability to change the information of your user and other users if you are admin
  • Created public kanban board for frontend and backend
June 2021
  • Added Joi validator each frontend form
  • Created notifications reducer (Frontend) for popupNotify component
  • When update a password of a user, you must add the password of current logged user
  • When edit or add a new user, check if email and username are available to avoid duplicate
July 2021
  • Auto-remove token expired
  • When I remove a user, I also remove all tokens associated with it
  • Frontend: Reset password page
  • Added Title component and MenuAuth component
  • Check user permit server side for the functions delete, update, enable, disable user
  • Cannot delete yourself when you are logged
  • Deploy first versione on Heroku

Environment variables

Key Example Description
CLUSTER false Start backend with or without cluster
NODE_ENV development Run in "development" mode or in "production" mode
PORT 8000 Port used by ExpressJS
FRONTEND_URL http://localhost:3000 Url frontend associated with it
ACCESS_TOKEN_SECRET example just a simple string to generate a token
REFRESH_TOKEN_SECRET example2 just a simple string to generate a token
ACCESS_TOKEN_LIFE 86400000 Duration time of the token expressed in milliseconds
REFRESH_TOKEN_LIFE 25920000 Duration time of the refresh token expressed in milliseconds
ADMIN_PASSWORD gino Password that accesses the services, bypassing the controls
MAILER_HOST smtp.ethereal.email Email host
MAILER_PORT 432 Email port
MAILER_USER pestrinmarco@gmail.com Email address
MAILER_PASSWORD myPassword123 Email password
HOST_APPLICATION localhost Host backend application

Others

This project are made in my free time. Currently under construction by myself. If you have any suggestions to improve the project or noticed errors please make a pull-request or send me an email to: pestrinmarco@gmail.com