Connect your app
Fireemu serves the same protocols and default ports as the Local Emulator Suite, so you connect to it the same way.
Server code and the Admin SDK
Section titled “Server code and the Admin SDK”The Firebase Admin SDK and the Google Cloud client libraries read the emulator environment variables. fireemu exec sets them for the command it runs:
npx fireemu exec -- node ./scripts/seed.mjs| Variable | Value |
|---|---|
FIRESTORE_EMULATOR_HOST, FIREBASE_FIRESTORE_EMULATOR_ADDRESS |
Firestore host:port |
FIREBASE_AUTH_EMULATOR_HOST |
Authentication host:port |
FIREBASE_STORAGE_EMULATOR_HOST |
Storage host:port |
STORAGE_EMULATOR_HOST |
Storage URL (http://host:port) for the Cloud Storage client libraries; with Storage App Check enforced and appCheck.storageServerRequests set to "capability" it also carries a per-run Admin capability (see App Check) |
PUBSUB_EMULATOR_HOST |
Pub/Sub host:port, when Pub/Sub runs |
CLOUD_EVENTARC_EMULATOR_HOST |
Eventarc URL, when Functions run |
CLOUD_TASKS_EMULATOR_HOST |
Cloud Tasks host:port, when Functions run |
FIREEMU_FUNCTIONS_HOST |
Functions host:port, when Functions run |
FIREEMU_APP_CHECK_EMULATOR_HOST, FIREEMU_APP_CHECK_JWKS_URL |
App Check exchange host and JWKS URL, when appCheck.enabled |
FIREBASE_EMULATOR_HUB |
Emulator Hub host:port, when the Hub is running |
FIREBASE_LOGGING_EMULATOR_HOST |
Logging emulator host:port |
GCLOUD_PROJECT, GOOGLE_CLOUD_PROJECT |
The project ID |
FIREBASE_CONFIG |
Set from the project ID unless your environment already has it |
FIREEMU_CONTROL_URL, FIREEMU_CONTROL_TOKEN |
Fireemu’s control API, used by fireemu/testing |
Variables for emulators that are not selected are left as your environment had them.
import { initializeApp } from 'firebase-admin/app';import { getFirestore } from 'firebase-admin/firestore';
// Under `fireemu exec`, the Admin SDK finds the emulators from the environment.initializeApp({ projectId: process.env.GCLOUD_PROJECT });await getFirestore().doc('notes/n1').set({ text: 'hello' });Client SDKs
Section titled “Client SDKs”Client SDKs are connected in code, as with the Local Emulator Suite. Use the project ID Fireemu runs with: the .firebaserc default, else daemon.authProject in fireemu.toml, else demo-app.
import { initializeApp } from 'firebase/app';import { getAuth, connectAuthEmulator } from 'firebase/auth';import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';import { getStorage, connectStorageEmulator } from 'firebase/storage';import { getFunctions, connectFunctionsEmulator } from 'firebase/functions';
const app = initializeApp({ projectId: 'demo-app', apiKey: 'fake-api-key', storageBucket: 'demo-app.appspot.com',});
connectAuthEmulator(getAuth(app), 'http://127.0.0.1:9099');connectFirestoreEmulator(getFirestore(app), '127.0.0.1', 8080);connectStorageEmulator(getStorage(app), '127.0.0.1', 9199);connectFunctionsEmulator(getFunctions(app), '127.0.0.1', 5001);Security Rules unit tests
Section titled “Security Rules unit tests”@firebase/rules-unit-testing works with Fireemu. Its unsigned mock ID tokens (authenticatedContext()) are accepted by default, also under the strict profile, and the routes it calls to load Firestore and Storage rules and to clear Firestore (testEnv.clearFirestore()) are served. See Security Rules.
The project ID
Section titled “The project ID”Fireemu takes the project ID from, in order:
--project(-P) on the command line, as an ID or a.firebasercalias;- the default project of the
.firebasercnext to the loadedfirebase.json; daemon.authProjectinfireemu.toml;demo-app.