Skip to main content

What are environment variables?

Environment variables are persistent variables that are available across your entire workspace. Typically, these are used to store things like external API keys or other sensitive information that you need to use across multiple function stacks, without storing it in a database table. Environment variables can be read in any logic or workflow, but they can not be modified from anywhere but this settings panel, so it’s best to only use them for things that you don’t need to change often.

Adding Environment Variables

Click the icon in the upper-right corner to open Settings. On the next screen, click ‘Manage’ to edit your environment variables.
environment-variables-20251013-085352
Click ’+ Add Variable’ at the bottom of the panel that opens to add a new variable. Give your environment variable a name that you can easily recognize; this is how you’ll identify it when calling it in function stacks. Then, supply the value. Values can span multiple lines, which is useful for things like PEM-encoded private keys or certificates — paste the whole block in and the line breaks are preserved. Reading a value through $env removes whitespace from its start and end, including a final line break; see Leading and trailing whitespace.
environment-variables-20251013-085442

Using Environment Variables

Environment variables are available in any logic or workflow from a value dropdown under ENV.
environment-variables-20251013-085918

Leading and trailing whitespace

The two ways of reading a variable treat whitespace differently.
  • $env.NAME, which is what the ENV dropdown uses, removes whitespace from both ends of the value: spaces, tabs, line breaks (\n and \r), vertical tabs and NUL characters. Line breaks inside the value are kept, and other characters, such as a non-breaking space, are kept too. A value that is only whitespace reads as an empty string. This forgives a key pasted with a stray space or newline. The variable’s name is trimmed the same way.
  • Get Environment Variables (util.get_env in XanoScript) returns every value exactly as it was saved, with nothing removed.
A PEM key usually ends with a line break. Saved that way, it reads two ways:
$pem_trimmed is the same key without its final line break. Read the value with util.get_env when the exact bytes matter: when you hash or sign the value itself, compare it byte for byte, or pass it to a system that requires the trailing newline, such as OpenSSH, which will not load a key in its own BEGIN OPENSSH PRIVATE KEY format without it.

Xano-generated Environment Variables

Xano maintains several environment variables you can use.