DEV Community

Mary Gathoni
Mary Gathoni

Posted on • Updated on

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 😁

Top comments (3)

Collapse
 
tombohub profile image
tombohub

Do you know how to use it locally?

Collapse
 
jeeali profile image
Sharjeel Ali

Quick Solution, Thanks 🔥

Collapse
 
gathoni profile image
Mary Gathoni

You're welcome 🙂