Environment variables
velixir injects environment variables into your app's pod at start-up. You set them per app from the dashboard, the CLI or the API, and they're applied on the next deploy.
Setting a variable
From the app's Environment tab:
- Enter a key (
DATABASE_URL,STRIPE_API_KEY, anything matching^[A-Za-z_][A-Za-z0-9_]*$). - Enter a value.
- Tick Treat as secret if it's something you don't want shown back in the UI.
- Click Save.
Setting a key that already exists replaces its value. No separate "edit" step.
Importing a .env file
Moving an app from another host, or from your laptop? Paste the whole file into Import from a .env file on the Environment tab. It reads KEY=value lines, an optional export prefix, comments, blank lines, and quoted values, including double-quoted values that run over several lines (PEM keys). That covers a local .env, the output of heroku config -s and railway variables --kv, and variables copied from a Render service. JSON works too: a flat object (Railway's Raw Editor) or the list az webapp config appsettings list prints. Railway references like ${{Postgres.DATABASE_URL}} are refused with a message, since they aren't values.
- It's all or nothing: if a line can't be read, nothing is saved and you're told which line.
- Keys that already exist are replaced. An existing secret stays secret.
PORTand the other variables velixir sets itself (listed below) are skipped, because aPORTcopied from another host would stop your app receiving traffic.
From the CLI
velixir env # list (secrets are masked)
velixir env set API_URL=https://api.example.com
velixir env set STRIPE_KEY=sk_live_... --secret
velixir env unset OLD_FLAG
velixir env import .env --secret # or pipe: heroku config -s -a my-app | velixir env import -
Add --redeploy to any of these to redeploy the app afterwards. The same operations are on the API under /api/v1/apps/{id}/env (see the API reference).
Variables your build needs
Most variables are read while your app runs. Some frameworks read them earlier, while they build, and copy the value into the output: Vite (VITE_*), Next.js (NEXT_PUBLIC_*), Create React App (REACT_APP_*), Nuxt (NUXT_PUBLIC_*), SvelteKit and Astro (PUBLIC_*), Expo (EXPO_PUBLIC_*), Gatsby (GATSBY_*) and Vue CLI (VUE_APP_*). That's how the apps Lovable, Bolt and v0 export find their Supabase URL or API address. If the value isn't there at build time, the build still succeeds, but the page can't reach its backend.
Mark those variables Also use at build and velixir passes them to the build as well as to the running app. New keys with the prefixes above are marked for you, including on a .env import. Use Use at build / Runtime only on a variable's row to change it.
velixir env set VITE_SUPABASE_URL=https://abc.supabase.co # used at build automatically
velixir env set API_BASE=https://api.example.com --build # any other key, explicitly
velixir env set VITE_DEBUG=1 --runtime-only # opt a prefixed key out
velixir rebuild # apply build values now
On the API, send "availableAtBuild": true or false with a set or import, or leave it out for the defaults above, and POST /api/v1/apps/{id}/rebuild to rebuild.
Rebuild after changing one. A redeploy restarts the image you already built, and a build value is inside that image, so it keeps the old one. When the build values differ from the ones your live release was built with, the Environment tab offers Rebuild now, and --redeploy (or "redeploy": true on the API) rebuilds instead of redeploying. A rebuild builds the source you're running again, from our copy of it, and deploys the result to the same slot.
Never a secret. A build value is saved in the image, and for the frameworks above it ends up in the JavaScript every visitor downloads. So a secret can't be used at build: velixir refuses it. That's fine for a Supabase URL and its anon key, which are designed to be public. A service-role key, a Stripe secret key or a database password stays a runtime-only secret, read by your server code.
Build variables can't contain line breaks or use names velixir's build uses itself (NIXPACKS_*, VELIXIR_*, PORT), and an app can have up to 100 of them.
Secrets vs plain values
- Plain values are stored as you typed them and shown back in the UI. Use these for non-sensitive config: feature flags, hostnames, environment names.
- Secrets are encrypted at rest with ASP.NET Core DataProtection (the same key infrastructure that signs cookies and antiforgery tokens). The UI shows
••••••••instead of the value; to change a secret you set the key again with a new value.
Both kinds reach your pod as ordinary environment variables, so your code reads them however your language normally does. Nothing velixir-specific is required.
Reading them from your code
Environment variables are read the standard way in every language, no velixir SDK required:
// Node.js
const dbUrl = process.env.DATABASE_URL;
const port = process.env.PORT;
// .NET
var dbUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
var port = Environment.GetEnvironmentVariable("PORT");
We also set some platform-managed vars automatically:
PORT- the port your app must listen on. This is the one variable every app has to honour, whatever language it's written in: bind your web server to it on0.0.0.0. It's 8080 unless you change it under Scaling → Runtime.VELIXIR_APP_ID,VELIXIR_APP_SLUG- identifiers your app can log or report.VELIXIR_VOLUME_PATH- where the app's volume is mounted, on apps that have one. See Volumes.
We also set the ASP.NET Core equivalents on every app, so a lift-and-shift .NET app runs with no code changes:
ASPNETCORE_URLS- bound to the same port asPORT.ASPNETCORE_HTTP_PORTS- the same port.ASPNETCORE_ENVIRONMENT-Production.
If you provision a managed database or cache inside the same project and link it to your app, we also inject a connection string for it automatically (see Postgres databases / Valkey caches).
Production and preview values
A variable applies everywhere unless you say otherwise. Choose Production only for a value pull request previews must never see (a live payment key, an admin token), and Pull request previews only for the value previews should use instead. A key can have both: STRIPE_KEY set to your live key for production and your test key for previews is two entries, and each app gets the right one.
From the CLI, add --production or --previews to velixir env set; the API takes "scope": "production" or "preview". velixir env unset KEY removes every value of the key.
Applying changes
Setting or deleting an env var doesn't auto-redeploy. The Environment tab shows a banner reminding you to redeploy - running pods keep their original values until they're rolled over. Hit Deploy on the latest release (or push a new one) to apply changes, or pass --redeploy from the CLI.
Environment variables reach your app when it runs, not while it's built. If your build step needs a value (a NEXT_PUBLIC_* variable baked into a frontend bundle, for example), commit it to the build config or read it at runtime instead.
Limits
- Keys: max 200 characters, must match
^[A-Za-z_][A-Za-z0-9_]*$. - Values: max 4000 characters, line breaks included. Secrets grow when encrypted, so keep a secret under about 2,600 characters. For larger blobs (big JSON config), put the blob in object storage and store the URL here.
- An import can hold up to 500 variables.