Node.js – Set Firebase local emulator cloud function environment config values

firebasegoogle-cloud-functionsnode.js

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)?

Best Answer

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