Bird
Raised Fist0
Firebasecloud~20 mins

Environment configuration in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of environment configuration in Firebase functions?
easy
A. To create new Firebase projects
B. To write the main logic of the function
C. To deploy the Firebase project
D. To store settings outside the code for security and flexibility

Solution

  1. Step 1: Understand environment configuration role

    Environment configuration holds settings like API keys or URLs outside the code to keep them safe and easy to change.
  2. Step 2: Compare options with this role

    Only To store settings outside the code for security and flexibility describes storing settings outside code for security and flexibility, which matches the purpose.
  3. Final Answer:

    To store settings outside the code for security and flexibility -> Option D
  4. Quick Check:

    Environment config = store settings outside code [OK]
Hint: Environment config = safe settings outside code [OK]
Common Mistakes:
  • Confusing environment config with function logic
  • Thinking environment config deploys projects
  • Mixing environment config with project creation
2. Which command correctly sets an environment variable named api.key with value 12345 in Firebase functions?
easy
A. firebase config:set api.key 12345
B. firebase functions:config:set api.key=12345
C. firebase functions:set-config api.key=12345
D. firebase functions:config add api.key 12345

Solution

  1. Step 1: Recall correct syntax for setting config

    The correct command uses 'firebase functions:config:set' followed by key=value pairs.
  2. Step 2: Match options to syntax

    Only firebase functions:config:set api.key=12345 matches the exact syntax: 'firebase functions:config:set api.key=12345'. Others have wrong commands or missing colons.
  3. Final Answer:

    firebase functions:config:set api.key=12345 -> Option B
  4. Quick Check:

    Set config = functions:config:set key=value [OK]
Hint: Use 'functions:config:set key=value' to set env vars [OK]
Common Mistakes:
  • Omitting the colon after 'functions'
  • Using spaces instead of '=' between key and value
  • Using wrong command verbs like 'add' or 'set-config'
3. Given the following commands run in order:
firebase functions:config:set service.api_key="abc123"
firebase deploy --only functions

What will functions.config().service.api_key return inside your function?
medium
A. service.api_key
B. undefined
C. "abc123"
D. null

Solution

  1. Step 1: Understand setting and deploying config

    Setting 'service.api_key' with value 'abc123' and then deploying functions makes the config available inside functions.
  2. Step 2: Accessing config in function

    Accessing 'functions.config().service.api_key' returns the string value set, which is 'abc123'.
  3. Final Answer:

    "abc123" -> Option C
  4. Quick Check:

    Config value = "abc123" after deploy [OK]
Hint: Deploy after setting config to access values [OK]
Common Mistakes:
  • Forgetting to redeploy functions after setting config
  • Expecting config to be available without deploy
  • Confusing key names or accessing wrong path
4. You set an environment variable with firebase functions:config:set db.url="https://mydb.com" but inside your function functions.config().db.url returns undefined. What is the most likely cause?
medium
A. You forgot to redeploy the functions after setting the config
B. The config key name is invalid
C. You need to restart the Firebase CLI
D. The value must be a number, not a string

Solution

  1. Step 1: Identify cause of undefined config

    Config values only update inside functions after redeploying them.
  2. Step 2: Check other options

    Key names can be strings, no CLI restart needed, and values can be strings. So these are not causes.
  3. Final Answer:

    You forgot to redeploy the functions after setting the config -> Option A
  4. Quick Check:

    Redeploy needed after config change [OK]
Hint: Always redeploy functions after config changes [OK]
Common Mistakes:
  • Assuming config updates instantly without deploy
  • Restarting CLI unnecessarily
  • Thinking config keys must be numbers
5. You want to store two environment variables for your Firebase functions: api.key with value key123 and api.secret with value secret456. Which command correctly sets both at once?
hard
A. firebase functions:config:set api.key=key123 api.secret=secret456
B. firebase functions:config:set api.key=key123; api.secret=secret456
C. firebase functions:config:set api.key=key123, api.secret=secret456
D. firebase functions:config:set api.key=key123 && api.secret=secret456

Solution

  1. Step 1: Recall syntax for multiple config keys

    Multiple keys are set by listing them separated by spaces, each as key=value pairs.
  2. Step 2: Evaluate options

    Only firebase functions:config:set api.key=key123 api.secret=secret456 uses spaces correctly. Others use semicolon, comma, or && which are invalid here.
  3. Final Answer:

    firebase functions:config:set api.key=key123 api.secret=secret456 -> Option A
  4. Quick Check:

    Multiple keys set with spaces [OK]
Hint: Separate multiple keys with spaces, not commas or semicolons [OK]
Common Mistakes:
  • Using commas or semicolons instead of spaces
  • Trying to chain commands with &&
  • Setting keys one at a time unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard