- Documentation
- Services
- Environment Variables
Environment Variables
Environment variables let you configure your application without changing the code. Use them to store database URLs, API keys, runtime settings, and other values that may vary between environments.
Managing environment variables
Adding variables
- Go to the service page in the dashboard
- Navigate to the Environment Variables tab
- Click Add Variable
- Enter the name (key) and the value
- Click Save
You can add as many variables as you need. Each variable is injected as an environment variable into your application’s container.
Editing variables
To edit an existing variable, click the edit icon next to it, change the value, and save. The previous value will no longer be accessible after editing.
Removing variables
To remove a variable, click the delete icon and confirm the action. The variable will be removed from the container on the next deployment.
Secret masking
Sensitive values are automatically masked in the dashboard after being saved. This means that after you set a variable, the full value will no longer be displayed in the interface. You can replace the value at any time, but you cannot view the current value.
This protects secrets like API keys and database passwords from accidental exposure.
Common patterns
Here are some commonly used environment variables:
| Variable | Example | Usage |
|---|---|---|
DATABASE_URL | postgresql://user:pass@host:5432/db | Database connection |
API_KEY | sk-abc123def456 | External service API key |
NODE_ENV | production | Runtime environment (Node.js) |
PORT | 3000 | Application port |
SECRET_KEY | my-secret-key | Encryption/token key |
Platform-injected variables
Guara Cloud automatically injects a set of environment variables into every service. You do not need to create these manually.
| Variable | Example | Description |
|---|---|---|
PORT | 3000 | The port your service should listen on |
GUARA_SERVICE_NAME | my-api-a3f2c1 | The service slug (internal identifier) |
GUARA_PROJECT_NAME | my-project | The project slug |
GUARA_ENVIRONMENT | production | The runtime environment |
Service discovery variables
When your project has multiple services, Guara Cloud automatically injects environment variables so each service can discover and communicate with its siblings. These variables use the service name as a prefix, making them intuitive and predictable.
For each sibling service, three variables are injected:
| Variable | Format | Description |
|---|---|---|
{SERVICE_NAME}_HOST | {slug}.{namespace}.svc.cluster.local | Internal hostname of the sibling |
{SERVICE_NAME}_PORT | 3000 | Port the sibling listens on |
{SERVICE_NAME}_URL | http://{slug}.{namespace}.svc.cluster.local:3000 | Full URL to reach the sibling |
The {SERVICE_NAME} prefix is derived from the sibling’s name: uppercased, with spaces and hyphens replaced by underscores.
Example
Suppose your project has three services:
- My API (port 8080)
- My Worker (port 3000)
- Redis Cache (port 6379)
The My API service will automatically receive:
# Discovery vars for "My Worker"
MY_WORKER_HOST=my-worker-b4d3e2.proj-myapp.svc.cluster.local
MY_WORKER_PORT=3000
MY_WORKER_URL=http://my-worker-b4d3e2.proj-myapp.svc.cluster.local:3000
# Discovery vars for "Redis Cache"
REDIS_CACHE_HOST=redis-cache-c5e6f7.proj-myapp.svc.cluster.local
REDIS_CACHE_PORT=6379
REDIS_CACHE_URL=http://redis-cache-c5e6f7.proj-myapp.svc.cluster.local:6379
You can use these variables directly in your application code:
// Node.js example
const workerUrl = process.env.MY_WORKER_URL;
const response = await fetch(`${workerUrl}/tasks`);
# Python example
import os
worker_url = os.environ["MY_WORKER_URL"]
Best practices
- Never put secrets in source code. Use environment variables to store sensitive values.
- Use descriptive names. Prefer
DATABASE_URLoverDBfor easier maintenance. - Separate by environment. Use different values for development and production.
- Review periodically. Remove variables that are no longer in use.