Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if environment is development or production with Firebase Cloud Functions?

How can I detect if my server environment is development or production with Firebase Cloud Functions?

I need something like this:

if(process.env.NODE_ENV === 'development'){

   //DO STUFF SPECIFIC TO DEV ENVIRONMENT

}
else if(process.env.NODE_ENV === 'production'){

   //DO STUFF SPECIFIC TO PRODUCTION ENVIRONMENT

}
like image 383
Brendan Avatar asked Nov 07 '18 07:11

Brendan


People also ask

Is Firebase cloud functions expensive?

Cloud functions in general are very cost-effective. It's difficult to compare pricing of cloud providers, but I can say that based on my experience, Firebase Cloud Functions have been ridiculously cheap.


1 Answers

process.env.FUNCTIONS_EMULATOR

At process.env, on firebase functions projects, there is a boolean variable called FUNCTIONS_EMULATOR, which indicates if the process is running on an emulator or on server.

this is enough to determine if environment is dev or production.

process.env.FUNCTIONS_EMULATOR === true

Obs: In some environments the variable might be a String 'true' instead of Boolean true

like image 176
Guilherme Ferreira Avatar answered Sep 21 '22 11:09

Guilherme Ferreira