Firebase: Set and access environment variables

gathoni

Mary Gathoni

Posted on May 22, 2020

Firebase: Set and access environment variables

Its never a good idea to have sensitive data like API keys in plain site.
Firebase cloud functions provide a way to set and access env variables.

Set env variable

firebase functions:config:set my.secret='giraffes are cool'
Enter fullscreen mode Exit fullscreen mode

Note that each config value must have a 2-part key (e.g. foo.bar) otherwise it will fail.

Deploy your functions for the change to take effect

firebase deploy --only functions
Enter fullscreen mode Exit fullscreen mode

Access env variable

const secret = firebase.config().my.secret
Enter fullscreen mode Exit fullscreen mode

Now you know 😁

πŸ’– πŸ’ͺ πŸ™… 🚩
gathoni
Mary Gathoni

Posted on May 22, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related