Dharmendra016/blogApplication

This is a simple BlogApplication

โ˜… 1Forks 0EJSGitHub โ†—Compare

Project website โ†—

README

Blog Application

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.

๐Ÿš€ Features

  • 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

๐Ÿ› ๏ธ Technologies Used

  • 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

๐Ÿ“‹ Prerequisites

Before running this application, make sure you have the following installed:

โš™๏ธ Installation & Setup

1. Clone the repository

git clone https://github.com/dharmendra016/blogApplication.git
cd blogApplication

2. Install dependencies

npm install

3. Environment Configuration

Create 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_string

Environment 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

4. Start the Application

Development mode (with auto-restart):

npm run dev

Production mode:

npm start

5. Access the Application

Open your web browser and navigate to:

http://localhost:3000

๐Ÿ“ Project Structure

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

๐Ÿ”ง API Endpoints

Authentication

  • POST /user/signup - User registration
  • POST /user/login - User login
  • GET /user/logout - User logout

Blog Management

  • GET /blog - Get all blogs
  • POST /blog - Create new blog
  • GET /blog/:id - Get specific blog

Comments

  • POST /comment/:blogId - Add comment to blog
  • GET /comment/:blogId - Get blog comments

๐Ÿš€ Usage Guide

  1. Register: Create a new account using the signup page
  2. Login: Access your account with email and password
  3. Create Blog: Navigate to "Add Blog" to create new posts
  4. Upload Images: Add relevant images to your blog posts
  5. View Blogs: Browse all blogs on the homepage
  6. Comment: Engage with other users through comments

๐Ÿ”’ Security Features

  • Password encryption and secure authentication
  • JWT-based session management
  • Input validation and sanitization
  • Secure file upload handling
  • Environment variable protection

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

๐Ÿ› Issues & Support

If you encounter any bugs or have questions:

  1. Check existing issues
  2. Create a new issue with detailed description
  3. Include steps to reproduce the problem

โญ If you found this project helpful, please give it a star!

Contributors

Dharmendra016

Issues