/firebase-tutorials

How to use Firebase emulator suite?

Learn to install Node.js & Firebase CLI, initialize a Firebase project, run local emulators, connect your app, and debug seamlessly.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to use Firebase emulator suite?

 

Step 1: Install Node.js and npm

 

First, ensure that Node.js and npm (Node Package Manager) are installed on your system. They are required to manage projects and dependencies. To check if you have them installed, run the following commands:

node -v
npm -v

If not installed, download and install them from the official Node.js website.

 

Step 2: Set Up Firebase CLI

 

Install Firebase CLI (Command Line Interface) through npm to access Firebase commands:

npm install -g firebase-tools

Verify the installation:

firebase --version

 

Step 3: Initialize Firebase Project

 

Navigate to your project directory and initialize Firebase:

firebase login

This logs you into Firebase using Google credentials.

Initialize a new Firebase project:

firebase init

Follow the prompts:

  • Select “Emulators” by using the arrow keys and pressing Spacebar, then Enter.
  • Choose to set up default emulators: “Firestore,” “Realtime Database,” “Authentication,” or others based on your needs.
  • Decide whether to use the default emulator ports or customize them.
  • Opt to enable the Emulator UI if desired.

Proceed to confirm the Firebase initialization.

 

Step 4: Start the Emulator Suite

 

Once Firebase project initialization is complete, start the emulators with the following command:

firebase emulators:start

Firebase will start the services you selected in the initialization step. Any web or mobile applications you develop can interact with these locally running versions of Firebase services.

 

Step 5: Connect Your App to Emulators

 

To connect your app to the Firebase emulators, update configurations in your project to point to the emulators' endpoints instead of the actual Firebase services.

Here's an example of how to update endpoints in your JavaScript/Node.js app:

const admin = require('firebase-admin');
const serviceAccount = require('/path/to/serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'http://localhost:9000?ns=your-database-name'
});

// Firestore emulator example
const db = admin.firestore();
db.settings({
  host: "localhost:8080",
  ssl: false
});

Ensure your app uses these configurations only during local development.

 

Step 6: Testing and Debugging

 

With the emulator suite running and your app connected, you can now test and debug your application as if it were using live Firebase services. Utilize the Emulator UI (if enabled in Step 3) by opening the URL displayed in the terminal to manage and inspect your local Firebase database, Firestore, and more.

 

Step 7: Stop Emulators

 

Once you have completed your testing, stop the emulators either by pressing Ctrl + C in the terminal running the emulators or by running:

firebase emulators:stop

This will safely terminate all running emulators.

 

Step 8: Advanced Emulator Configurations (Optional)

 

You can further configure the Firebase emulator suite by editing the firebase.json file in your project directory. This file allows you to customize emulator settings, such as port numbers and service behavior. For complex setups, refer to the Firebase documentation for field-specific configurations.

Example firebase.json snippet:

{
  "emulators": {
    "firestore": {
      "port": 8080
    },
    "database": {
      "port": 9000
    },
    "ui": {
      "enabled": true
    }
  }
}

This setup will make your development environment closely resemble production, ensuring your app behaves consistently across environments.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022