|
| 1 | +# Firebase Emulator Reference |
| 2 | + |
| 3 | +## Port Mapping |
| 4 | + |
| 5 | +| Service | Port | URL | |
| 6 | +|------------|------|-----| |
| 7 | +| Firestore | 8080 | http://127.0.0.1:8080 | |
| 8 | +| Storage | 9199 | http://127.0.0.1:9199 | |
| 9 | +| Auth | 9099 | http://127.0.0.1:9099 | |
| 10 | +| Pub/Sub | 8085 | http://127.0.0.1:8085 | |
| 11 | +| Functions | 5001 | http://127.0.0.1:5001 | |
| 12 | +| Hub/UI | 4000 | http://127.0.0.1:4000 | |
| 13 | +| Hosting | 8081 | http://127.0.0.1:8081 | |
| 14 | + |
| 15 | +## Health Check |
| 16 | + |
| 17 | +The emulator hub exposes a health endpoint: |
| 18 | + |
| 19 | +```bash |
| 20 | +curl -sf http://127.0.0.1:4000 > /dev/null && echo "Emulator is running" || echo "Emulator is not running" |
| 21 | +``` |
| 22 | + |
| 23 | +## Environment Variables |
| 24 | + |
| 25 | +Tests expect these environment variables to point to the emulator: |
| 26 | + |
| 27 | +```bash |
| 28 | +export FIRESTORE_EMULATOR_HOST="127.0.0.1:8080" |
| 29 | +export STORAGE_EMULATOR_HOST="127.0.0.1:9199" |
| 30 | +export FIREBASE_AUTH_EMULATOR_HOST="127.0.0.1:9099" |
| 31 | +export PUBSUB_EMULATOR_HOST="127.0.0.1:8085" |
| 32 | +export GCLOUD_PROJECT="demo-gcp" |
| 33 | +export PROJECT_ID="demo-gcp" |
| 34 | +``` |
| 35 | + |
| 36 | +## Emulator Configuration |
| 37 | + |
| 38 | +The emulator config lives in `_emulator/`: |
| 39 | + |
| 40 | +``` |
| 41 | +_emulator/ |
| 42 | +├── firebase.json # Emulator service config and ports |
| 43 | +├── .firebaserc # Project aliases (demo-extensions-testing, dev-extensions-testing) |
| 44 | +├── firestore.rules # Firestore security rules |
| 45 | +├── storage.rules # Storage security rules |
| 46 | +├── extensions/ # Extension environment configs |
| 47 | +│ ├── firestore-palm-chatbot.env |
| 48 | +│ ├── firestore-semantic-search.env |
| 49 | +│ ├── storage-image-labeling.env.local |
| 50 | +│ └── ... |
| 51 | +└── functions/ # Dummy functions project for emulator |
| 52 | + ├── index.js |
| 53 | + └── package.json |
| 54 | +``` |
| 55 | + |
| 56 | +## Extension Environment Config |
| 57 | + |
| 58 | +Each extension can have an `.env` file in `_emulator/extensions/` that sets its params. Example for `firestore-semantic-search.env`: |
| 59 | + |
| 60 | +``` |
| 61 | +COLLECTION_NAME=products |
| 62 | +EMBEDDING_METHOD=palm |
| 63 | +FIELDS=title,description |
| 64 | +DISTANCE_MEASURE=SQUARED_L2_DISTANCE |
| 65 | +``` |
| 66 | + |
| 67 | +## Firebase CLI Commands |
| 68 | + |
| 69 | +```bash |
| 70 | +# Start emulator |
| 71 | +cd _emulator && firebase emulators:start --project=demo-gcp |
| 72 | + |
| 73 | +# Clear Firestore data |
| 74 | +curl -X DELETE "http://127.0.0.1:8080/emulator/v1/projects/demo-gcp/databases/(default)/documents" |
| 75 | + |
| 76 | +# List Firestore documents |
| 77 | +curl -sf "http://127.0.0.1:8080/v1/projects/demo-gcp/databases/(default)/documents/<collection>" | jq . |
| 78 | + |
| 79 | +# List Storage objects |
| 80 | +curl -sf "http://127.0.0.1:9199/v0/b/demo-gcp.appspot.com/o" | jq '.items[].name' |
| 81 | +``` |
| 82 | + |
| 83 | +## Clearing Data Between Tests |
| 84 | + |
| 85 | +```bash |
| 86 | +# Clear all Firestore data |
| 87 | +.skills/test-extension/scripts/clear-firestore.sh |
| 88 | + |
| 89 | +# Clear a specific collection (delete and recreate) |
| 90 | +# There's no emulator API for this — clear all data instead |
| 91 | + |
| 92 | +# Clear Storage (no emulator API — restart emulator or delete objects individually) |
| 93 | +``` |
| 94 | + |
| 95 | +## Troubleshooting |
| 96 | + |
| 97 | +- **Port already in use**: Run `npx kill-port 8080 8085 4000 4400 5001 9199 9000 9099` |
| 98 | +- **Emulator won't start**: Check Java is installed (`java -version`), the emulator requires it |
| 99 | +- **Tests fail with ECONNREFUSED**: Emulator isn't running or wrong port. Check `FIRESTORE_EMULATOR_HOST` |
| 100 | +- **Extension doesn't trigger**: Check that the extension's env file exists in `_emulator/extensions/` and has the correct `COLLECTION_NAME` or bucket config |
0 commit comments