A full-stack blog application that enables users to create accounts, write blog posts, upload images, and engage with content through comments. Built with modern web technologies for a seamless user experience.
- User Authentication: Secure user registration, login, and logout with JWT
- Blog Management: Create, view, and manage blog posts
- Image Upload: Upload and display images with blog posts using Multer
- Comments System: Comment on your own and others' blog posts
- Responsive Design: Mobile-friendly interface that works across all devices
- Session Management: Secure user sessions with cookie-based authentication
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Frontend: EJS templating engine
- Authentication: JSON Web Tokens (JWT)
- File Upload: Multer middleware
- Environment Management: dotenv
- Development: Nodemon for auto-restart
Before running this application, make sure you have the following installed:
git clone https://github.com/dharmendra016/blogApplication.git
cd blogApplicationnpm installCreate a .env file in the root directory and add the following variables:
PORT=3000
JWT_SECRET=your_jwt_secret_key
DATABASE_URL=your_mongodb_connection_stringEnvironment Variables Explanation:
PORT: The port number on which the server will run (default: 3000)JWT_SECRET: A secret key for JWT token signing (use a strong, random string)DATABASE_URL: Your MongoDB connection string
For MongoDB Atlas:
DATABASE_URL=mongodb+srv://username:[email protected]/blogapp?retryWrites=true&w=majority
For Local MongoDB:
DATABASE_URL=mongodb://localhost:27017/blogapp
Development mode (with auto-restart):
npm run devProduction mode:
npm startOpen your web browser and navigate to:
http://localhost:3000
blogApplication/
โโโ configs/
โ โโโ databaseConnection.js # Database configuration
โโโ controllers/
โ โโโ blogController.js # Blog-related logic
โ โโโ commentController.js # Comment handling
โ โโโ userController.js # User authentication
โโโ middlewares/
โ โโโ auth.js # Authentication middleware
โโโ models/
โ โโโ blogModel.js # Blog data model
โ โโโ commentModel.js # Comment data model
โ โโโ userModel.js # User data model
โโโ public/
โ โโโ image/ # Static images
โ โโโ uploads/ # User uploaded files
โโโ routes/
โ โโโ blogRoutes.js # Blog routes
โ โโโ commentRoutes.js # Comment routes
โ โโโ staticRoutes.js # Static content routes
โ โโโ userRoute.js # User routes
โโโ services/
โ โโโ auth.js # Authentication services
โโโ views/
โ โโโ partials/ # EJS partial templates
โ โโโ addBlog.ejs # Create blog page
โ โโโ blog.ejs # Individual blog view
โ โโโ home.ejs # Homepage
โ โโโ login.ejs # Login page
โ โโโ signup.ejs # Registration page
โโโ .env # Environment variables
โโโ index.js # Main application file
โโโ package.json # Project dependencies
โโโ README.md # Project documentation
POST /user/signup- User registrationPOST /user/login- User loginGET /user/logout- User logout
GET /blog- Get all blogsPOST /blog- Create new blogGET /blog/:id- Get specific blog
POST /comment/:blogId- Add comment to blogGET /comment/:blogId- Get blog comments
- Register: Create a new account using the signup page
- Login: Access your account with email and password
- Create Blog: Navigate to "Add Blog" to create new posts
- Upload Images: Add relevant images to your blog posts
- View Blogs: Browse all blogs on the homepage
- Comment: Engage with other users through comments
- Password encryption and secure authentication
- JWT-based session management
- Input validation and sanitization
- Secure file upload handling
- Environment variable protection
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
If you encounter any bugs or have questions:
- Check existing issues
- Create a new issue with detailed description
- Include steps to reproduce the problem
โญ If you found this project helpful, please give it a star!