This is a Node.js backend application for a multi-user chat system that utilizes Express and WebSocket for real-time messaging.
- Send messages between users
- Retrieve messages for a specific user
- Real-time message broadcasting using WebSocket
chat-backend
├── src
│ ├── app.js # Initializes the Express application and WebSocket server
│ ├── server.js # Entry point for starting the server
│ ├── controllers
│ │ └── messageController.js # Handles message-related requests
│ ├── routes
│ │ └── messageRoutes.js # Defines message-related routes
│ ├── models
│ │ └── message.js # Defines the Message model
│ ├── services
│ │ └── websocketService.js # Manages WebSocket connections and broadcasting
│ └── utils
│ └── index.js # Utility functions
├── package.json # npm configuration file
└── README.md # Project documentation
- Clone the repository:
git clone <repository-url> - Navigate to the project directory:
cd chat-backend - Install the dependencies:
npm install
-
Start the server:
npm startThe server will listen on the specified port (default is 3000).
-
Send a message:
- Endpoint:
POST /messages - Body:
{ "userId": "senderId", "destinationId": "receiverId", "content": "Hello!" }
- Endpoint:
-
Retrieve messages:
- Endpoint:
GET /messages/:userId - This will return all messages for the specified user.
- Endpoint:
The application supports real-time messaging through WebSocket. When a message is sent, it is broadcasted to all connected clients.
This project is licensed under the MIT License.