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).
const debug = process.env.FUNCTIONS_EMULATOR === 'true';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With