This project is a real-time chat application built using the MERN Stack (MongoDB, Express, React, and Node.js). It features real-time messaging, user authentication, online/offline status indicators, and basic chat UI.
- JWT-based Authentication for session management.
- User registration and login with password hashing and validation.
- Real-time messaging using WebSockets via Socket.io.
- Chat history storage in MongoDB, accessible on login.
- Simple React-based chat UI for sending and receiving messages.
- Online users list showing connection status.
- Chat window with auto-scroll for new messages and timestamps for each message.
- Real-time updates for user online/offline status using WebSocket events.
- Typing Indicator: Shows "typing..." when the other user is typing.
This repository contains two main folders:
- client: A React-based frontend built with Vite and TypeScript.
- server: A Node.js backend using Express and MongoDB.
Both parts are hosted on Render. Replace the placeholders with your hosted URLs and Git repository URL before sharing.
Ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- MongoDB Atlas account
-
Navigate to the
serverfolder:cd server -
Install dependencies:
npm install
-
Set environment variables:
Create a.envfile in theserverfolder with the following content:PORT= MONGODB_URI= JWT_SECRET= NODE_ENV=development DB_NAME= CLIENT_URL= LOCAL_URL=http://localhost:5174
-
Start the server:
npm start
The backend should now run on
http://localhost:5000.
-
Navigate to the
clientfolder:cd client -
Install dependencies:
npm install
-
Set environment variables:
Create a.envfile in theclientfolder with the following content:VITE_SERVER_URL=
-
Start the client:
npm run dev
The frontend should now run on
http://localhost:5174.
The backend is hosted on Render at:
Backend Hosted URL
The frontend is hosted on Render at:
Frontend Hosted URL
- Make sure the frontend
VITE_SERVER_URLmatches the hosted backend URL. - For production, ensure sensitive environment variables are stored securely.