Firebase Functions variables

Sometimes you want to use some environment or config variables in your Functions, be it to decide if you are running on your local machine or on the server, or reading API keys to use for with third party libraries.

You can access environment variables by looking at process.env.

If you want to know if your function in running on the server you can check the NODE_ENV variable. A simple use case would be initializing the firebase-admin SDK to get access to you database. You can load the needed credentials from functions.config().firebase if running in production, but need to load credentials from a file when testing.

Do get an idea of what is available as environment variables when running a function, here is a dump of mine (with my personal details replaced by <placeholders>).


If you have any API keys you want to use, you can add it to your functions config by running

firebase functions:config:set someservice.key="THE API KEY""THE CLIENT ID"

or for a practical example

firebase functions:config:set third_party.key=”My Test Key”

and then access it with


By default functions.config() only contains the firebase object but you can add as many extra objects as you want. Mine now looks like this:

"key":"My Test Key"