With the recent release of Firebase Local Emulator Suite, which comprises of the following
- Firestore Emulator
- Realtime Database Emulator
- Function Emulator
- Hosting Emulator
- Pub/Sub Emulator
This tutorial focus on the Firestore Emulator.
By default, Firebase Emulator is started by using the command
within a firebase project.
This start the Firebase Emulators in a clean blank state.
Once you add and play with your local data for development or testing purpose and stop the emulators. The data is cleared off.
For some projects, it is perfectly fine whereas for others projects, it might be needed to persist some data whenever the emulators are started.
To do this, there are two steps that needs to be followed
- Add the necessary data to the firestore emulator and then export it.
- Reimport the exported data, whenever the firestore emulator is restarted.
Exporting the data from Firebase Emulator
firebase emulators:export "<path-to-directory>"
This will export the contents from the emulator to the specified directory
Importing the data to the Firebase Emulator
firebase emulators:start --import="<path-to-directory>"
This will import the data and start the firebase emulator