How to set config variables in Firebase Cloud Functions


firebase cloud functions cloud

Assume, you have a Firebase project with Cloud Functions and Firebase CLI.

Set config

To set the config (environment) you need to run the following command in the project’s folder:

firebase functions:config:set <key>=<value>

For example:

firebase functions:config:set youtube.key="AIzaSyAaNK8gBK7dTtMuSrNSozNTiiy5-02fIof”

Set environment variable in Firebase CLI

Get config

We can check the existing environment config by running:

firebase functions:config:get

Let us say:

The result of functions:config:get

The usage

In order to get the adjusted config in the cloud function, we need to import the firebase-functions and run the config method. I.e:

const config = functions.config();

const youtube = google.youtube({
    version: "v3",
    auth: config.youtube.key,
});
comments powered by Disqus