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.
- 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.
- 
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.
 
- 
Socket.IO Setup: - Socket.IO is initialized with CORS settings and attached to the HTTPS server.
 
- 
MongoDB Connection: - Connects to a MongoDB database to store user information.
- Defines a schema and model for online users.
 
- 
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.
 
- Node.js
- MongoDB
- SSL certificates
- 
Clone the repository: git clone https://github.com/mohit-nagaraj/WeChat.git 
- 
Install dependencies: npm install 
- 
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_KEYvalues
- 
Place your SSL certificates in the /ssl directory. 
Start the server: Here both the socket server & the express server should be started, they run as 2 separate servers.
node index.jsThe server will start listening on port specified with HTTPS.
License This project is licensed under the MIT License. See the LICENSE file for details.