A modern real-time chat application built with MERN stack (MongoDB, Express.js, React, Node.js) and enhanced with NestJS framework. This repository contains the backend codebase.
- Real-time Messaging: Instant message delivery using Socket.IO
- User Authentication: Secure JWT-based authentication with cookie sessions
- Image Sharing: Support for image uploads in chat using Cloudinary
- User Profiles: Customizable user profiles with avatars
- Responsive Design: Works seamlessly across all devices
- Role-based Access: Support for user roles (user, admin)
- Framework: NestJS
- Database: MongoDB with Mongoose
- Real-time Communication: Socket.IO
- Authentication: Passport.js with JWT
- File Storage: Cloudinary
- API Documentation: Built-in Swagger/OpenAPI
- Deployment: Vercel
- Node.js >= 20.0.0
- npm >= 10.0.0
- MongoDB instance
- Cloudinary account
Create a .env
file in the root directory:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
JWT_EXPIRE=7d
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
- Clone the repository:
git clone https://github.com/itzSerag/realtime_MERN_chatty-backend.git
cd realtime_MERN_chatty-backend
- Install dependencies:
npm install
- Start the development server:
npm run start:dev
The server will start on http://localhost:3000
POST /api/v1/auth/signup
: Register a new userPOST /api/v1/auth/login
: Login userPOST /api/v1/auth/logout
: Logout user
GET /api/v1/users
: Get all usersGET /api/v1/users/:id
: Get user by IDPATCH /api/v1/users/:id
: Update userDELETE /api/v1/users/:id
: Delete userPATCH /api/v1/users/profile/updateImg
: Update profile image
GET /api/v1/messages/history/:userId
: Get chat history with a userPOST /api/v1/messages
: Send a new message
connection
: Client connects to WebSocket servernewMessage
: New message eventdisconnect
: Client disconnects from WebSocket server
- Frontend Repository: realtime_MERN_chatty-frontend
- Live Demo: Chatty App
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request