# Deploying Trade Community (Trading Bite) on a Namecheap cPanel VPS

This is a **Node.js** app (Express + JSON file storage). It is **not** a PHP/HTML
site, so you can't just drop it in `public_html`. You register it as a Node app and
cPanel/Passenger runs it behind your domain.

Your VPS has **root + WHM**, so everything below is possible even if a tool is missing.

---

## Path A — cPanel "Setup Node.js App" (recommended, easiest)

### 1. Prepare the upload
- Zip the project **excluding `node_modules`** (it's rebuilt on the server).
  Include: `server.js`, `package.json`, `public/`, `data/`, `uploads/`.
  You can also skip `data/backups/` if you don't need old snapshots.

### 2. Upload
- cPanel → **File Manager** → create a folder in your home dir, e.g. `apps/trade-community`
  (keep it **outside** `public_html`).
- Upload the zip there and **Extract**.

### 3. Create the Node app
- cPanel → **Setup Node.js App** → **Create Application**:
  - **Node.js version:** 18 or 20 (newest available)
  - **Application mode:** Production
  - **Application root:** `apps/trade-community`
  - **Application URL:** your domain or subdomain (e.g. `community.yourdomain.com`)
  - **Application startup file:** `server.js`
- **Create**.

### 4. Install dependencies + start
- On the app page click **Run NPM Install** (installs express + nodemailer).
- Click **Restart**. Open the Application URL — the app should load.

---

## Path B — via SSH (if "Setup Node.js App" is missing, you're root)

If WHM has no Node selector, either enable it or run it manually.

**Enable the tool (WHM):** WHM → EasyApache 4 → add `ea-nodejs` / enable
CloudLinux Node.js Selector, then use Path A.

**Or run it manually with PM2 + Apache reverse proxy:**
```bash
# as root over SSH
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
yum install -y nodejs        # (or dnf, depending on OS)
npm install -g pm2

cd /home/<cpaneluser>/apps/trade-community
npm install --production
PORT=3100 pm2 start server.js --name trading-bite
pm2 save && pm2 startup      # keeps it running after reboot
```
Then reverse-proxy your domain to `127.0.0.1:3100`. Easiest: in cPanel install
**Application Manager**, or add an Apache proxy via WHM → Include Editor, or put
nginx in front. (Ask and I'll give the exact proxy config for your setup.)

---

## After it's live — do these

1. **SSL / HTTPS:** cPanel → **SSL/TLS Status** → run **AutoSSL** on the domain.
   (Share links, OG previews, and phone push notifications need HTTPS.)
2. **Change the admin password.** Default is `admin@local` / `admin123` — log in and
   change it immediately. Don't leave that live.
3. **Email OTP:** edit `data/email.json` and put a **real Gmail App Password** in
   `pass` (16 chars, from Google Account → Security → App passwords). Restart the app.
   Without it, signups fall back to showing the code on screen.
4. **Folder permissions:** `data/` and `uploads/` must be **writable** (755). The app
   saves `db.json` and uploaded images there. **Back up `data/db.json` regularly** —
   it holds everything (members, trades, messages).
5. **DNS:** point your domain/subdomain's A record at the VPS IP (Namecheap → Domain →
   Advanced DNS).

---

## Notes / limits
- **Data store is a JSON file** (`data/db.json`). Fine for a community of this size;
  it is not built for thousands of simultaneous writers. Keep backups.
- **Don't upload `node_modules`** — always `npm install` on the server.
- **PORT is automatic** under cPanel/Passenger; the code already reads
  `process.env.PORT`. Only set PORT yourself in the manual PM2 path.
- **Restart after any file change** (Setup Node.js App → Restart, or `pm2 restart`).
