Firebase – How to setup local environment variables for Cloud Functions for Firebase

firebasegoogle-cloud-functions

I'm using http cloud functions to listen for a request and then return a simple message.

I'm developing cloud functions locally using:

firebase serve --only functions

I've setup some custom environment variables using

firebase functions:config:set

Accessing the custom config variables using the below code works fine when the project is deployed

 functions.config()

but it does not work when developing locally. When the function is triggered by hitting: http://localhost:5002/my-project-name/us-central1/functionName I can't access the custom config variables. when using functions.config() locally, I can see the default config, just not my custom config variables

Is there an alternate solution or best practice for environment variables when working locally?

Best Answer

As of now, you have to manually create a .runtimeconfig.json file inside your functions directory by running this command. Then run the serve command.

firebase functions:config:get > .runtimeconfig.json

If you are using Windows Powershell, replace the above with:

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

You can learn more in https://firebase.google.com/docs/functions/local-emulator

Related Topic