> ## Documentation Index
> Fetch the complete documentation index at: https://dos.dzaleka.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment Variables

> Configure environment variables for Dzaleka Online Services

Environment variables are used to configure sensitive data and environment-specific settings without hardcoding them into your application.

## Overview

Dzaleka Online Services uses environment variables for:

* Email service configuration (Resend API)
* Deployment adapter selection
* SSL/TLS certificates (optional)
* Server configuration

## Required Variables

These environment variables are required for full functionality:

### RESEND\_API\_KEY

**Required for**: Email notifications from Netlify functions

**Used in**:

* `netlify/functions/submit-voice.ts:4`
* `netlify/functions/submit-store.ts:4`
* `netlify/functions/submit-marketplace.ts:4`
* `netlify/functions/submit-course.ts:4`
* `netlify/functions/send-feedback-confirmation.ts:4`
* `netlify/functions/send-booking-confirmation.ts:4`

**Description**: API key for [Resend](https://resend.com) email service, used to send submission notifications and confirmations.

**How to obtain**:

1. Sign up for a Resend account at [https://resend.com](https://resend.com)
2. Navigate to API Keys in your dashboard
3. Create a new API key
4. Copy the key (it will only be shown once)

```bash theme={null}
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

## Optional Variables

These variables are optional and provide additional functionality:

### NETLIFY

**Used in**: `astro.config.mjs:15`

**Description**: Automatically set by Netlify during deployment. When present, the Netlify adapter is used instead of the Node.js adapter.

```bash theme={null}
NETLIFY=true
```

<Note>
  You don't need to set this manually. Netlify automatically provides this variable during builds.
</Note>

### PORT

**Used in**: `dist/server/entry.mjs:1317`

**Description**: Port number for the production server when using Node.js adapter. Defaults to 8080 if not specified.

```bash theme={null}
PORT=8080
```

### HOST

**Used in**: `dist/server/entry.mjs:1321`

**Description**: Host address for the production server when using Node.js adapter.

```bash theme={null}
HOST=0.0.0.0
```

### SERVER\_CERT\_PATH & SERVER\_KEY\_PATH

**Used in**: `dist/server/entry.mjs:1261,1264,1265`

**Description**: Paths to SSL/TLS certificate and key files for HTTPS support in standalone Node.js mode.

```bash theme={null}
SERVER_CERT_PATH=/path/to/cert.pem
SERVER_KEY_PATH=/path/to/key.pem
```

<Warning>
  These are only needed for self-hosted deployments with HTTPS. Netlify handles SSL automatically.
</Warning>

### ASTRO\_NODE\_AUTOSTART

**Used in**: `dist/server/entry.mjs:1361`

**Description**: Controls whether the Node.js server starts automatically. Set to `disabled` to prevent auto-start.

```bash theme={null}
ASTRO_NODE_AUTOSTART=disabled
```

## Example .env File

Create a `.env` file in the root directory:

```bash title=".env" theme={null}
# Required
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Optional - Only for self-hosted deployments
# PORT=8080
# HOST=0.0.0.0

# Optional - Only for HTTPS in standalone mode
# SERVER_CERT_PATH=/path/to/cert.pem
# SERVER_KEY_PATH=/path/to/key.pem
```

## Setting Environment Variables in Netlify

For production deployments on Netlify:

<Steps>
  ### Navigate to Site Settings

  1. Go to your Netlify dashboard
  2. Select your site
  3. Click on **Site settings**

  ### Add Environment Variables

  1. Navigate to **Environment variables** in the sidebar
  2. Click **Add a variable**
  3. Enter the variable name and value
  4. Select the appropriate scopes (Production, Deploy Previews, Branch deploys)
  5. Click **Create variable**

  ### Add RESEND\_API\_KEY

  Add your Resend API key:

  * **Key**: `RESEND_API_KEY`
  * **Value**: Your Resend API key (starts with `re_`)
  * **Scopes**: Production, Deploy Previews (recommended)

  ### Redeploy

  After adding environment variables, trigger a new deployment:

  ```bash theme={null}
  git commit --allow-empty -m "Trigger rebuild"
  git push
  ```
</Steps>

<Note>
  Changes to environment variables in Netlify don't automatically trigger a rebuild. You need to manually redeploy.
</Note>

## Security Best Practices

<Warning>
  **Never commit `.env` files to version control!**
</Warning>

Follow these security practices:

1. **Add `.env` to `.gitignore`**:
   ```bash title=".gitignore" theme={null}
   .env
   .env.local
   .env.*.local
   ```

2. **Use `.env.example` for documentation**:
   Create a template file without sensitive values:
   ```bash title=".env.example" theme={null}
   RESEND_API_KEY=your_resend_api_key_here
   ```

3. **Rotate keys regularly**: Change API keys periodically and after any suspected compromise

4. **Use different keys for development and production**: Never use production API keys in development

5. **Limit key permissions**: Use API keys with minimum required permissions

## Validation

The Netlify functions include basic validation. If `RESEND_API_KEY` is missing, email sending will fail but won't crash the function:

```typescript theme={null}
try {
  await resend.emails.send({...});
} catch (emailError) {
  console.error('Error sending email:', emailError);
}
```

Check your Netlify function logs to verify emails are being sent successfully.

## Next Steps

<CardGroup cols={2}>
  <Card title="Netlify Deployment" icon="rocket" href="/deployment/netlify">
    Learn how to configure environment variables in Netlify
  </Card>

  <Card title="Configuration" icon="gear" href="/deployment/configuration">
    Explore Astro and Tailwind configuration options
  </Card>
</CardGroup>
