Skip to content

Haarush2006/ChatApp-BE

Repository files navigation

RoomsBackend - Chat App Backend

A simple WebSocket-based backend for a multi-room chat application. This backend allows clients to join chat rooms, send and receive messages in real-time, and maintains message history for each room with automatic expiration.

Features

  • Real-time chat using WebSockets
  • Multiple chat rooms support
  • Message history per room (auto-expires after 30 minutes of inactivity)
  • System messages for join/leave events
  • Simple, stateless server (no database required)

Getting Started

Prerequisites

  • Node.js (v16+ recommended)
  • npm

Installation

  1. Clone the repository:
    git clone <your-repo-url>
    cd RoomsBackend
  2. Install dependencies:
    npm install

Running the Server

To start the server in development mode:

npm run dev

The WebSocket server will run on ws://localhost:8080.

WebSocket API

Events

  • Join Room
    { "type": "join", "username": "yourName", "roomId": "room1" }
  • Send Chat Message
    { "type": "chat", "message": "Hello!" }
  • Receive Message
    { "type": "chat", "sender": "user", "message": "Hello!", "timestamp": 123456789 }
  • Receive System Message
    { "type": "system", "sender": "system", "message": "user joined the room", "timestamp": 123456789 }
  • Receive History
    { "type": "history", "messages": [ ... ] }

Project Structure

  • src/index.ts - Main WebSocket server implementation
  • src/types/ - TypeScript type definitions

Author

Haarush

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published