NC

Naijacloud

Docs

DashboardStart free

Deploy

/

Environment variables

Environment variables

Variables are scoped to an environment, so a production value never leaks into development. Files your app needs to read from disk are handled separately, as secret files.

4 min read

Setting variables

Variables can be set when you create a service, and edited afterwards from its Variables tab. Each has a key, a value, and a scope.

The variables tab listing environment variables with masked secret values, and a secret files section

For a long list, the bulk editor accepts KEY=value lines pasted straight from a local .env file, which is faster than adding them one at a time.

Scoping

A variable is scoped either to one environment or to all environments:

ScopeVisible in
A single environmentOnly that environment
All environmentsdev, uat and prod

Scope to a single environment for anything that differs per stage, like a database URL, a payment key or a log level. Scope to all environments only for values that are genuinely identical everywhere.

i

Values are masked in the interface once saved. Reveal a value deliberately when you need it. We never print it in logs, though your own application can of course log it.

Changing a variable restarts the service

Saving a variable change restarts the service with the new value, because a process reads its environment once at startup.

!

Set the variable before you deploy the code that reads it. Deploying code that expects a variable that does not exist yet gives you a crash loop until the value lands.

Secret files

Some configuration is not a string. A service account JSON, a private key or a certificate chain all go in Secret files instead: you give a path and contents, and the file is written into the container at runtime.

Common secret file paths

.env credentials.json certs/client.pem

Contents are encrypted at rest and are not written into the built image, so they are not baked into anything you might later export.

Read them from your application the way you would read any file:

Reading a secret file

const creds = JSON.parse( await readFile(new URL('./credentials.json', import.meta.url), 'utf8'), );

Variables you get automatically

Some values are supplied for you:

Next steps