Skip to main content

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.

Set environment variables using the 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.

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 <your-env-file-path>

Depending on your project's structure - a fullstack single repository or dedicated repositories for backend and frontend - be careful to provide the correct path to the file:

--env .env or --env ./server/.env.

Use environment variables locally

When testing locally with genezio local, the environment variable are loaded by default without any prior flags.

For fullstack single repositories, the default path and name of the environment variables file will be:


For dedicated server repositories, the default path and name of the environment variables file will be:


If the file used to store environment variables has a different name or is located to a different path, you must provide the new name/localtion using the .env flag:

genezio local --env ./custom-path/.my-env

Note: There is no need for you to explicitly use the dotenv library in your code.

How to use the environment variables in your project

The environment variables used on the deployed environment are exported.

To access an environment variable use process.env.MY_VARIABLE

const myVariable = process.env.MY_VARIABLE;
console.log("Print environment variable", myVariable);

Note: There is no need to import specific libraries for loading environment variables (such as dotenv).genezio will implicitly load the .env file while testing locally.