Comment on page

Backend Environment Variables

This page describes how to set environment variables for your backend classes.
These variables can be either secrets such as database keys or 3rd party API keys, or variables to use globally across your backend classes.

How to set environment variables using genezio dashboard

To set environment variables in the backend classes, head to the Dashboard page of the project.
On the Backend tab, click on the Environment Variables button:
Add the environment variables like a <key, value> pair. After adding all the environment variables hit the Save button:
Note: You can also import environment variables from a file using Import from .env button.

How to set environment variables using genezio CLI

You can load your environment variables when deploying genezio in the CLI by appending the following flag:
genezio deploy --env .env

How to use the environment variables in your project

The environment variables used on the deployed environment are exported.
TypeScript
Dart
To access an environment variable use process.env.MY_VARIABLE
main.ts
1
const myVariable = process.env.MY_VARIABLE;
2
console.log('Print environment variable', myVariable);
To access an environment variable use Platform.environment['MY_VARIABLE']
main.dart
1
import 'dart:io';
2
3
void main() {
4
my_variable = Platform.environment['MY_VARIABLE'];
5
print(my_variable);
6
}
Note: There is no need to import specific libraries for loading environment variables (such as dotenv), genezio loads them for you.