Spaces:
Runtime error
Runtime error
Discord-Like Chat Application
A comprehensive real-time chat application with Discord-like features including user profiles, friends system, shop, voice channels, and media sharing.
Features
User Management
- User registration and login with email/password
- JWT-based authentication
- Editable user profiles with bio and avatar
- Persistent accounts saved in MongoDB
Chat & Messaging
- Real-time messaging with Socket.IO
- Text channels and voice channel support
- Typing indicators
- Media sharing (photos & videos)
- Message history
Social Features
- Friends list system
- Friend requests with accept/reject
- Online status tracking
- Member list with online indicators
Shop & Economy
- In-game shop with purchasable items
- Coin currency system (1000 starting coins)
- User inventory
- Purchase tracking
UI/UX
- Discord-inspired dark theme
- Responsive design (desktop, tablet, mobile)
- Channel sidebar with quick access
- Member sidebar
- Profile panel
Installation & Setup
Prerequisites
- Node.js (v14 or higher)
- MongoDB (local or cloud)
- npm (comes with Node.js)
Step 1: Install Dependencies
npm install
Step 2: Configure Environment Variables
- Copy
.env.exampleto.env:
cp .env.example .env
- Edit
.envand set your MongoDB connection:
MONGODB_URI=mongodb://localhost:27017/discord-app
JWT_SECRET=your_secret_key_here
Step 3: Start MongoDB
Make sure MongoDB is running on your system.
Windows (if using local MongoDB):
mongod
Or use MongoDB Atlas (cloud):
- Sign up at https://www.mongodb.com/cloud/atlas
- Create a cluster
- Get your connection string
- Update
MONGODB_URIin.env
Step 4: Start the Server
npm start
Or for development with auto-reload:
npm run dev
The server will start at http://localhost:3000
How to Use
1. Create Account
- Click "Register"
- Enter username, email, and password
- Click "Create Account"
2. Log In
- Enter your email and password
- Click "Login"
3. Send Messages
- Select a channel from the left sidebar
- Type your message in the input box
- Press Enter or click the send button
4. Share Media
- Click the paperclip icon in the message input
- Select an image or video from your computer
- The file will be sent in the message
5. Manage Profile
- Click the profile icon (top right)
- Edit your username and bio
- Click "Save Profile"
- Check your inventory and coins
6. Add Friends
- Click the Friends icon (users icon) in the left guild sidebar
- Accept friend requests from others
- View your current friends list
7. Use the Shop
- Click the Shop icon (store icon) in the left guild sidebar
- Browse available items
- Click "Buy" to purchase items (uses coins)
- Check inventory in your profile
Project Structure
message-app/
βββ server.js # Express & Socket.IO backend
βββ client.js # Frontend JavaScript
βββ index.html # Frontend HTML
βββ package.json # Dependencies
βββ .env # Environment variables (create this)
βββ .env.example # Example environment file
βββ README.md # This file
API Endpoints
Authentication
POST /api/register- Register new userPOST /api/login- Login user
Profile
GET /api/profile/:userId- Get user profilePUT /api/profile- Update profile
Friends
POST /api/friends/request- Send friend requestGET /api/friends/requests- Get pending requestsPOST /api/friends/accept- Accept friend requestGET /api/friends- Get friends list
Shop
GET /api/shop- Get shop itemsPOST /api/shop/buy- Purchase itemGET /api/inventory- Get user inventory
Channels
POST /api/channels- Create channelGET /api/channels- Get channels
π Socket.IO Events
Client to Server
join- User joins with tokenjoin channel- Join a channelleave channel- Leave a channelsend message- Send messagetyping- User is typingstop typing- User stopped typingstart voice call- Start voice call
Server to Client
users update- Online users list updatedmessage- New message receiveduser typing- User is typinguser stop typing- User stopped typingvoice call started- Voice call started
π οΈ Configuration
MongoDB
You can use either:
- Local MongoDB: Install MongoDB Community Edition
- MongoDB Atlas: Free cloud hosting at https://www.mongodb.com/cloud/atlas
JWT Secret
Change the JWT_SECRET in .env to a secure random string for production:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Port
Default port is 3000. Change in .env:
PORT=8080
Mobile Support
The app is fully responsive and works on:
- Desktop (Chrome, Firefox, Safari, Edge)
- Tablet (iPad, Android tablets)
- Mobile phones (iOS, Android)
Troubleshooting
"Cannot connect to MongoDB"
- Make sure MongoDB is running (
mongodcommand) - Check
MONGODB_URIin.env - Verify MongoDB port (default 27017)
"Port already in use"
- Change
PORTin.env - Or kill the process:
lsof -ti:3000 | xargs kill -9
"Socket.IO connection failed"
- Check if server is running
- Verify correct server URL
- Check CORS settings in server.js
Files not uploading
- Check file size (max 50MB)
- Verify file type (images/videos only)
- Check browser console for errors
Default Shop Items
The shop comes with these starting items (add more by modifying server.js):
- Discord Nitro Badge - 500 coins
- Profile Border - 300 coins
- Custom Status - 200 coins
- Emote Pack - 250 coins
Security Notes
- Change
JWT_SECRETin production - Use strong MongoDB passwords
- Enable HTTPS in production (use
setup-https.ps1) - Keep dependencies updated with
npm update
Support
For issues or questions:
- Check the troubleshooting section
- Review server console for errors
- Check browser console (F12) for client errors
Future Enhancements
- Direct messaging (DMs)
- Message reactions with emojis
- Message editing and deletion
- Voice call with WebRTC
- Video streaming
- File storage with cloud services
- Admin commands
- Server roles and permissions
- Message pins
- Custom emoji upload
Made with using Node.js, Express, Socket.IO, and MongoDB