Firebase emulator suite for local development and testing. Provides local emulation of Firebase services including Authentication, Functions, Firestore, Realtime Database, Storage, Hosting, Pub/Sub, and Extensions.
Starts the Firebase emulator suite for local development.
/**
* Start Firebase emulators
* @param options - Emulator configuration options
* @returns Promise resolving when emulators are started
*/
function start(options?: Options & {
/** Comma-separated list of emulators to start */
only?: string;
/** Node.js inspect flag for Functions emulator */
inspect?: string;
/** Import data from export directory */
import?: string;
/** Export data on exit */
exportOnExit?: string | boolean;
/** Host to bind emulators to */
host?: string;
/** Port for emulator UI */
uiPort?: number;
/** Disable emulator UI */
ui?: boolean;
}): Promise<{
hub: {
host: string;
port: number;
};
emulators: Record<string, {
host: string;
port: number;
}>;
}>;Usage Examples:
const client = require("firebase-tools");
// Start all configured emulators
await client.emulators.start({
project: "my-project"
});
// Start specific emulators
await client.emulators.start({
project: "my-project",
only: "functions,firestore,auth"
});
// Start emulators with data import
await client.emulators.start({
project: "my-project",
import: "./emulator-data",
exportOnExit: true
});
// Start emulators on custom host/port
await client.emulators.start({
project: "my-project",
host: "0.0.0.0",
uiPort: 4001,
ui: true
});Runs a command with Firebase emulators running, automatically starting and stopping them.
/**
* Execute command with Firebase emulators
* @param script - Command/script to execute
* @param options - Execution options
* @returns Promise resolving when script completes
*/
function exec(
script: string,
options?: Options & {
/** Comma-separated list of emulators to start */
only?: string;
/** Import data from export directory */
import?: string;
/** Export data after execution */
exportOnExit?: string | boolean;
/** Environment variables for the script */
env?: Record<string, string>;
}
): Promise<{
exitCode: number;
stdout: string;
stderr: string;
}>;Usage Examples:
// Run tests with emulators
await client.emulators.exec("npm test", {
project: "my-project",
only: "firestore,auth"
});
// Run script with environment variables
await client.emulators.exec("node test-script.js", {
project: "my-project",
env: {
FIRESTORE_EMULATOR_HOST: "localhost:8080",
FIREBASE_AUTH_EMULATOR_HOST: "localhost:9099"
}
});Exports data from running emulators to a directory.
/**
* Export emulator data
* @param options - Export configuration options
* @returns Promise resolving when export completes
*/
function exportData(options?: Options & {
/** Export directory path */
exportPath: string;
/** Force overwrite existing export */
force?: boolean;
}): Promise<void>;Usage Examples:
// Export emulator data
await client.emulators.export({
project: "my-project",
exportPath: "./backup-data",
force: true
});Emulator configuration is specified in firebase.json:
{
"emulators": {
"auth": {
"host": "localhost",
"port": 9099
},
"functions": {
"host": "localhost",
"port": 5001
},
"firestore": {
"host": "localhost",
"port": 8080
},
"database": {
"host": "localhost",
"port": 9000
},
"hosting": {
"host": "localhost",
"port": 5000
},
"storage": {
"host": "localhost",
"port": 9199
},
"pubsub": {
"host": "localhost",
"port": 8085
},
"ui": {
"enabled": true,
"host": "localhost",
"port": 4000
},
"singleProjectMode": true
}
}When emulators are running, they set environment variables for client SDKs:
FIRESTORE_EMULATOR_HOST=localhost:8080
FIREBASE_AUTH_EMULATOR_HOST=localhost:9099
FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
FIREBASE_STORAGE_EMULATOR_HOST=localhost:9199
GCLOUD_PROJECT=demo-projectThese variables automatically configure Firebase client SDKs to connect to local emulators instead of production services.