A modern, full-featured blog application built with Node.js, Express, and MongoDB. Create, share, and engage with blog posts in a beautiful, responsive interface.
- User Registration with profile image upload
- Secure Login/Logout with JWT tokens
- Session Management with 24-hour token expiration
- Custom profile picture
- Create Blog Posts with rich text content
- Image Upload for blog cover images
- View All Blogs in a responsive card layout
- Blog Details with full content display
- Author Attribution with profile information
- Add Comments to blog posts (authenticated users only)
- Comment Threading with user avatars
- Author Badges for blog creators in comments
- Real-time Comment Count display
- Responsive Design for mobile, tablet, and desktop
- Modern UI with Bootstrap 5
- Image Preview during upload
- Error Handling with user-friendly messages
- Loading States and visual feedback
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- Git for version control
-
Clone the repository
git clone https://github.com/GitWitAnish/Blog-App.git cd Blog-App -
Install dependencies
npm install
-
Set up MongoDB
- Make sure MongoDB is running locally on
mongodb://localhost:27017 - Or update the connection string in
index.jsfor your database
- Make sure MongoDB is running locally on
-
Create uploads directory
mkdir -p public/uploads/profiles
-
Start the application
# Development mode (with auto-restart) npm run dev # Production mode npm start
-
Open your browser
- Visit
http://localhost:8000 - Start creating your blog!
- Visit
Blog-App/
βββ π middlewares/
β βββ authentication.js # JWT authentication middleware
βββ π models/
β βββ blog.js # Blog post schema
β βββ comment.js # Comment schema (separate model)
β βββ user.js # User schema with authentication
βββ π public/
β βββ π images/
β β βββ avatar.jpg # Default user avatar
β βββ π uploads/
β βββ π profiles/ # User profile pictures
βββ π routes/
β βββ blog.js # Blog and comment routes
β βββ user.js # Authentication routes
βββ π services/
β βββ authentication.js # JWT token creation/verification
βββ π views/
β βββ π partials/
β β βββ head.ejs # HTML head section
β β βββ nav.ejs # Navigation bar
β β βββ scripts.ejs # JavaScript imports
β βββ 404.ejs # Error page
β βββ addBlog.ejs # Blog creation form
β βββ blogDetails.ejs # Blog post display
β βββ home.ejs # Homepage with blog list
β βββ signin.ejs # Login form
β βββ signup.ejs # Registration form
βββ .gitignore
βββ index.js # Main application entry point
βββ package.json
βββ README.md
- Node.js - JavaScript runtime
- Express.js - Web application framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JWT - JSON Web Token authentication
- Multer - File upload handling
- Cookie Parser - Cookie parsing middleware
- EJS - Embedded JavaScript templating
- Bootstrap 5 - CSS framework
- Vanilla JavaScript - Client-side interactions
- Password Hashing with crypto module
- File Upload Validation (size, type)
- XSS Protection with proper templating
- Session Management with JWT expiration
- Error Handling throughout the application
Create a .env file for production configurations:
# Database
MONGODB_URI=mongodb://localhost:27017/blogify
# JWT
JWT_SECRET=your-super-secret-key-here
# Server
PORT=8000
# File Upload
MAX_FILE_SIZE=5242880 # 5MB in bytesThe app automatically creates the blogify database and required collections on first run.
GET /user/signup- Registration pagePOST /user/signup- Create new user accountGET /user/signin- Login pagePOST /user/signin- User authenticationGET /user/logout- Logout and clear session
GET /- Homepage with all blogsGET /blog/add- Create new blog page (auth required)POST /blog/add- Submit new blog post (auth required)GET /blog/:id- View specific blog postPOST /blog/:id/delete- Delete blog post (author only)
POST /blog/comment/:blogId- Add comment (auth required)
- β View all blog posts
- β Read full blog content and comments
- β Register for new account
- β Login to existing account
- β All visitor features
- β Create new blog posts with images
- β Add comments to any blog post
- β Upload custom profile picture
- β See personalized navigation
- β Delete own blog posts (future feature)
- β Special "Author" badge in comments
- β Author attribution on blog posts
- β Profile display in blog details
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature) - Open a Pull Request
- User Profiles - Dedicated profile pages
- Blog Editing - Edit existing blog posts
- Comment Replies - Nested comment threading
- Search & Filter - Find blogs by title, author, or content
- Categories & Tags - Organize blogs by topics
- Like System - Like blogs and comments
- Admin Dashboard - Manage users and content
- Email Notifications - Notify users of new comments
- Social Sharing - Share blogs on social media
- Rich Text Editor - WYSIWYG blog editor
This project is licensed under the ISC License.
Anish - @GitWitAnish