Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Firebase local emulator cloud function environment config values

When you update cloud function environment variables, the config values are not accessible when using the local node.js emulator.

On a project with no environment config variables:

  • Set a new value firebase functions:config:set x=true
  • Get the config variables firebase functions:config:get (shows the new value)
  • Deploy the functions firebase deploy --only functions
  • Run the local emulator and log out the functions.config{}
  • Output: {} (empty object)

There is no mention in the environment config docs but I am assuming it is possible to use the same environment config locally (or a local alternative)?

like image 598
Yasir Avatar asked Feb 14 '19 11:02

Yasir


People also ask

Can you use Firebase locally?

The Firebase Local Emulator Suite is a set of advanced tools for developers looking to build and test apps locally using Cloud Firestore, Realtime Database, Cloud Storage, Authentication, Cloud Functions, Pub/Sub, Firebase Hosting and Firebase Extensions.


1 Answers

The answer was in the local emulator documentation.

Note: You can retrieve your production custom configuration variables when emulating functions. However, be cautious when using production config values in local testing of API calls, emails, etc.

To use config variables, run the following command in the functions directory before running firebase serve.

MacOS

firebase functions:config:get > .runtimeconfig.json

Windows

firebase functions:config:get | ac .runtimeconfig.json

like image 195
Yasir Avatar answered Sep 19 '22 03:09

Yasir