Cyber-Programer / posting-system-backend

Repository from Github https://github.comCyber-Programer/posting-system-backendRepository from Github https://github.comCyber-Programer/posting-system-backend

πŸ“ Posting System Backend

This is a demo/test project created for educational purposes only. It demonstrates basic backend functionalities such as user authentication, JWT token management, post creation, and route protection using middleware.

  • This project is not completed properly .

πŸš€ Project Overview

This project is a backend server built using Node.js and Express.js that handles:

  • βœ… User registration
  • βœ… User login with password hashing
  • βœ… JWT-based authentication
  • βœ… Middleware to protect private routes
  • βœ… Post creation with title, description, image, and like count
  • βœ… EJS views to render post data
  • βœ… Cookie-based session token management

πŸ“ Features

πŸ” Authentication

  • User login system with encrypted passwords (bcrypt)
  • JWT tokens are issued on login and stored in cookies
  • Middleware verifies token for protected routes

πŸ‘€ User Features

  • Create a new user
  • Prevent duplicate user creation if a user is already logged in

πŸ“ Post Management

  • Create a post with:
    • Title
    • Description
    • Optional Image URL
    • Like count (defaults to 0)
    • Date (automatically generated)
  • Each post is tied to the authenticated user

πŸ”’ Middleware Protection

  • A middleware checks if the JWT token exists and is valid
  • Blocks access to protected routes if the user is not authenticated
  • Clears expired or invalid tokens and redirects to login

πŸ› οΈ Tech Stack

  • Node.js
  • Express.js
  • MongoDB + Mongoose
  • JWT (jsonwebtoken)
  • bcrypt
  • cookie-parser
  • EJS (Embedded JavaScript Templates)

πŸ“· Sample Post Data Format

{
  "title": "My First Post",
  "description": "This is a test post.",
  "image": "https://example.com/image.jpg",
  "likes": 0,
  "date": "2025-04-14T12:47:47.267Z"
}

About


Languages

Language:JavaScript 48.0%Language:EJS 38.4%Language:CSS 13.5%