A MERN (MongoDB, Express.js,ejs, Node.js) stack project involves both frontend and backend development. Here's a basic guide to executing a MERN stack project:
-
Setting Up the Project
- Clone the Repository: Start by cloning the project repository from GitHub.
git clone https://github.com/username/repo-name.git cd repo-name
- Clone the Repository: Start by cloning the project repository from GitHub.
-
Backend (Node.js + Express)
- Install Dependencies: Navigate to the backend directory (if separated) and install the necessary packages.
cd backend npm install - Set Up Environment Variables: Create a
.envfile to store environment variables such as database URIs, API keys, and ports.MONGO_URI=your_mongodb_connection_string PORT=5000
- Run the Server: Start the Node.js server.
The server will typically run on
npm start
http://localhost:5000.
- Install Dependencies: Navigate to the backend directory (if separated) and install the necessary packages.
-
Frontend (React.js)
- Install Dependencies: Navigate to the frontend directory and install React dependencies.
cd frontend npm install - Run the React App: Start the React development server.
The frontend will usually run on
npm start
http://localhost:3000.
- Install Dependencies: Navigate to the frontend directory and install React dependencies.
-
Connecting Frontend and Backend
- Ensure the frontend makes API requests to the correct backend URL, typically something like
http://localhost:5000/api/.
- Ensure the frontend makes API requests to the correct backend URL, typically something like
-
Running Both Frontend and Backend
- You can either run the frontend and backend separately or use a tool like
concurrentlyto run both with a single command.Then modify your rootnpm install concurrently --save-dev
package.jsonscripts:"scripts": { "start": "concurrently \"npm run server\" \"npm run client\"", "server": "cd backend && npm start", "client": "cd frontend && npm start" }
- You can either run the frontend and backend separately or use a tool like
-
Building for Production
- Frontend: Create a production build of the React app.
npm run build
- Backend: Serve the built React app using Express in production.
- Frontend: Create a production build of the React app.
## YelpCamp
YelpCamp is a full-stack web application designed to allow users to browse, review, and manage campgrounds. Built with the MERN stack, YelpCamp offers a robust and interactive experience, featuring:
- **User Authentication**: Secure user login and registration using Passport.js.
- **Interactive Maps**: Integration with Mapbox for displaying campground locations on an interactive map.
- **Campground Management**: Users can create, edit, and delete their own campgrounds.
- **Review System**: Users can leave reviews and ratings for campgrounds.
- **Responsive Design**: A mobile-friendly interface built with modern CSS techniques.
### Tech Stack
- **MongoDB**: NoSQL database for storing campground and user data.
- **Express.js**: Backend framework to build a RESTful API.
- **ejs**: Frontend library for building dynamic user interfaces.
- **Node.js**: JavaScript runtime for handling server-side operations.
This project demonstrates a range of skills including frontend development, backend API creation, database management, and user authentication.This description provides an overview of the project, highlighting the key features and technologies used in YelpCamp, making it easier for others to understand the project's scope and functionality.