Environment variables
Environment variables hold values that change by environment or must stay outside source code. Keep database credentials, auth secrets, provider tokens, and server-side Apso API keys outside the repository.
Local development
Use the generated project’s .env file for local service configuration:
DATABASE_TYPE=pglite
DATABASE_SYNC=true
APP_PORT=3100
BETTER_AUTH_SECRET=replace-with-a-long-random-value
STRIPE_SECRET_KEY=replace-with-a-test-keyAdd .env to .gitignore. Commit an .env.example with names and harmless sample values so another developer knows what the service requires.
DATABASE_TYPE=pglite
DATABASE_SYNC=true
APP_PORT=3100
BETTER_AUTH_SECRET=
STRIPE_SECRET_KEY=Hosted services
For a deployed hosted service:
- Open the service in Apso Cloud .
- Select Environment.
- Click Add Variable.
- Enter an uppercase key, its value, and whether the value is secret.
- Save the variable.
- Click Apply Changes to synchronize pending changes to the running service.
Environment changes also apply during a later deployment. Editing or deleting a variable creates another pending change until it is applied.
The CLI does not provide apso env commands. Manage hosted variables in the service Environment view and local variables in the generated .env file.
Variable classes
| Class | Examples | Handling |
|---|---|---|
| Local service configuration | APP_PORT, DATABASE_TYPE | Store in local .env; include the name in .env.example. |
| Hosted configuration | Feature toggles, provider URLs | Add in the Environment view and apply the change. |
| Secret | BETTER_AUTH_SECRET, STRIPE_SECRET_KEY | Mark as secret and do not log or expose it to a client bundle. |
| Frontend public value | Public API base URL | Use the frontend framework’s public variable convention only when the value is safe to expose. |
Access values in code
TypeScript
const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
if (!stripeSecretKey) {
throw new Error('STRIPE_SECRET_KEY is required');
}Python
import os
stripe_secret_key = os.environ["STRIPE_SECRET_KEY"]Go
stripeSecretKey := os.Getenv("STRIPE_SECRET_KEY")
if stripeSecretKey == "" {
log.Fatal("STRIPE_SECRET_KEY is required")
}Frontend boundaries
An Apso service API key is a server credential. Store it in a Next.js server environment and use it from Server Components, Server Actions, or route handlers. Do not place it in NEXT_PUBLIC_*, Vite VITE_*, React Native application code, or Flutter assets.
For browser and mobile clients, use a BFF or a user-scoped authentication token with the generated REST API.
Change workflow
- Add the variable name to
.env.example. - Configure a development value locally.
- Read it from an extension or framework configuration module.
- Add the hosted value in the Environment view.
- Apply the pending change or deploy the service.
- Exercise the affected endpoint and inspect logs without printing the secret.
Rotation
For a provider credential or auth secret:
- Create the replacement at the provider.
- Update the local or hosted value.
- Apply the hosted change.
- Verify the dependent workflow.
- Revoke the old credential at the provider.