File-based Environment Configuration in Firebase

Learn to set and retrieve environment variables in Firebase.

Environment variables are variables made up of name-value pairs used to configure values inside an application’s code from outside the code. They can affect the behavior of running processes on a computer or operating system.

When running Cloud Functions, well often need to include additional configuration required by functions such as API keys, client secrets, and so on. The Firebase SDK for Cloud Functions offers a built-in environment configuration to make it easy to store and retrieve this type of data for our projects. We can choose between using a runtime environment configuration with the Firebase CLI or a file-based configuration of these variables.

File-based configuration

The Firebase SDK for Cloud Functions supports the .env file format for loading environment variables into the process.env interface, where our application reads them. To do this, we must create the .env file containing our desired variables and include it in the functions/ directory on our Firebase project:

Get hands-on with 1200+ tech skills courses.