A full-stack real-time messaging application built with the MERN stack (MongoDB, Express, React, Node.js), featuring instant message delivery powered by Pusher and Firebase Authentication.
- π Firebase Authentication - Secure user authentication with email and password
- π¬ Real-Time Messaging - Instant message delivery using Pusher WebSockets
- π€ User Management - User registration and profile management
- π¨ Modern UI - Built with Material-UI for a beautiful, responsive interface
- π Live Updates - Messages appear instantly without page refresh
- π± Responsive Design - Works seamlessly on desktop and mobile devices
- π Secure - Password hashing with bcrypt, environment variable protection
- β‘ Fast & Efficient - Optimized for performance with MongoDB and Express
- React 16.13.1 - UI library
- Material-UI - Component library
- Pusher-js - Real-time WebSocket communication
- Firebase - Authentication service
- Axios - HTTP client
- React Flip Move - Smooth message animations
- Node.js - Runtime environment
- Express 5.1.0 - Web framework
- MongoDB with Mongoose - Database and ODM
- Pusher - Real-time messaging service
- bcryptjs - Password hashing
- CORS - Cross-origin resource sharing
Before you begin, ensure you have the following installed:
- Node.js (v14.0.0 or higher)
- npm (v6.0.0 or higher)
- MongoDB Atlas account (free tier works)
- Pusher account (free tier available)
- Firebase project (free tier available)
git clone https://github.com/yogeshkhant77/realtime-chat.git
cd realtime-chat# Navigate to backend directory
cd messenger-backend
# Install dependencies
npm install
# Create .env file (copy from .env.example)
# Windows
copy .env.example .env
# Linux/Mac
cp .env.example .env
# Edit .env file with your credentials (see Configuration section)# Navigate to frontend directory
cd ../messenger-mern-starter-project
# Install dependencies
npm install
# Create .env file (copy from .env.example)
# Windows
copy .env.example .env
# Linux/Mac
cp .env.example .env
# Edit .env file with your credentials (see Configuration section)Terminal 1 - Backend:
cd messenger-backend
npm start
# Server runs on http://localhost:9000Terminal 2 - Frontend:
cd messenger-mern-starter-project
npm start
# App opens on http://localhost:3000Create a .env file in messenger-backend/ directory:
# MongoDB Connection String
MONGODB_URI=your mongodb uri
# Server Port
PORT=9000
# Pusher Configuration
PUSHER_APP_ID=your_pusher_app_id
PUSHER_KEY=your_pusher_key
PUSHER_SECRET=your_pusher_secret
PUSHER_CLUSTER=ap2Create a .env file in messenger-mern-starter-project/ directory:
# Pusher Configuration (for real-time messaging)
REACT_APP_PUSHER_KEY=your_pusher_key
REACT_APP_PUSHER_CLUSTER=ap2
# Firebase Configuration
REACT_APP_FIREBASE_API_KEY=your_firebase_api_key
REACT_APP_FIREBASE_AUTH_DOMAIN=your_firebase_auth_domain
REACT_APP_FIREBASE_PROJECT_ID=your_firebase_project_id
REACT_APP_FIREBASE_STORAGE_BUCKET=your_firebase_storage_bucket
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=your_firebase_messaging_sender_id
REACT_APP_FIREBASE_APP_ID=your_firebase_app_id
REACT_APP_FIREBASE_MEASUREMENT_ID=your_firebase_measurement_id- Go to MongoDB Atlas
- Create a free cluster
- Create a database user
- Whitelist your IP address (or use
0.0.0.0/0for development) - Get your connection string from "Connect" β "Connect your application"
- Go to Pusher Dashboard
- Create a new app
- Go to "App Keys" tab
- Copy App ID, Key, Secret, and Cluster
- Go to Firebase Console
- Create a new project
- Enable Authentication (Email/Password)
- Go to Project Settings β General
- Scroll down to "Your apps" and add a web app
- Copy the configuration values
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Health check endpoint |
| POST | /api/users/save |
Save or update user information |
| POST | /save/messages |
Save a new message |
| GET | /retrieve/conversation |
Retrieve all messages |
Save User:
POST http://localhost:9000/api/users/save
Content-Type: application/json
{
"email": "user@example.com",
"username": "johndoe",
"password": "securepassword"
}Save Message:
POST http://localhost:9000/save/messages
Content-Type: application/json
{
"message": "Hello, World!",
"name": "John Doe",
"timestamp": "2024-01-01T12:00:00Z",
"received": false
}Retrieve Messages:
GET http://localhost:9000/retrieve/conversationrealtime-chat/
βββ messenger-backend/ # Backend server
β βββ server.js # Main server file
β βββ messagemodel.js # Message schema
β βββ usermodel.js # User schema
β βββ package.json # Backend dependencies
β βββ .env # Environment variables (not in git)
β βββ .env.example # Environment template
β
βββ messenger-mern-starter-project/ # Frontend React app
β βββ src/
β β βββ App.js # Main React component
β β βββ Message.js # Message component
β β βββ axios.js # API configuration
β β βββ firebase.js # Firebase config
β βββ public/ # Static files
β βββ package.json # Frontend dependencies
β βββ .env # Environment variables (not in git)
β βββ .env.example # Environment template
β
βββ .gitignore # Git ignore rules
βββ .gitattributes # Line ending configuration
βββ SECURITY_CHECKLIST.md # Security guidelines
βββ SETUP.md # Detailed setup guide
βββ README.md # This file
This project follows security best practices:
- β Environment variables for sensitive data
- β Password hashing with bcrypt
- β
.envfiles excluded from version control - β CORS enabled for secure cross-origin requests
- β Input validation and sanitization
Important: Never commit .env files or expose credentials. See SECURITY_CHECKLIST.md for detailed security guidelines.
cd messenger-backend
npm run dev # Uses nodemon for auto-restartcd messenger-mern-starter-project
npm start # Runs on http://localhost:3000Frontend:
cd messenger-mern-starter-project
npm run buildThe build folder will contain the optimized production build.
- Verify your MongoDB Atlas connection string
- Check if your IP is whitelisted in MongoDB Atlas
- Ensure the database user has proper permissions
- Verify your Pusher credentials in
.env - Check Pusher dashboard for app status
- Ensure cluster name matches (e.g., "ap2")
- Verify Firebase credentials in frontend
.env - Ensure Email/Password authentication is enabled in Firebase Console
- Check Firebase project settings
- Backend default port: 9000
- Frontend default port: 3000
- Change ports in
.envorpackage.jsonif needed
- Use
cross-envfor environment variables (already configured) - Use
;instead of&&for command chaining in PowerShell
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
yk studios
- GitHub: @yogeshkhant77
- Repository: realtime-chat
- Pusher for real-time messaging infrastructure
- Firebase for authentication services
- MongoDB Atlas for database hosting
- Material-UI for UI components
- Detailed Setup Guide
- Security Checklist
- Express.js Documentation
- React Documentation
- MongoDB Documentation
- Pusher Documentation
β If you find this project helpful, please consider giving it a star!