I am moving some of my firebase-queue
workers to Firebase Functions. I have used process.env.NODE_ENV
to set some of the configuration for the workers depending on the environment in which I am running them. Is there a way to set the NODE_ENV
for the functions while deploying them. I understand that the recommended way to provide such config options is via firebase.config.set
which I have verified works as expected but just wanted to check if there is a way to set the NODE_ENV
also. When I try to print out the NODE_ENV
inside of a function, it is always set to production
.
相关问题
- adding sha1 in firebase app fails with error
- firebase storage cors strange Behaviour
- Firebase security rules difference between get() a
- LoginActivty with Firebase & Facebook authenticati
- How to add working directory to deployment in GitH
相关文章
- How can make folder with Firebase Cloud Functions
- Firestore Update a document field Using Rest API
- How to convert a FCM token to APNS token?
- App not showing Notification receiving FCM when th
- Android Studio - Get Firebase token from GetIdToke
- How to combine Firestore orderBy desc with startAf
- Remove Duplicates from an Array of GeoFire Objects
- Is it possible to test a Firebase trigger locally?
At the time I'm answering this question the Firebase SDK for Cloud Functions offers built-in environment configuration out of the box.
Set environment configuration for your project
Example
Get environment configuration for your project
Example
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 functions and you need to use thegcloud
command-line tool.https://cloud.google.com/functions/docs/env-var#accessing_environment_variables_at_runtime
Other options
If you are developing specifically for Firebase and need a similar solution, then there are options.
Conditions based on project ID
You can access the project id if you are having test, staging and production projects and want to have different behavior or logging depending on the environment.
process.env.GCLOUD_PROJECT
is set to your GCP project ID so you can build logic based on that.Cloud Function Environment Variables
As you already mentioned there's the cloud functions environment variables also. You can effectively create build pipelines that are configuring your environment configuration upon build/deploy and later access them in your cloud function.
Accessing the configuration is effectively the same as your
process.env
but can not be accessed outside of the scope of a cloud function (i.e. you can't use it in a global variable declaration).Following Google's
Best practices and reserved environment variables
in their documentationBasically don't use
NODE_ENV
. Use your own environment variables and set them accordingly.NOTE: This documentations is from Google Cloud Functions. Firebase functions are like a wrapper around google cloud functions. Check this question