1

I can create process.env variables from https://console.cloud.google.com/functions but I've to create this variables for each and every firebase cloud functions which is inefficient.

How can I create these process.env variables from code? while deploying cloud functions from my machine? If I can set it up from GUI then there must be a way to set it up from CLI/code.

enter image description here

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225

2 Answers2

2

Firebase does not directly support setting process environment variables. Currently, the only way to provide configuration at the time of deployment is using a different kind of environment configuration, which is not really the same as process env vars that you're showing in the screenshot.

If you want to set process environment variable for functions deployed with the Firebase CLI, you will have to use the method that you've already discovered. If you want to set them at the time of deployment, you will have to use Google Cloud's command line "gcloud" instead, which means you won't be able to take advantage of the firebase-functions API or the Firebase CLI at all. You just have to choose between the two.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • if using .runtimeconfig.json (functions:config:set) then how can I set different environments like dev, testing, prod? and choose appropriate one while testing and deploying? – GorvGoyl Jun 06 '20 at 20:44
  • You use the CLI to change the active project using `firebase use` along with aliases you define. See the documentation. https://firebase.google.com/docs/cli#project_aliases – Doug Stevenson Jun 06 '20 at 21:04
0

Update: Feb 16, 2022

This can now be done from the code using .env, see answer.