Skip to content

ChatApp API is a real-time messaging application backend built using Node.js and Express. This project demonstrates the integration of RESTful APIs with WebSocket for creating a seamless chat experience

Notifications You must be signed in to change notification settings

Aladaabdul/Chat_App_API

Repository files navigation

Real-Time Chat Application API

This project provides the backend for a real-time chat application. Users can register, log in, and send messages to each other in real time. The application uses Socket.io for WebSocket connections to enable real-time communication and JWT for secure authentication.

Features

  • User registration and login with JWT-based authentication.
  • Real-time messaging using WebSockets.
  • Storage of user data and messages in MongoDB.
  • Secure communication with JWT verification.
  • Scalable architecture with a clear separation of concerns.

Technologies Used

  • Node.js
  • Express
  • MongoDB
  • Mongoose
  • Socket.io
  • JWT (JSON Web Token)
  • bcrypt
  • dotenv

Getting Started

Prerequisites

  • Node.js (v14 or later)
  • MongoDB

Installation

  1. Clone the repository:

    git clone https://github.com/Aladaabdul/Chat_App_API.git
  2. Navigate to the project directory:

    cd chat_app_api
  3. Install dependencies:

    npm install
  4. Create a .env file in the root of the project and add the following environment variables:

    PORT=8000
    MONGO_DB_URL=your_mongodb_connection_string
    secretKey=your_jwt_secret
    
  5. Run the application:

    npm start

    The server will start on http://localhost:8000

Usage

Register a User

Log In a User

Messages Endpoints

Send Messages

WebSocket Connection

  URL: http://localhost:8000
  Use the JWT token from the login response to authenticate WebSocket connections. It should be included in the request header as access_token

WebSocket Event

Users have to be listening to the "chat message" event to receive message

  - Join a Room
    {
	      "event": "join",
	      "data": "userId"
    }

  - Send Chat Messages:
      {
        "event": "chat message",
        "data": {
                  "sender": "userId",
                  "receiver": "userId",
                  "content": "content"
                }
    }

    - Receive Chat Messages: 
    {
        "sender": "userId",
        "receiver": "userId",
        "content": "content"
    }

Contact

For any inquiries, please contact aladarahman18@gmail.com

About

ChatApp API is a real-time messaging application backend built using Node.js and Express. This project demonstrates the integration of RESTful APIs with WebSocket for creating a seamless chat experience

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published