There is currently no way to set custom environment variables such as process.env.NODE_ENV . What you want to do can only be done for Google Cloud features, and you need to use gcloud command line.
https://cloud.google.com/functions/docs/env-var#accessing_environment_variables_at_runtime
Other options
If you are developing specifically for Firebase and you need a similar solution, then there are options.
Project ID based conditions
You can access the project ID if you have test, intermediate, and production projects, and you want to behave differently or keep a log depending on the environment.
process.env.GCLOUD_PROJECT the identifier of your GCP project is set, so you can build logic based on it.
if (process.env.GCLOUD_PROJECT === 'my-production-project') {
Cloud function environment variables
As you already mentioned, cloud functions are also environment variables. You can efficiently create assembly pipelines that configure your environment during assembly / deployment, and then access them in your cloud function.
- firebase functions:config:set runtime.env="production" --token $FIREBASE_DEPLOY_KEY
Access to the configuration is actually the same as for your process.env but it cannot be accessed outside the cloud function (i.e. you cannot use it in the declaration of a global variable).
if (functions.config().runtime.env === 'production') {
source share