Firebase Emulator Suite

Firebase.jl can talk to the local Firebase Emulator Suite instead of live Firebase, which is handy for tests and local development.

using Firebase

# Use the standard *_EMULATOR_HOST environment variables, if set
use_emulator()

# Or name services explicitly (true = default port on localhost)
use_emulator(firestore=true, database=true, auth=true, storage=true,
             project_id="demo-firebase")

# Switch every service back to live Firebase
use_production()

When a service is emulated, requests to it use the emulator's owner token, so no service-account credentials are needed. Services that are not emulated keep using live Firebase and your real credentials.

ServiceEnvironment variableDefault port
FirestoreFIRESTORE_EMULATOR_HOST8080
Realtime DBFIREBASE_DATABASE_EMULATOR_HOST9000
AuthFIREBASE_AUTH_EMULATOR_HOST9099
StorageFIREBASE_STORAGE_EMULATOR_HOST9199
Firebase.database_ns — Method
database_ns() -> String

Realtime Database namespace used for the ?ns= query parameter in emulator mode.

source
Firebase.emulator_active — Method
emulator_active(service::Symbol) -> Bool

Return true when service (:firestore, :database, :auth, or :storage) is currently pointed at an emulator.

source
Firebase.emulator_running — Method
emulator_running(hostport::AbstractString) -> Bool

Best-effort check that something is listening on hostport ("host:port"), used to gate integration tests. Returns false if the connection cannot be established.

source
Firebase.firestore_url — Method
firestore_url() -> String

Base URL for Firestore REST calls: the emulator host when active, otherwise live.

source
Firebase.use_emulator — Method
use_emulator(; host="localhost", firestore=nothing, database=nothing,
               auth=nothing, storage=nothing, project_id="demo-firebase",
               detect_env=true)

Point the package at the local Firebase Emulator Suite.

For each service you may pass an explicit "host:port" string, true to use the standard port on host, or leave it nothing. When detect_env is true, the standard *_EMULATOR_HOST environment variables are read for any service not given explicitly. If nothing is specified for a service and no env var is set, that service stays live.

Calling use_emulator() with no arguments enables every service whose env var is set, falling back to the default ports on host only for services you request.

Example

use_emulator()                                   # from FIRESTORE_EMULATOR_HOST etc.
use_emulator(firestore=true, database=true)      # localhost:8080 / localhost:9000
use_emulator(firestore="127.0.0.1:8080", project_id="my-demo")
source