A full-stack blog application built with Node.js, Express, and MongoDB that allows users to create, read, and manage blog posts with user authentication and file uploads.
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Template Engine: EJS (Embedded JavaScript)
- Authentication: JWT (JSON Web Tokens)
- File Upload: Multer
- Frontend: Bootstrap 5, HTML5, CSS3
- Development: Nodemon for auto-restart
- π User Authentication: Sign up, sign in, and secure session management
- π Blog Management: Create, view, and manage blog posts
- πΌοΈ Image Upload: Upload cover images for blog posts
- π¬ Comments System: Users can comment on blog posts
- π± Responsive Design: Bootstrap-powered responsive UI
- π Protected Routes: Authentication middleware for secure access
- πͺ Cookie-based Sessions: Secure user session management
BLOG-APPLICATION/
β
βββ middlewares/ # Custom middleware functions
β βββ auth.js # Middleware to handle authentication checks
β
βββ models/ # Mongoose schemas for database collections
β βββ blog.js # Blog post schema
β βββ comment.js # Comment schema
β βββ user.js # User schema
β
βββ node_modules/ # Installed npm packages
β
βββ public/ # Publicly accessible assets
β βββ images/
β βββ uploads/ # Uploaded images (like blog cover images)
β
βββ routes/ # Express route definitions
β βββ blog.js # Routes related to blogs
β βββ user.js # Routes for user signup, login, etc.
β
βββ services/ # Helper/service functions
β βββ auth.js # Auth service for login/signup logic
β
βββ views/ # EJS templates for rendering UI
β βββ partials/ # Reusable UI components (header, nav, etc.)
β β βββ head.ejs
β β βββ nav.ejs
β β βββ script.ejs
β βββ addBlog.ejs # Form to add a new blog post
β βββ blog.ejs # Single blog post page
β βββ home.ejs # Homepage displaying all blogs
β βββ signin.ejs # User sign-in page
β βββ signup.ejs # User registration page
β
βββ index.js # Entry point of the application
βββ notes.txt # Developer notes or to-do list
βββ package.json # Project metadata and dependencies
βββ package-lock.json # Exact version lock for dependenciesMake sure you have the following installed:
-
Clone the repository
git clone https://github.com/melroy12/blog-application.git cd blog-application -
Install dependencies
npm install
-
Start MongoDB
Make sure MongoDB is running on your system:
# On Windows (if MongoDB is installed as a service) net start MongoDB # Or start manually mongod
-
Start the application
For development with auto-restart:
npm run dev
For production:
npm start
-
Access the application
Open your browser and navigate to:
http://localhost:8000
- Homepage: Visit the homepage to see all published blog posts
- Sign Up: Create a new account using the sign-up form
- Sign In: Log in with your credentials
- Create Blog: Once logged in, create new blog posts with images
- View Blogs: Click on any blog card to read the full post
- Comments: Add comments to blog posts (requires authentication)
/- Homepage with all blogs/user/signup- User registration/user/signin- User login/blog/add-new- Create new blog post/blog/:id- View individual blog post
The application supports image uploads for blog cover images:
- Supported formats: Common image formats (PNG, JPG, JPEG, etc.)
- Files are stored in
public/uploads/directory - Automatic filename generation with timestamps
The application connects to MongoDB using the following default configuration:
mongodb://127.0.0.1:27017/blogifyTo change the database connection, modify the connection string in index.js:
mongoose.connect('your-mongodb-connection-string')For production deployment, consider using environment variables:
const PORT = process.env.PORT || 8000;
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/blogify';express- Web frameworkmongoose- MongoDB object modelingejs- Template enginejsonwebtoken- JWT authenticationmulter- File upload handlingcookie-parser- Cookie parsing middlewarebootstrap- CSS frameworkcrypto- Cryptographic functionality
nodemon- Development server with auto-restart
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
GET /user/signin- Sign in pageGET /user/signup- Sign up pagePOST /user/signin- Process sign inPOST /user/signup- Process sign upGET /user/logout- User logout
GET /blog/add-new- Add new blog pagePOST /blog/- Create new blog postGET /blog/:id- View specific blogPOST /blog/comment/:blogId- Add comment to blog
- JWT-based authentication
- Password hashing
- Protected routes with middleware
- Cookie-based session management
- Input validation and sanitization
- Express.js community for the excellent framework
- MongoDB team for the robust database solution
- Bootstrap team for the responsive CSS framework
- All contributors who help improve this project
- Made with β€οΈ by Charul192
- Feel free to fork, clone, or contribute!
- If you found this project useful or interesting, please give it a star on GitHub β it helps others discover it too!