Persisting Data on Firebase EmulatorAug 14, 2021 . 2 min Muhammed Mukhthar CM
Firebase Emulator Suite is a great tool to develop with Firebase locally. It allows us to even use Firebase Functions without the paid Blaze plan.
But by default, Firebase Emulators don’t store any data. That is, if I ran Firebase Auth Emulator and created a User when I run It next time, The User would’ve been deleted.
Or, All those Notes you created in Firestore would’ve wiped.
I don’t know about you, It is a mess to play with Emulator UI to add mock Data. So I’d rather save them.
Even though Firebase Emulators Don’t have something like Saving Data, Luckily, they Can Export and Import Data. Let’s dig into it.
Exporting Firebase Emulator Data
While the Emulators are running, run the below command in another terminal to export emulator Data. Of course, it should be in the same folder as you’re running the Emulators
firebase emulators:export <export-directory>
This will export the emulator data to the Directory you specify.
There is another method to do it.
If we start the Emulators with an
--export-on-exit flag, the Firebase Emulator will automatically export Data when we shutdown it.
firebase emulators:start --export-on-exit
Importing Emulator Data
We can import data from an earlier export by starting the emulator by running the below command.
firebase emulators:start --import <export-directory>
This will import data from the directory we earlier exported.
What if we can do both of these in a single command?
We can combine the above commands to make another command which will do both the functions. ie, Importing and Exporting.
firebase emulators:start --import <export-directory> --export-on-exit
The above command will import data from the directory we specify at
<export-directory> and exports the emulator data on Exit to the same directory.
You can find more articles related to Firebase Here
Hope you found something useful here.
I’m always open to suggestions!
Let me know your suggestions and opinions on Twitter DM or drop a mail a firstname.lastname@example.org.
If you’re feeling too generous, you can support me through Buy Me a Coffee.
Finally, if you found this helpful, please share this within your reach so that more people can benefit from this. And Follow me on Twitter for getting more posts like these 😉.