Firebase Local Emulator - Import & Export

Published July 25, 2020 | development

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
Photo - Asian Giant Hornet by Kenpei on Wikimedia
Photo: Asian Giant Hornet by Kenpei on Wikimedia

This tutorial focus on the Firestore Emulator.

By default, Firebase Emulator is started by using the command

firebase emulators:start

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

  1. Add the necessary data to the firestore emulator and then export it.
  2. 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

Tags:
  • firebase
  • emulator
  • local
  • google-cloud