firebase / firebase/firebase-admin-node

[FR] Dedicated initializer function for connecting to the Firebase emulator suite

Open
#2,327 1 comment 0 reactions 0 assignees View on GitHub
api: core type: feature request
Dominant language
TypeScript
Stars
1.7k
Forks
419
Avg merge
3d 10h
Merged PRs (30d)
16

Description

The use case involves use of two initialized instances of FirebaseApp, one for the emulator and another for an actual project. Specifically, it's desirable to programmatically copy data from one to the other without having to export then import separately.

Currently, the Admin SDK requires that an env var is set with host and port in order to connect to the emulator. This is unnecessarily complex when it comes time to init the app. For example, using Auth and Firestore together (and potentially more products) requires code like this:

```js
import { initializeApp } from "firebase-admin/app"
import { getAuth } from "firebase-admin/auth"
import { getFirestore } from "firebase-admin/firestore"

export const remote = initializeApp()
export const remoteAuth = getAuth(remote)
export const remoteFirestore = getFirestore(remote)

process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080'
export const local = initializeApp(undefined, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)
delete process.env.FIRESTORE_EMULATOR_HOST
```

The use of the temporary env var is clunky here, and it would be more straightforward if there was a dedicated function that allowed the caller to pass the host and port instead:

```js
const host, port = ...
export const local = initializeEmulatorApp(host, port, "local")
export const localAuth = getFirestore(local)
export const localFirestore = getFirestore(local)
```

Either that, or something similar to the way the web and mobile clients work for connecting to the emulator.

Contributor guide

Open the contributing guide

Research direction

Start by reading the Admin SDK entry points initializeApp, getAuth, and getFirestore, along with the current FIRESTORE_EMULATOR_HOST handling. Compare the requested emulator initialization with the existing web and mobile client approaches. Done means supporting separate emulator and remote FirebaseApp instances without a temporary environment variable, including Auth and Firestore usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.