Challenge - 5 Problems
Firebase Environment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Firebase environment variable usage in functions
You have set an environment variable in Firebase Functions using
firebase functions:config:set api.key="12345". What will be the output of the following code snippet when deployed and called?exports.getApiKey = functions.https.onRequest((req, res) => { res.send(process.env.api.key || 'No key');});Firebase
exports.getApiKey = functions.https.onRequest((req, res) => { res.send(process.env.api.key || 'No key');});Attempts:
2 left
💡 Hint
Firebase environment variables are accessed differently than process.env.
✗ Incorrect
Firebase Functions environment variables set via 'firebase functions:config:set' are accessed using 'functions.config()', not 'process.env'. So 'process.env.api.key' is undefined, resulting in the fallback 'No key'.
❓ Configuration
intermediate2:00remaining
Correct Firebase environment variable access
Given you set an environment variable with
firebase functions:config:set service.id="abc123", which code snippet correctly retrieves this value inside a Firebase Function?Attempts:
2 left
💡 Hint
Firebase environment config is accessed via a function call.
✗ Incorrect
The correct way is to call 'functions.config()' which returns the config object. Accessing 'service.id' is done with 'functions.config().service.id'.
❓ Architecture
advanced2:00remaining
Managing multiple Firebase environments
You want to deploy your Firebase project to both staging and production environments with different environment variables. Which approach best supports this?
Attempts:
2 left
💡 Hint
Consider isolation and safety of production data.
✗ Incorrect
Using separate Firebase projects for staging and production ensures isolation of data and environment variables, reducing risk of accidental changes.
❓ security
advanced2:00remaining
Protecting sensitive environment variables in Firebase
Which practice best protects sensitive environment variables like API keys in Firebase Functions?
Attempts:
2 left
💡 Hint
Think about where environment variables should live and visibility.
✗ Incorrect
Firebase Functions config is encrypted and not exposed to clients. Hardcoding or storing in Firestore risks exposure.
✅ Best Practice
expert3:00remaining
Automating environment config deployment in CI/CD
You want to automate deployment of Firebase Functions with environment variables in a CI/CD pipeline. Which method ensures environment variables are correctly set during deployment?
Attempts:
2 left
💡 Hint
Think about how to keep environment variables in sync with deployment automatically.
✗ Incorrect
Running 'firebase functions:config:set' in the pipeline ensures environment variables are set in the correct project before deploying functions.