# Deploying the Backend to cPanel

This guide explains how to deploy the Hono/Node.js backend to a cPanel hosting environment.

## Prerequisites

- cPanel hosting with Node.js support (Node.js 20 or higher)
- SSH access to your cPanel server (recommended)
- The backend source code

## Step 1: Compile TypeScript to JavaScript

The backend is written in TypeScript. You must compile it to JavaScript before deploying to cPanel.

Run this command locally (or on Vibecode before downloading):

```bash
npm run build
```

This will create a `dist/` folder containing compiled JavaScript files. Upload this `dist/` folder to your server.

## Step 2: Upload Files to cPanel

Upload the following files and folders to your Node.js app directory on cPanel (e.g. `/home/username/myapp/`):

```
dist/           ← compiled JavaScript (from npm run build)
prisma/         ← Prisma schema and migrations
node_modules/   ← dependencies (or run npm install on server)
package.json
```

**Do NOT upload:**
- `src/` (source TypeScript - not needed in production)
- `.env` (set environment variables in cPanel instead)

## Step 3: Install Dependencies on cPanel

If you did not upload `node_modules/`, SSH into your server and run:

```bash
cd /home/username/myapp
npm install --omit=dev
```

Then generate the Prisma client:

```bash
npx prisma generate
```

## Step 4: Set Up the SQLite Database

Push the Prisma schema to create your SQLite database:

```bash
npx prisma db push
```

Make sure the `prisma/` directory is writable by the Node.js process.

Use an absolute path for `DATABASE_URL` to avoid path issues:

```
DATABASE_URL=file:/home/username/myapp/prisma/dev.db
```

## Step 5: Set Environment Variables in cPanel

In cPanel's Node.js App manager, add these environment variables:

| Variable | Value |
|----------|-------|
| `NODE_ENV` | `production` |
| `PORT` | `3000` (or the port cPanel assigns) |
| `DATABASE_URL` | `file:/home/username/myapp/prisma/dev.db` |
| `ALLOWED_ORIGIN` | `https://menefphub.com` |

For email features, also add:
- `SMTP_HOST`
- `SMTP_PORT`
- `SMTP_USER`
- `SMTP_PASS`
- `SMTP_FROM`

See `.env.cpanel.example` for a full list of available variables.

## Step 6: Set the Application Entry Point

In cPanel's Node.js App manager:

- **Node.js version**: 20.x or higher
- **Application startup file**: `dist/index.js`
- **Application root**: the folder where you uploaded the files

The start command is:

```bash
node dist/index.js
```

## Step 7: Start the Application

Click "Start" or "Restart" in cPanel's Node.js App manager.

Check the application logs in cPanel to confirm the server started without errors. You should see:

```
Server running on port 3000
```

## Notes

- **File uploads** (`/api/upload`) are not available in production (`NODE_ENV=production`). These require the Vibecode SDK which is only available on Vibecode.
- **SQLite** works fine on cPanel shared hosting — no external database needed.
- The `menefphub.com` domain is already whitelisted for CORS. If your domain is different, set the `ALLOWED_ORIGIN` environment variable.
- If you change the Prisma schema, re-run `npx prisma db push` on the server after uploading the new `dist/` files.
