Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Know if express app is running as firebase cloud function

I have an express app that I want to run locally as a standalone server in my machine however, when deploying it to firebase cloud functions I need to set it as a cloud function.

Is there a reliable way to know in which environment the app is running without manually setting env variables or what is the best practice?

eg:

if(isRunningInFirebase()){
  exports.myFun=functions.https.onRequest(app)
} else app.listen(3030)
like image 525
angrykoala Avatar asked Dec 14 '22 13:12

angrykoala


1 Answers

Firebase now sets the FUNCTIONS_EMULATOR environment variable when running the emulator:

if (process.env.FUNCTIONS_EMULATOR === 'true') {
    functions are on localhost
} else {
    functions are on Firebase
}
like image 176
Brent Washburne Avatar answered Dec 21 '22 11:12

Brent Washburne