This is a MERN stack boilerplate that uses MongoDB, Express, React, and Node.js. This repository provides a starting point for building full-stack web applications using the MERN stack.
This boilerplate uses the following dependencies:
bcryptjs
: library used to hash passwordscookie-parser
: parses cookies attached to the client request objectcors
: enables Cross-Origin Resource Sharingdotenv
: loads environment variables from a .env fileexpress
: web framework for Node.jsjsonwebtoken
: used to create and verify JSON Web Tokensmongoose
: interact with MongoDBreact
: building user interfacesreact-dom
: package provides DOM-specific methods for React
@babel/core
: core package required for Babel to work@babel/eslint-parser
: parser that allows ESLint to understand new JavaScript syntax features@babel/preset-env
: package that automatically determines the Babel plugins and polyfills needed based on the target environment@babel/preset-react
: preset that enables Babel to transform JSX into regular JavaScriptbabel-loader
: webpack loader for transpiling JavaScript using Babelconcurrently
: tool for running multiple commands concurrentlycss-loader
: webpack loader for handling CSS fileseslint
: linter for identifying and reporting on patterns found in codeeslint-plugin-react
: provides additional ESLint rules specifically for Reacteslint-plugin-react-hooks
: provides additional ESLint rules specifically for React hooksfile-loader
: webpack loader for handling file imports in JavaScript and CSShtml-webpack-plugin
: simplifies creation of HTML files to serve your webpack bundlesnodemon
: automatically restarts your Node.js application when file changes are detectedsass
: CSS preprocessor that extends CSS syntax with features like variables and mixinssass-loader
: webpack loader for handling SASS/SCSS filesstyle-loader
: webpack loader for injecting styles into the DOMwebpack
: module bundler for JavaScriptwebpack-cli
: command-line interface for webpackwebpack-dev-server
: development server that provides live reloading and other features for webpack
To download and use this boilerplate:
- Clone this repository to your local machine.
- Navigate to the project directory in your terminal and run
npm install
to install the required dependencies. - Edit the
.env
file in the root directory of the project and add any necessary environment variables. - Run
npm run build
to build the project for production using webpack. This command will bundle all the JavaScript, CSS, and other assets and create adist
folder in your project directory. - Run
npm run start
to start the server using nodemon and the bundled files in thedist
folder. Thestart
script uses nodemon to monitor changes to your server files and restarts the server automatically when changes are detected. Alternatively, you can usenpm run dev
to start the webpack dev server and the server using concurrently.
This boilerplate has the following file structure:
├── client
│ ├── components
│ │ └── App.jsx
│ ├── dist
│ │ ├── bundle.js
│ │ ├── bundle.js.LICENSE.txt
│ │ └── index.html
│ ├── index.html
│ ├── index.js
│ └── styling
│ ├── _styles.scss
│ ├── _variables.scss
│ └── application.scss
├── package-lock.json
├── package.json
├── server
│ ├── controllers
│ ├── models
│ ├── routes
│ │ └── api.js
│ └── server.js
└── webpack.config.js
This boilerplate provides the following scripts:
start
: Starts the server using nodemon and theserver.js
file. This script is used for starting the application in development mode.build
: Builds the project for production using webpack. This script is used for building the project for production.dev
: Starts the webpack dev server and the server using concurrently. This script is used for starting the application in development mode with live reloading.
To run these scripts, use the command npm run [script]
in your terminal.