Skip to content

A full-stack blog application built with the MERN stack (MongoDB, Express.js, React.js, Node.js), featuring user authentication and post management.

Notifications You must be signed in to change notification settings

EmaniAditya/blog-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Blog Application

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.

Prerequisites

Before you begin, ensure you have installed:

  • Node.js
  • MongoDB
  • npm (package manager)

Project Structure

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

Getting Started

Backend Setup

  1. Navigate to the server directory:

    cd server
  2. Install dependencies:

    npm install
  3. 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
    
  4. Start the server:

    node index.js

Frontend Setup

  1. Navigate to the client directory:

    cd client
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

Main Features

Backend

  • User Authentication

    • JWT-based authentication
    • Secure password handling
    • Protected routes
  • Blog Post Management

    • Create, read, update, and delete posts
    • User-specific post management

Frontend

  • UI with Tailwind CSS

    • Responsive design
    • Clean and intuitive interface
  • Routing

    • React Router for navigation
    • Protected routes for authenticated users

Development Notes

Environment Variables

The server requires the following environment variables:

  • ATLAS_URI: MongoDB connection string
  • PORT: Server port number
  • JWT_SECRET: Secret key for JWT token generation
  • CLIENT_URL: Frontend application URL

Common Issues

  1. MongoDB Connection:

    • I used docker to run locally. MongoDB Atlas also works fine.
    • Check connection string in .env
  2. Authentication Issues:

    • Verify JWT_SECRET is properly set
    • Check token expiration settings

Security Considerations

  1. The .env file contains sensitive information and is included in .gitignore
  2. JWT tokens are used for secure authentication
  3. CORS is set to accept requests only from the specified CLIENT_URL

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

About

A full-stack blog application built with the MERN stack (MongoDB, Express.js, React.js, Node.js), featuring user authentication and post management.

Topics

Resources

Stars

Watchers

Forks

Languages