# Publish EnerTek on Truehost — enerteksolarservices.com

This package is ready for Truehost cPanel **Setup Node.js App**. It includes the catalog, photos, and SQLite database. Do **not** upload `node_modules` or your local `.env`.

---

## 1. Point the domain at Truehost

If the domain and hosting are **both** at Truehost, skip this step.

Otherwise, in the registrar for **enerteksolarservices.com**, set nameservers to the values in your Truehost welcome email or **cPanel → Account Information**. Truehost often uses:

```text
ns1.cloudoon.com
ns2.cloudoon.net
ns3.cloudoon.org
```

Wait until `https://www.whatsmydns.net/#NS/enerteksolarservices.com` shows those nameservers.

In cPanel → **Domains**, confirm `enerteksolarservices.com` exists. Add `www.enerteksolarservices.com` as an alias if it is missing.

---

## 2. Upload this zip

1. Log in to cPanel → **File Manager**.
2. Go **up** from `public_html` to `/home/USERNAME/`.
3. Create a folder named `enertek-solar`.
4. Upload `enerteksolarservices-truehost.zip` into that folder and **Extract**.
5. You should have `/home/USERNAME/enertek-solar/app.js` (not buried in an extra subfolder). If extract created `enertek-solar/enertek-solar/`, move the inner files up one level.

Keep the app **outside** `public_html`. Truehost’s Node.js selector will wire the domain to it.

---

## 3. Create `.env` on the server

In File Manager, inside `enertek-solar/`, copy `.env.example` to `.env` and edit:

```text
NODE_ENV=production
SITE_URL=https://enerteksolarservices.com
SESSION_SECRET=paste-a-long-random-string-here
ADMIN_USERNAME=admin
ADMIN_PASSWORD=your-new-strong-password
```

Leave `PORT` out of `.env` if the Node.js selector shows its own port — the panel injects `PORT` automatically.

Generate a secret (any long random text is fine), for example in cPanel Terminal:

```bash
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
```

This zip already contains the product database. `ADMIN_PASSWORD` in `.env` is **not** applied to that existing admin row. After the site is up, log in with the current local admin password and change it immediately under **Admin → Security**.

---

## 4. Setup Node.js App

cPanel → **Software → Setup Node.js App** → **Create Application**:

```text
Node.js version          : 20.x (or 18.x)
Application mode         : Production
Application root         : enertek-solar
Application URL          : enerteksolarservices.com
Application startup file : app.js
```

Add environment variables in that same screen (same values as `.env`):

```text
NODE_ENV=production
SITE_URL=https://enerteksolarservices.com
SESSION_SECRET=the-same-secret-as-.env
```

Click **Create**. Open the app → **Run NPM Install**. Wait until it finishes. This compiles `better-sqlite3` for Linux — Windows `node_modules` will not work here.

Then **Start** / **Restart** the app.

---

## 5. HTTPS

cPanel → **SSL/TLS Status** → tick `enerteksolarservices.com` and `www` → **Run AutoSSL**.

cPanel → **Domains** → enable **Force HTTPS Redirect** for the domain.

Visit `https://enerteksolarservices.com` — you should see the EnerTek storefront with catalog photos.

---

## 6. First login (required)

1. Open `https://enerteksolarservices.com/admin/login`
2. Sign in with the existing admin account from this package.
3. Go to **Admin → Security** and set a new password before sharing the URL.

If login fails with “Form expired”, AutoSSL is not active yet and secure cookies need HTTPS. Finish step 5, then try again.

---

## 7. Daily backup (cPanel Cron)

```bash
mkdir -p $HOME/backups
cp $HOME/enertek-solar/data/enertek.db $HOME/backups/db-$(date +\%F).db
```

Also download `public/uploads/` occasionally (logo + catalog photos).

---

## Updating later

Upload changed files over the same folder. **Do not overwrite** `.env` or `data/enertek.db` unless you intend to replace the live catalog. Then **Restart** the Node.js app.

---

## Troubleshooting

| Problem | What to do |
|---|---|
| App will not start | Node.js App → **Error Log**. Missing `SESSION_SECRET` is the usual cause. |
| NPM install fails on sqlite | cPanel Terminal: enter the virtualenv command shown on the Node.js App page, `cd ~/enertek-solar`, then `npm install --build-from-source`. |
| CSS/images missing | Confirm `public/css` and `public/uploads/catalog` extracted. Folder permissions 755, files 644. |
| Domain does not resolve | Nameservers (step 1) have not propagated. |
| Login cookie problems | Finish AutoSSL + Force HTTPS, then restart the app. |
| Port already in use | Remove `PORT` from `.env` and use the port assigned by Setup Node.js App. |

`ops/nginx.conf` is only for a VPS. On Truehost shared hosting, skip it and use Setup Node.js App.
