A boilerplate for building full-stack applications using the MERN (MongoDB, Express, React, Node.js) stack. This template sets up essential configurations and file structures, allowing you to quickly start developing robust, scalable web applications.
.env
support for flexible configuration in development and production.Follow the steps below to set up and run the project locally.
Ensure the following tools are installed on your machine:
/mern-template
├── /backend # Express server-side code
└── /frontend # React client-side code
Navigate to the backend directory:
cd backend
Install dependencies:
npm install
Set up environment variables:
Create a .env
file in the backend
directory with the following keys:
PORT=5004
CORS_ORIGINS=http://localhost:5173
TOKEN_SECRET=YOUR_TOKEN_SECRET
CONNECTION_URI=YOUR_CLUSTER_URI
STRIPE_SECRET_KEY=YOUR_STRIPE_SECRET_KEY
Run the development server:
npm run dev
The backend API will now be running at http://localhost:5004
.
npm run start
– Starts the server in production mode.npm run dev
– Starts the server in development mode with Nodemon for auto-restarts on changes.Navigate to the frontend directory:
cd frontend
Install dependencies:
npm install
Set up environment variables:
Create .env
and .env.production
files in the frontend
directory:
# .env (for development)
VITE_API_URL=http://localhost:5004/api
# .env.production (for production)
VITE_API_URL=/api
Run the React development server:
npm run dev
The frontend will be available at http://localhost:5173
.
npm run dev
– Starts the frontend development server with hot-reloading.npm run build
– Builds the frontend for production.Start the backend server:
cd backend
npm run dev
Start the frontend server:
cd frontend
npm run dev
Visit http://localhost:5173
to view the app. The frontend will proxy API requests to the backend server running on http://localhost:5004
.
PORT
– Port for the backend server (default: 5004).TOKEN_SECRET
– Secret key for JWT authentication.CONNECTION_URI
– MongoDB connection string.VITE_API_URL
– API base URL for both development and production environments.This project is licensed under the MIT License. See the LICENSE file for more details.