Skip to content

Latest commit

 

History

History
45 lines (27 loc) · 3.21 KB

nx-firebase-functions-environment.md

File metadata and controls

45 lines (27 loc) · 3.21 KB

Firebase Function Environment Variables

Overview

Firebase functions can make use of environment variables in their runtime.

The Nx-firebase application generator will automatically create default function environment files for you to use:

  • environment/.env
  • environment/.env.local
  • environment/.secret.local

If you run the getconfig target, it will place .runtimeconfig.json file in the environment folder also.

These environment files are considered common to all of your functions by nx-firebase, and are copied from your firebase app's environment folder to your function's dist folder when the function is built.

This ensures they are available for deployment and emulation.

All functions share the same environment variable files.

Environment file types

File Description Git Ignored Deployed
.env General environment variables for functions - Yes
.env.local Environment variable overrides for function emulation - -
.env.<project-alias> Environment variable overrides for specific deployment targets (eg. dev/prod) - Yes
.secret.local Secrets only for function emulation Yes -
.runtimeconfig.json Function configurations Yes -

Note that the Firebase team appear to be deprecating the use of .runtimeconfig.json function configs and recommending migration to dotenv environment variables.

Deployed Files

The firebase CLI will deploy .env and/or .env.<project-id> files along with function code, and they can be version controlled.

Non-deployed files

.env.local and .secret.local files are excluded from deployment by using an functions.ignore rule in firebase.json.

Local Files

.secret.local and .env.local are only used by the Firebase emulator suite.

.secret.local and .runtimeconfig.json should not be version controlled, and are both git ignored, but included in Nx dependency graph using a .nxignore override.