Use Firestore emulator locally
The Google Cloud CLI provides a local, in-memory emulator for Firestore that you can use to test your application. You can use the emulator with all Firestore client libraries. You should use the emulator only for local testing.
Do not use the emulator for production deployments. Because the emulator stores data only in memory, it will not persist data across runs.
Install the emulator
To install the Firestore emulator, install and update the gcloud CLI:
-
Update your gcloud CLI installation to get the latest features:
gcloud components update
Run the emulator
-
Run the following command to start the emulator:
gcloud emulators firestore startThe emulator prints the host and port number where it is running.
By default, the emulator attempts to use
127.0.0.1:8080. To bind the emulator to a specific host and port, use the optional--host-portflag, replacing HOST and PORT :gcloud emulators firestore start --host-port= HOST : PORT -
Type
Control + Cto stop the emulator. The emulator may also be stopped with a POST to/shutdown. For example:curl -d '' HOST : PORT /shutdown
Connect to the emulator
How you connect to the emulator depends on the type of client library, server client library, or mobile/web SDK.
Server client libraries
To connect a Firestore server client
library (C#, Go, Java, Node.js, PHP, Python, and Ruby),
set the FIRESTORE_EMULATOR_HOST
environment variable. When this environment
variable is set, the server client libraries automatically connect to the emulator.
export
FIRESTORE_EMULATOR_HOST
=
" HOST
: PORT
"
Android, Apple platforms, and Web SDKs
The following examples demonstrate how to connect the Android, Apple platforms, and Web SDKs to the Firestore emulator:
Android
// 10.0.2.2 is the special IP address to connect to the 'localhost' of // the host computer from an Android emulator. FirebaseFirestore firestore = FirebaseFirestore . getInstance (); firestore . useEmulator ( "10.0.2.2" , 8080 ); FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings . Builder () . setPersistenceEnabled ( false ) . build (); firestore . setFirestoreSettings ( settings );
Swift
let settings = Firestore . firestore (). settings settings . host = "127.0.0.1:8080" settings . cacheSettings = MemoryCacheSettings () settings . isSSLEnabled = false Firestore . firestore (). settings = settings . swift

