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

# convex env

> Set and view environment variables on your deployment

The `convex env` command allows you to manage environment variables on your Convex deployment. Environment variables are accessible in your Convex functions via `process.env`.

## Subcommands

* `convex env set` - Set environment variables
* `convex env get` - Print a variable's value
* `convex env list` - List all environment variables
* `convex env remove` - Unset an environment variable

## Set command

Set environment variables on your deployment.

### Usage

```bash theme={null}
npx convex env set <name> [value] [options]
npx convex env set --from-file <file> [options]
```

### Arguments

<ParamField path="name" type="string">
  Name of the environment variable to set.

  Optional when using `--from-file`.
</ParamField>

<ParamField path="value" type="string">
  Value to set. If omitted, you'll be prompted to enter it interactively.
</ParamField>

### Options

<ParamField path="--from-file" type="string">
  Read environment variables from a `.env` file.

  Without `--force`, fails if any existing variable has a different value.
</ParamField>

<ParamField path="--force" type="boolean">
  When setting multiple variables, overwrite existing environment variable values instead of failing on mismatch.
</ParamField>

### Examples

#### Set a single variable

Set a variable with a value:

```bash theme={null}
npx convex env set API_KEY "sk_live_abc123"
```

#### Set interactively

Set a variable and be prompted for the value:

```bash theme={null}
npx convex env set API_SECRET
# You'll be prompted to enter the value
```

#### Set from file

Set multiple variables from a `.env` file:

```bash theme={null}
npx convex env set --from-file .env.production
```

#### Force overwrite

Overwrite existing values when importing from file:

```bash theme={null}
npx convex env set --from-file .env.production --force
```

#### Set from stdin

Read value from stdin:

```bash theme={null}
echo "secret_value" | npx convex env set API_KEY
```

#### Set on production

Set a variable on your production deployment:

```bash theme={null}
npx convex env set API_KEY "sk_live_abc123" --prod
```

## Get command

Print an environment variable's value.

### Usage

```bash theme={null}
npx convex env get <name>
```

### Arguments

<ParamField path="name" type="string" required>
  Name of the environment variable to retrieve.
</ParamField>

### Examples

```bash theme={null}
npx convex env get API_KEY
```

## List command

List all environment variables on your deployment.

### Usage

```bash theme={null}
npx convex env list
```

### Examples

List all environment variables:

```bash theme={null}
npx convex env list
```

List variables on production:

```bash theme={null}
npx convex env list --prod
```

## Remove command

Unset an environment variable from your deployment.

### Usage

```bash theme={null}
npx convex env remove <name>
```

### Aliases

* `convex env rm`
* `convex env unset`

### Arguments

<ParamField path="name" type="string" required>
  Name of the environment variable to remove.
</ParamField>

### Examples

Remove a variable:

```bash theme={null}
npx convex env remove API_KEY
```

Remove from production:

```bash theme={null}
npx convex env remove OLD_CONFIG --prod
```

## Deployment selection

All `convex env` subcommands support deployment selection:

* `--prod` - Target production deployment
* `--preview-name <name>` - Target a preview deployment
* `--url <url>` - Target a specific deployment URL
* `--admin-key <key>` - Admin key for authentication

By default, commands target your dev deployment.

## Environment variable format

When using `--from-file`, the file should follow the `.env` format:

```bash theme={null}
# Comments are allowed
API_KEY=sk_live_abc123
DATABASE_URL=postgresql://localhost/mydb
FEATURE_FLAG=true

# Multi-line values use quotes
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQ...
-----END PRIVATE KEY-----"
```

## Best practices

1. **Never commit secrets** - Don't commit `.env` files with secrets to version control
2. **Use different values per environment** - Production and dev should have separate API keys
3. **Set in CI/CD** - Use `convex env set` in deployment pipelines to configure production
4. **Validate on startup** - Check for required environment variables in your backend initialization code

## Security

Environment variables are:

* Encrypted at rest
* Only accessible to your Convex functions
* Not exposed in client-side code
* Transmitted securely over HTTPS

Values are shown in the Convex dashboard but can be marked as sensitive to hide them from unauthorized team members.
