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.
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 (if you are using MONGODB) - Run ⭐ 'npm run dev' ⭐ to start the webpack-dev-server and the backend server concurrently. This command will start the webpack-dev-server with hot reloading enabled and it will start your backend server as well.
- The frontend application will be served at
localhost:3033
and the backend server will be running on port 3040 (you can change this in thewebpack.config.js
andserver.js
file)
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
This boilerplate has the following file structure:
├── LICENSE
├── README.md
├── client
│ ├── components
│ │ └── App.jsx
│ ├── dist
│ │ ├── bundle.js
│ │ ├── bundle.js.LICENSE.txt
│ │ └── index.html
│ ├── index.html
│ ├── index.js
│ └── stylesheets
│ ├── _styles.scss
│ ├── _variables.scss
│ └── application.scss
├── package-lock.json
├── package.json
├── server
│ ├── 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 production mode after building the frontend.dev
: Starts the webpack dev server and the backend server concurrently. This script is used for starting the application in development mode with live reloading. The frontend will be served atlocalhost:3000
, and the backend server will be running on port 3040.build
: Builds the project for production using webpack. This script is used for building the project for production. It will bundle all the JavaScript, CSS, and other assets and create adist
folder in your project directory.
To run these scripts, use the command npm run [script]
in your terminal.