This repository contains the backend for a real-time chat application built using Node.js, Express, MongoDB, and JWT-based authentication. It offers secure login, user management, real-time messaging support, and avatar uploads.
π Repository: Backend-ChatApplication
- βοΈ Node.js + Express β Server and routing
- π’ MongoDB + Mongoose β NoSQL database with schema validation
- π JWT + httpOnly Cookies β Secure authentication
- βοΈ Cloudinary β For image/avatar uploads
- π§ͺ Middleware β For protecting routes and token verification
- π€ User registration, login, and logout
- π§Ύ JWT-based authentication via secure cookies
- πΌοΈ Profile update with avatar image (Cloudinary)
- π Protected routes using custom middleware
- π¬ Real-time messaging logic (text/image)
- π¦ Scalable file structure
backend/ β βββ src/ β βββ controllers/ # Request handlers (auth, user, message) β βββ middlewares/ # JWT authentication middleware β βββ models/ # Mongoose schemas (User, Message) β βββ routes/ # API endpoints grouped by feature β βββ lib/ β β βββ db.js # MongoDB connection setup β β βββ cloudinary.js # Cloudinary configuration β β βββ utils.js # Token generation & utilities β βββ index.js # Main Express app entry point β βββ .env # Environment variables (Mongo URI, JWT, Cloudinary keys) βββ package.json # Dependencies and scripts βββ README.md # Project documentation
To run the server locally:
-
Clone the repository
git clone https://github.com/Priyansu22382/Backend-ChatApplication.git cd Backend-ChatApplication
-
Install Dependencies npm install
-
Create a .env file
PORT=5001 MONGODB_URI=<your_mongo_uri> JWT_SECRET=<your_jwt_secret> CLOUDINARY_CLOUD_NAME=<your_cloud_name> CLOUDINARY_API_KEY=<your_api_key> CLOUDINARY_API_SECRET=<your_api_secret>
-
Start The Server
npm run dev