Skip to content

Danielito1996/chatServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-User Chat System

This is a Node.js backend application for a multi-user chat system that utilizes Express and WebSocket for real-time messaging.

Features

  • Send messages between users
  • Retrieve messages for a specific user
  • Real-time message broadcasting using WebSocket

Project Structure

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

Installation

  1. Clone the repository:
    git clone <repository-url>
    
  2. Navigate to the project directory:
    cd chat-backend
    
  3. Install the dependencies:
    npm install
    

Usage

  1. Start the server:

    npm start
    

    The server will listen on the specified port (default is 3000).

  2. Send a message:

    • Endpoint: POST /messages
    • Body:
      {
        "userId": "senderId",
        "destinationId": "receiverId",
        "content": "Hello!"
      }
  3. Retrieve messages:

    • Endpoint: GET /messages/:userId
    • This will return all messages for the specified user.

WebSocket

The application supports real-time messaging through WebSocket. When a message is sent, it is broadcasted to all connected clients.

License

This project is licensed under the MIT License.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors