File size: 5,469 Bytes
55a57c5
272dfc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55a57c5
272dfc6
55a57c5
 
272dfc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55a57c5
272dfc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64e57ec
 
 
 
 
272dfc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#  Getting Started - Step by Step

## Prerequisites
- Node.js (https://nodejs.org/) - Download LTS version
- MongoDB - Either local or cloud (MongoDB Atlas)

## Step 1: Prepare Your Environment

### Install Node.js Dependencies
Open PowerShell in your project folder and run:
```powershell
npm install
```

This installs all required packages:
- express (web framework)
- socket.io (real-time communication)
- mongoose (database ORM)
- jsonwebtoken (authentication)
- bcryptjs (password hashing)
- And more...

## Step 2: Set Up MongoDB

### Option A: Local MongoDB
1. Download MongoDB Community Edition: https://www.mongodb.com/try/download/community
2. Install it (use default settings)
3. MongoDB will start automatically
4. Your connection string: `mongodb://localhost:27017/discord-app`

### Option B: MongoDB Atlas (Cloud)
1. Go to https://www.mongodb.com/cloud/atlas
2. Sign up for free account
3. Create a cluster
4. Click "Connect"
5. Copy the connection string
6. Replace `<password>` with your password

## Step 3: Configure Environment

1. Edit the `.env` file in your project root:
```
PORT=3000
MONGODB_URI=mongodb://localhost:27017/discord-app
JWT_SECRET=MySecretKey123!
```

2. Replace `MONGODB_URI` with your MongoDB connection string

## Step 4: Initialize Database (Optional)

Add sample shop items:
```powershell
npm run init-db
```

This creates default shop items in your database.

## Step 5: Start the Server

### Development (with auto-reload):
```powershell
npm run dev
```

### Production:
```powershell
npm start
```

You should see:
```
╔═══════════════════════════════════════╗
β•‘   Discord-Like Server Running     β•‘
β•‘                                       β•‘
β•‘    Local: http://localhost:3000    β•‘
β•‘    Status: Online & Ready          β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
```

## Step 6: Access the App

Open your browser and go to:
```
http://localhost:3000
```

## First Time Account Setup

1. **Click "Register"** (first time)
2. Enter:
   - Username (e.g., "john_doe")
   - Email (e.g., "john@example.com")
   - Password (minimum 6 characters)
3. Click "Create Account"
4. You're logged in! 

## Test the Features

### 1. Send Messages
- Type in the message box
- Press Enter to send
- Messages appear in real-time

### 2. Upload Media
- Click the attachment icon (πŸ“Ž)
- Select an image or video
- It appears in the chat

### 3. Profile
- Click profile icon (top right)
- Edit username and bio
- Click "Save Profile"

### 4. Friends
- Click Friends icon (πŸ‘₯)
- See online members
- Accept friend requests

### 5. Shop
- Click Shop icon (πŸͺ)
- Browse items for sale
- Buy with coins (1000 starting coins)
- Check inventory in profile

## Troubleshooting

### Port 3000 Already In Use
Change in `.env`:
```
PORT=8080
```

### MongoDB Connection Error
1. Make sure MongoDB is running
2. Check MONGODB_URI in .env is correct
3. If using local: `mongod` command starts it
4. If using Atlas: Check connection string has correct password

### App Won't Load
1. Check server is running (see console output)
2. Check localhost:3000 is being accessed
3. Press Ctrl+F5 to hard refresh browser
4. Check browser console (F12) for errors

### Can't Upload Files
1. Check file size < 50MB
2. Try PNG or JPG (not all formats supported)
3. Clear browser cache
4. Check file type (image/* or video/*)

## File Structure

```
πŸ“ message-app/
β”œβ”€β”€ πŸ“„ server.js          ← Backend (API & WebSockets)
β”œβ”€β”€ πŸ“„ client.js          ← Frontend JavaScript
β”œβ”€β”€ πŸ“„ index.html         ← Frontend HTML/CSS
β”œβ”€β”€ πŸ“„ package.json       ← Dependencies list
β”œβ”€β”€ πŸ“„ .env               ← Configuration (you create this)
β”œβ”€β”€ πŸ“„ init-db.js         ← Database initializer
β”œβ”€β”€ πŸ“„ SETUP-GUIDE.md     ← Detailed setup guide
β”œβ”€β”€ πŸ“„ FEATURES.md        ← Features documentation
└── πŸ“„ README.md          ← Original readme
```

## Command Reference

```powershell
npm install              
npm start                
npm run dev             
npm run init-db          
npm run https           
```

## Environment Variables

In `.env` file:
```env
PORT=3000                              # Server port
MONGODB_URI=mongodb://...              # Database URL
JWT_SECRET=your_secret_key             # JWT signature key
CORS_ORIGIN=*                          # Allowed origins
NODE_ENV=development                   # dev or production
```

## Next Steps

### To Customize:
1. Edit colors in `index.html` (CSS variables in :root)
2. Add more channels in `client.js` (showChannel function)
3. Add more shop items (modify init-db.js)
4. Change server name: Edit sidebar header in HTML

### To Deploy:
1. Use Heroku, Railway, or Render
2. Set environment variables in hosting platform
3. Use MongoDB Atlas (not local)
4. Add HTTPS certificates
5. Update CORS_ORIGIN to your domain

### To Extend:
- Add direct messaging
- Add voice/video (WebRTC)
- Add message reactions
- Add roles and permissions
- Add server administration

## Getting Help

1. Check SETUP-GUIDE.md for detailed instructions
2. Check FEATURES.md for feature list
3. Check browser console (F12) for errors
4. Check server console output
5. Try resetting browser cache (Ctrl+Shift+Delete)

---

**Enjoy your Discord-like chat application! πŸŽ‰**