Spaces:
Runtime error
Runtime error
File size: 6,563 Bytes
272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | # 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
```bash
npm install
```
### Step 2: Configure Environment Variables
1. Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```
2. Edit `.env` and 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):**
```bash
mongod
```
**Or use MongoDB Atlas (cloud):**
- Sign up at https://www.mongodb.com/cloud/atlas
- Create a cluster
- Get your connection string
- Update `MONGODB_URI` in `.env`
### Step 4: Start the Server
```bash
npm start
```
Or for development with auto-reload:
```bash
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 user
- `POST /api/login` - Login user
### Profile
- `GET /api/profile/:userId` - Get user profile
- `PUT /api/profile` - Update profile
### Friends
- `POST /api/friends/request` - Send friend request
- `GET /api/friends/requests` - Get pending requests
- `POST /api/friends/accept` - Accept friend request
- `GET /api/friends` - Get friends list
### Shop
- `GET /api/shop` - Get shop items
- `POST /api/shop/buy` - Purchase item
- `GET /api/inventory` - Get user inventory
### Channels
- `POST /api/channels` - Create channel
- `GET /api/channels` - Get channels
## π Socket.IO Events
### Client to Server
- `join` - User joins with token
- `join channel` - Join a channel
- `leave channel` - Leave a channel
- `send message` - Send message
- `typing` - User is typing
- `stop typing` - User stopped typing
- `start voice call` - Start voice call
### Server to Client
- `users update` - Online users list updated
- `message` - New message received
- `user typing` - User is typing
- `user stop typing` - User stopped typing
- `voice call started` - Voice call started
## π οΈ Configuration
### MongoDB
You can use either:
1. **Local MongoDB**: Install MongoDB Community Edition
2. **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:
```bash
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 (`mongod` command)
- Check `MONGODB_URI` in `.env`
- Verify MongoDB port (default 27017)
### "Port already in use"
- Change `PORT` in `.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
1. Change `JWT_SECRET` in production
2. Use strong MongoDB passwords
3. Enable HTTPS in production (use `setup-https.ps1`)
4. Keep dependencies updated with `npm update`
## Support
For issues or questions:
1. Check the troubleshooting section
2. Review server console for errors
3. 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**
|