Skip to content

Run Firebase Emulator locally

Suesi Tran edited this page Mar 28, 2025 · 1 revision

Firebase Emulator

The Firebase Emulator Suite is a set of local development tools that lets you build and test Firebase apps without connecting to the actual Firebase backend. It provides emulated versions of several Firebase services, so you can develop and test your app locally before deploying it.

What Does Firebase Emulator Suite Include?

  • Firestore: Test Firestore database reads/writes locally.
  • Realtime Database: Simulate real-time sync of data.
  • Authentication: Sign in users locally without real accounts.
  • Cloud Functions: Run and debug serverless functions locally.
  • Cloud Storage: Upload and retrieve files in a local storage emulator.
  • Pub/Sub: Test message publishing (but not full behavior).

Why Use Firebase Emulator Suite?

  • No need to use the Firebase free quota.
  • No network delay, instant updates.
  • Work without an internet connection.
  • No risk of modifying real data.

What Firebase Service we use in in our project

  • Authentication
  • Firestore
  • Cloud Storage
  • Cloud Function

How to use Firebase Emulator Suite?

1️⃣ Install Firebase CLI

npm install -g firebase-tools

2️⃣ Log in to Firebase (Optional for local testing)

firebase login

3️⃣ Initialize Firebase Emulator in your project

firebase init emulators

4️⃣ Start the emulator

firebase emulators:start

Now, you can interact with the emulated services on http://localhost:4000.

How to connect your mobile test device to Firebase Emulator?

1️⃣ Get your laptop's IP Address

ipconfig | grep "192.168"

2️⃣ Copy your laptop's IP address, and open file firebase.json. Under emulators, replace <Add your IP address here> with IP address you copied above

"emulators": {
    "auth": {
      "host": "<Add your IP address here>",
      "port": 9099
    },
    "functions": {
      "host": "<Add your IP address here>",
      "port": 5001
    },
    "firestore": {
      "host": "<Add your IP address here>",
      "port": 8080
    },
    "storage": {
      "host": "<Add your IP address here>",
      "port": 9199
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  },

3️⃣ Open file android/app/src/main/res/xml/network_security_config.xml, look for tag domain, and replace text replace with your IP Address with your IP address

<domain includeSubdomains="true">replace with your IP Address</domain>

4️⃣ In your lib/main.dart, after initialise Firebase app, add following lines, and replace host with your IP address above

if (kDebugMode) {
  final String host = 'replace with your IP Address';
  FirebaseFirestore.instance.useFirestoreEmulator(host, 8080);
  FirebaseAuth.instance.useAuthEmulator(host, 9099);
  FirebaseStorage.instance.useStorageEmulator(host, 9199);
}

5️⃣ Connect your test device to the same Wifi network as your laptop 6️⃣ Run ap

When Should You Use It?

  • Developing a chat app with Firestore or Realtime Database.
  • Testing Firebase Authentication without creating real users.
  • Debugging Cloud Functions locally before deploying.
  • Working offline or in a restricted network.