This application is part of the MERN stack practical series. It allows users to create, manage, and share blog posts and notes.
If you're seeing the error: "Could not connect to any servers in your MongoDB Atlas cluster", follow these steps:
-
Check your .env file in the backend folder:
cd backend # Create .env file if it doesn't exist echo "PORT=5000" > .env echo "MONGO_URI=mongodb://localhost:27017/blogapp" >> .env echo "JWT_SECRET=your-secret-key" >> .env
-
For Local MongoDB (easiest fix):
- Install MongoDB locally
- Use:
mongodb://localhost:27017/blogapp
-
For MongoDB Atlas:
- Go to MongoDB Atlas
- Create cluster → Database Access → Add user
- Network Access → Add IP (use 0.0.0.0/0 for development)
- Get connection string
BlogPostorNotes Management App/
├── backend/
│ ├── src/
│ │ ├── config/
│ │ ├── controllers/
│ │ ├── middleware/
│ │ ├── models/
│ │ ├── routes/
│ │ ├── services/
│ │ ├── utils/
│ │ └── app.js
│ ├── uploads/
│ ├── .env.example
│ ├── .gitignore
│ ├── package.json
│ └── server.js
│
├── frontend/
│ ├── BlogApp/
│ ├── .env.example
│ ├── .gitignore
│ ├── package.json
│ └── README.md
│
├── shared/
│ ├── types/
│ └── constants/
│
├── docs/
│ ├── API.md
│ ├── SETUP.md
│ └── CONTRIBUTING.md
│
├── .gitignore
└── README.md
- Authentication: JWT-based auth with refresh tokens
- Blog Management: CRUD operations for blogs
- User Management: Profile management and user roles
- Comment System: Nested comments with moderation
- File Upload: Image uploads for blog posts
- Search & Filter: Full-text search and category filtering
- Pagination: Efficient data loading
- Rate Limiting: API protection
- Responsive Design: Mobile-first approach
- Dark/Light Mode: Theme switching
- Rich Text Editor: WYSIWYG editor for blog posts
- Image Gallery: Multiple image uploads
- Real-time Updates: Live comments and notifications
- SEO Optimization: Meta tags and structured data
- Progressive Web App: Offline capabilities
- Accessibility: WCAG 2.1 compliance
PORT=5000
MONGO_URI=mongodb://localhost:27017/blogapp
# OR for MongoDB Atlas:
# MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/blogapp?retryWrites=true&w=majority
JWT_SECRET=your-secret-key
JWT_REFRESH_SECRET=your-refresh-secret
NODE_ENV=development
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
VITE_API_URL=http://localhost:5000/api
VITE_APP_NAME=BlogApp
-
Clone the repository
-
Backend Setup:
cd backend npm install # Create .env file with your MongoDB URI echo "PORT=5000" > .env echo "MONGO_URI=mongodb://localhost:27017/blogapp" >> .env echo "JWT_SECRET=your-secret-key" >> .env
-
Frontend Setup:
cd frontend/BlogApp npm install # Create .env file echo "VITE_API_URL=http://localhost:5000/api" > .env
- Install MongoDB locally
- Start MongoDB service
- Use connection string:
mongodb://localhost:27017/blogapp
- Create account at MongoDB Atlas
- Create a new cluster
- Create a database user
- Whitelist your IP address (or use 0.0.0.0/0 for development)
- Get your connection string
This error occurs when MongoDB Atlas cannot be reached. Solutions:
-
Check your .env file:
# Make sure MONGO_URI is set correctly MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/blogapp -
Whitelist IP in MongoDB Atlas:
- Go to MongoDB Atlas → Network Access
- Click "Add IP Address"
- Add your current IP or use "Allow Access from Anywhere" (0.0.0.0/0) for development
-
Verify database user credentials:
- Ensure the username and password in your connection string are correct
- Check the database user has proper permissions
-
Check MongoDB cluster status:
- Ensure your cluster is running in MongoDB Atlas
- Verify the cluster name in your connection string
cd backend
npm run dev
# Server will run on http://localhost:5000cd frontend/BlogApp
npm run dev
# App will run on http://localhost:5173{
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
}
}{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}# Backend setup
cd backend
npm install