DEV Community

Mary Gathoni
Mary Gathoni

Posted on • Edited on

6 5

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 🙂

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay