Spaces:
Runtime error
Runtime error
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:
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
- Download MongoDB Community Edition: https://www.mongodb.com/try/download/community
- Install it (use default settings)
- MongoDB will start automatically
- Your connection string:
mongodb://localhost:27017/discord-app
Option B: MongoDB Atlas (Cloud)
- Go to https://www.mongodb.com/cloud/atlas
- Sign up for free account
- Create a cluster
- Click "Connect"
- Copy the connection string
- Replace
<password>with your password
Step 3: Configure Environment
- Edit the
.envfile in your project root:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/discord-app
JWT_SECRET=MySecretKey123!
- Replace
MONGODB_URIwith your MongoDB connection string
Step 4: Initialize Database (Optional)
Add sample shop items:
npm run init-db
This creates default shop items in your database.
Step 5: Start the Server
Development (with auto-reload):
npm run dev
Production:
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
- Click "Register" (first time)
- Enter:
- Username (e.g., "john_doe")
- Email (e.g., "john@example.com")
- Password (minimum 6 characters)
- Click "Create Account"
- 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
- Make sure MongoDB is running
- Check MONGODB_URI in .env is correct
- If using local:
mongodcommand starts it - If using Atlas: Check connection string has correct password
App Won't Load
- Check server is running (see console output)
- Check localhost:3000 is being accessed
- Press Ctrl+F5 to hard refresh browser
- Check browser console (F12) for errors
Can't Upload Files
- Check file size < 50MB
- Try PNG or JPG (not all formats supported)
- Clear browser cache
- 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
npm install
npm start
npm run dev
npm run init-db
npm run https
Environment Variables
In .env file:
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:
- Edit colors in
index.html(CSS variables in :root) - Add more channels in
client.js(showChannel function) - Add more shop items (modify init-db.js)
- Change server name: Edit sidebar header in HTML
To Deploy:
- Use Heroku, Railway, or Render
- Set environment variables in hosting platform
- Use MongoDB Atlas (not local)
- Add HTTPS certificates
- 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
- Check SETUP-GUIDE.md for detailed instructions
- Check FEATURES.md for feature list
- Check browser console (F12) for errors
- Check server console output
- Try resetting browser cache (Ctrl+Shift+Delete)
Enjoy your Discord-like chat application! π