A full-stack blog application built with the MERN stack (MongoDB, Express.js, React.js, Node.js), with user authentication, post management, and commenting system.
Before you begin, ensure you have installed:
- Node.js
- MongoDB
- npm (package manager)
blog-application/
├── client/ # Frontend React application
├── server/ # Backend Node.js application
│ ├── db/ # Database models and connection
│ ├── routes/ # API routes
│ ├── authMiddleware.js # Authentication middleware
│ └── index.js # Server entry point
└── README.md # This file
-
Navigate to the server directory:
cd server
-
Install dependencies:
npm install
-
Create a
.env
file based on.env.example
:ATLAS_URI=mongodb://localhost:27017/blog-application PORT=5050 JWT_SECRET=your-secret CLIENT_URL=https://frontend-url.here.com
-
Start the server:
node index.js
-
Navigate to the client directory:
cd client
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
User Authentication
- JWT-based authentication
- Secure password handling
- Protected routes
-
Blog Post Management
- Create, read, update, and delete posts
- User-specific post management
-
UI with Tailwind CSS
- Responsive design
- Clean and intuitive interface
-
Routing
- React Router for navigation
- Protected routes for authenticated users
The server requires the following environment variables:
ATLAS_URI
: MongoDB connection stringPORT
: Server port numberJWT_SECRET
: Secret key for JWT token generationCLIENT_URL
: Frontend application URL
-
MongoDB Connection:
- I used docker to run locally. MongoDB Atlas also works fine.
- Check connection string in
.env
-
Authentication Issues:
- Verify JWT_SECRET is properly set
- Check token expiration settings
- The
.env
file contains sensitive information and is included in.gitignore
- JWT tokens are used for secure authentication
- CORS is set to accept requests only from the specified CLIENT_URL
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request