How to Start Firebase Emulator: Simple Steps to Run Locally
To start the Firebase Emulator, run
firebase emulators:start in your project directory after installing the Firebase CLI. This command launches local emulators for services like Firestore, Authentication, and Functions for safe testing.Syntax
The basic command to start the Firebase Emulator Suite is firebase emulators:start. You can add flags to specify which emulators to run or to use a specific configuration file.
firebase emulators:start: Starts all emulators defined in yourfirebase.json.--only <emulator1,emulator2>: Runs only specified emulators, e.g.,--only firestore,auth.--import <path>: Imports saved emulator data from a folder.--export-on-exit <path>: Saves emulator data on exit to a folder.
bash
firebase emulators:start [--only <emulator1,emulator2>] [--import <path>] [--export-on-exit <path>]
Example
This example shows how to start the Firebase Emulator Suite with Firestore and Authentication emulators only. It assumes you have Firebase CLI installed and a firebase.json configured.
bash
firebase emulators:start --only firestore,auth
Output
ā emulators: Starting emulators: firestore, auth
i firestore: Firestore Emulator logging to firestore-debug.log
ā firestore: Firestore Emulator started at http://localhost:8080
i auth: Authentication Emulator logging to auth-debug.log
ā auth: Authentication Emulator started at http://localhost:9099
ā All emulators started, it is now safe to connect your app.
Common Pitfalls
Some common mistakes when starting Firebase emulators include:
- Not installing the Firebase CLI globally with
npm install -g firebase-tools. - Running the command outside a Firebase project folder without
firebase.json. - Forgetting to specify which emulators to start if you only want some.
- Not configuring ports properly, causing conflicts with other services.
Always check your firebase.json to ensure emulators are configured correctly.
bash
Wrong: firebase start Right: firebase emulators:start
Quick Reference
| Command | Description |
|---|---|
| firebase emulators:start | Start all configured emulators |
| firebase emulators:start --only firestore,auth | Start only Firestore and Authentication emulators |
| firebase emulators:start --import ./saved-data | Start emulators with imported data |
| firebase emulators:start --export-on-exit ./saved-data | Save emulator data on exit |
Key Takeaways
Run 'firebase emulators:start' inside your Firebase project folder to launch emulators.
Use '--only' flag to start specific emulators like Firestore or Authentication.
Ensure Firebase CLI is installed globally before running emulator commands.
Check your 'firebase.json' to configure which emulators to run and their ports.
Avoid running commands outside a Firebase project directory to prevent errors.