Why can't I use ENV variables with Firebase functions

Viewed 3335

Why can't I use env variables as I would with Google Cloud Functions? As I understand, Firebase functions sit on top of Google Cloud. With Firebase functions you can use environment configuration but is not the same.

I have done both implementations but I find it easier to work with environment variables with google cloud functions.

Maybe I just don't know how to do it and I can't find any documentation, so if someone can point me in the right direction I will appreciate it. If there are any advantages of doing it the firebase functions way let me know.

Google cloud functions env docs

Firebase functions config env docs

2 Answers

The Firebase CLI manages the process environment variables for deployed functions. It does not offer a way to change or override that management, other than modifying its source code to do what you want.

To store environment data for Firebase functions, you can use the firebase functions:config:set command in the Firebase CLI. Each key can be namespaced using periods to group related configuration together. Keep in mind that only lowercase characters are accepted in keys; uppercase characters are not allowed.

For instance, to store the Client ID and API key for "Some Service", you might run:

firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"

To inspect what's currently stored in environment config for your project, you can use firebase functions:config:get. It will output JSON something like this:

{
  "someservice": {
    "key":"THE API KEY",
    "id":"THE CLIENT ID"
  }
}
Related