Skip to content

Arun290799/chat-app-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time Chat Application

A real-time chat application built with Node.js, Express, MongoDB, and Socket.IO. This application provides instant messaging functionality with user authentication and real-time message delivery.

Features

  • User authentication (Register/Login)
  • Real-time messaging
  • Online/Offline status
  • Message history
  • Secure password hashing
  • JWT-based authentication
  • CORS enabled for cross-origin requests

Tech Stack

Backend

  • Node.js - JavaScript runtime
  • Express - Web framework
  • MongoDB - Database
  • Mongoose - MongoDB object modeling
  • Socket.IO - Real-time communication
  • JWT - JSON Web Tokens for authentication
  • bcryptjs - Password hashing
  • dotenv - Environment variables

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (local or cloud instance)
  • npm or yarn

Getting Started

  1. Clone the repository

    git clone <repository-url>
    cd chat-app/backend
  2. Install dependencies

    npm install
  3. Set up environment variables Create a .env file in the backend directory with the following variables:

    PORT=5000
    MONGO_URI=your_mongodb_connection_string
    JWT_SECRET=your_jwt_secret_key
    JWT_EXPIRE=30d
    
  4. Start the development server

    npm run dev

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

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login user
  • GET /api/auth/me - Get current user (protected)
  • GET /api/auth/logout - Logout user

Users

  • GET /api/users - Get all users (protected)

Messages

  • GET /api/messages - Get all messages (protected)
  • POST /api/messages - Send a new message (protected)

WebSocket Events

Client to Server

  • sendMessage - Send a new message
  • typing - Notify when user is typing
  • stopTyping - Notify when user stops typing

Server to Client

  • message - Receive a new message
  • userTyping - Notify that a user is typing
  • userStopTyping - Notify that a user stopped typing
  • userOnline - Notify when a user comes online
  • userOffline - Notify when a user goes offline

Environment Variables

  • PORT - Server port (default: 5000)
  • MONGO_URI - MongoDB connection string
  • JWT_SECRET - Secret key for JWT
  • JWT_EXPIRE - JWT expiration time (e.g., 30d)

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Acknowledgments

  • Built with ❤️ using modern JavaScript technologies

Happy Coding! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors