Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether firebase app is hosted by emulator or in production

I have a web app which currently uses Firestore as a database with Firebase Auth. I have it set up to try to connect to the Firebase emulators when in development, like so:

if(process.env.NODE_ENV === "development") {
    connectFirestoreEmulator(firestoreDb, "localhost", 8080);
}

I also use this technique to disable some in-browser testing when not in development.

This works fine when running a development server through Vite, which is what I have been using. However, I recently set up the project to run on Firebase hosting, and I found that process.env.NODE_ENV is not set when I run the hosting emulator. Is there another way to determine whether the app is being hosted from an emulator (i.e. for development) or on the real Firebase hosting service?

To clarify, I need to run this check in the app's client-side code, which is to be hosted statically via Firebase hosting. I am NOT concerned with server-side Firebase Cloud Functions (see this question for answers on that).

like image 218
Aaron Campbell Avatar asked Sep 10 '25 12:09

Aaron Campbell


1 Answers

const debug = process.env.FUNCTIONS_EMULATOR === 'true';
like image 73
rscotten Avatar answered Sep 13 '25 01:09

rscotten