https://github.com/mohit-nagaraj/wechat
A real-time chat application (better features :D) using Socket.IO, Express, and MongoDB with HTTPS support. It manages user connections and messages securely.
https://github.com/mohit-nagaraj/wechat
aws context-api expressjs github-actions mongodb nodejs rest-api socket-io tailwindcss vitejs
Last synced: 9 months ago
JSON representation
A real-time chat application (better features :D) using Socket.IO, Express, and MongoDB with HTTPS support. It manages user connections and messages securely.
- Host: GitHub
- URL: https://github.com/mohit-nagaraj/wechat
- Owner: mohit-nagaraj
- License: mit
- Created: 2024-08-13T17:00:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-20T07:52:58.000Z (about 1 year ago)
- Last Synced: 2025-03-31T14:52:26.790Z (10 months ago)
- Topics: aws, context-api, expressjs, github-actions, mongodb, nodejs, rest-api, socket-io, tailwindcss, vitejs
- Language: JavaScript
- Homepage: https://we-chat-rho.vercel.app
- Size: 298 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# WeChat
This project is a real-time chat application built using Socket.IO, Express, and MongoDB with HTTPS support. It manages user connections and messages securely.
## Features
- Real-Time Communication: Utilizes Socket.IO for real-time, bidirectional communication between clients and server.
- Secure Connections: HTTPS support with SSL certificates ensures secure data transmission.
- User Management: Connects to MongoDB to store and manage online users.
- Message Handling: Sends and receives messages between users in real-time.
- CORS Support: Configured to allow cross-origin requests from a specified domain.
### How It Works
1. Server Initialization:
- An Express app is initialized.
- SSL certificates are read from the file system.
- An HTTPS server is created using the SSL certificates and the Express app.
2. Socket.IO Setup:
- Socket.IO is initialized with CORS settings and attached to the HTTPS server.
3. MongoDB Connection:
- Connects to a MongoDB database to store user information.
- Defines a schema and model for online users.
4. Event Handling:
- Connection: When a new user connects, their socket ID is logged.
- Add New User: Adds a new user to the MongoDB database if they don't already exist and emits the list of online users.
- Disconnect: Removes the user from the MongoDB database when they disconnect and emits the updated list of online users.
- Message: Sends a message to the specified recipient if they are online.
## Getting Started
### Prerequisites
- Node.js
- MongoDB
- SSL certificates
### Installation
1. Clone the repository:
```bash
git clone https://github.com/mohit-nagaraj/WeChat.git
```
2. Install dependencies:
```bash
npm install
```
3. Configure MongoDB connection in the code if necessary. Add the env variables as you can see from .env.example and put the `PORT`, `MONGO_URI`, `JWT_KEY` values
4. Place your SSL certificates in the /ssl directory.
### Running the Server
Start the server:
Here both the socket server & the express server should be started, they run as 2 separate servers.
```bash
node index.js
```
The server will start listening on port specified with HTTPS.
License
This project is licensed under the MIT License. See the LICENSE file for details.