Skip to content
Lasha Kakhidze edited this page Oct 18, 2019 · 16 revisions

mern-template

npm version npm

mern-temlate is a cli tool for generating isomorphic and modular mongo, express, react and node web app. The project is based on the best practices and popular tools. This is not just a simple starter that generates only the folder structure, but a real example of a production ready todo list web application.

Table of contents

Visualization

alt text

Installation

npx mern-template my-app

or

npm install mern-template -g
mern-template my-app

Run Project

cd my-app
npm install
npm start

or

cd my-app
docker-compose up

Project Structure

|__ bin
|__ client
|__ config
|__ public
|__ server
|.. docker-compose.yml
|.. Dockerfile
|.. Dockerfile-development
|.. jest.config.js
|.. package.json
|.. process.json
|.. project.config.js
|.. webpack.common.js
|.. webpack.dev.js
|.. webpack.prod.js

bin

bin folder contains file named www from where we start express server and connect to mongodb.

config

I use dotenv to load environment variables. If NODE_ENV is development or test, environment variables are loaded from config/.development and config/.test files relatively. In production it is better to enter all your environment variables from console. It isn't good idea to upload environment variables on github.

client

client folder contains react code. I use redux and redux-saga for state management, react-router-dom to handle client side routing and material-ui as a UI framework. I use scss preprocessor with bem methodology.

public

public folder contains static assets.

server

server side code has following structure:

|__ server
    |__ auth
    |__ tasks
    |__ users
    |.. app.js
    |.. db.js
    |.. routes.js

and each module looks like this:

|__ tasks
    |__ __tests__
    |.. index.js
    |.. task-controller.js
    |.. task-model.js
    |.. task-validation.js

I use jest for testing, joi for validation, passport-jwt for authentication, mongoose driver for mongodb and signale for logging.

License

Copyright (c) 2019 Lasha Kakhidze. This code is released under the MIT license.