0
0
Firebasecloud~20 mins

Environment configuration in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Environment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2: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');});
AIt will respond with 'undefined'
BIt will respond with '12345'
CIt will throw a runtime error because process.env.api.key is undefined
DIt will respond with 'No key'
Attempts:
2 left
💡 Hint
Firebase environment variables are accessed differently than process.env.
Configuration
intermediate
2: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?
Aconst serviceId = process.env.service.id;
Bconst serviceId = functions.config().service.id;
Cconst serviceId = functions.config.service.id;
Dconst serviceId = process.env.SERVICE_ID;
Attempts:
2 left
💡 Hint
Firebase environment config is accessed via a function call.
Architecture
advanced
2: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?
AUse separate Firebase projects for staging and production, each with its own environment config.
BStore all environment variables in one project and select them at runtime based on request headers.
CUse the same Firebase project and switch environment variables manually before each deploy.
DUse Firebase Emulator Suite to simulate different environments in production.
Attempts:
2 left
💡 Hint
Consider isolation and safety of production data.
security
advanced
2:00remaining
Protecting sensitive environment variables in Firebase
Which practice best protects sensitive environment variables like API keys in Firebase Functions?
AStore sensitive keys in Firebase Functions config and never commit them to source code.
BStore sensitive keys in Firestore database and read them at runtime.
CHardcode sensitive keys in your function code but restrict access to the repository.
DInclude sensitive keys in client-side code but obfuscate them.
Attempts:
2 left
💡 Hint
Think about where environment variables should live and visibility.
Best Practice
expert
3: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?
AStore environment variables in a .env file committed to the repository and load them during deploy.
BManually run 'firebase functions:config:set' on your local machine before pipeline runs.
CInclude 'firebase functions:config:set' commands in the pipeline before 'firebase deploy'.
DUse Firebase Hosting rewrites to inject environment variables at runtime.
Attempts:
2 left
💡 Hint
Think about how to keep environment variables in sync with deployment automatically.