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.
- User authentication (Register/Login)
- Real-time messaging
- Online/Offline status
- Message history
- Secure password hashing
- JWT-based authentication
- CORS enabled for cross-origin requests
- 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
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd chat-app/backend
-
Install dependencies
npm install
-
Set up environment variables Create a
.envfile 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 -
Start the development server
npm run dev
The server will start on
http://localhost:5000
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/me- Get current user (protected)GET /api/auth/logout- Logout user
GET /api/users- Get all users (protected)
GET /api/messages- Get all messages (protected)POST /api/messages- Send a new message (protected)
sendMessage- Send a new messagetyping- Notify when user is typingstopTyping- Notify when user stops typing
message- Receive a new messageuserTyping- Notify that a user is typinguserStopTyping- Notify that a user stopped typinguserOnline- Notify when a user comes onlineuserOffline- Notify when a user goes offline
PORT- Server port (default: 5000)MONGO_URI- MongoDB connection stringJWT_SECRET- Secret key for JWTJWT_EXPIRE- JWT expiration time (e.g., 30d)
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Built with ❤️ using modern JavaScript technologies
Happy Coding! 🚀