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.
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.
The firebase CLI will deploy .env
and/or .env.<project-id>
files along with function code, and they can be version controlled.
.env.local
and .secret.local
files are excluded from deployment by using an functions.ignore
rule in firebase.json
.
.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.