Back to Firebase Js Sdk

app package

docs-devsite/app.md

12.12.115.0 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

app package

Firebase App

This package coordinates the communication between the different Firebase components

Functions

FunctionDescription
<b>function(app, ...)</b>
deleteApp(app)Renders this app unusable and frees the resources of all associated services.
<b>function()</b>
getApps()A (read-only) array of all initialized apps.
initializeApp()Creates and initializes a FirebaseApp instance.
<b>function(config, ...)</b>
initializeServerApp(config)Creates and initializes a FirebaseServerApp instance.
<b>function(libraryKeyOrName, ...)</b>
registerVersion(libraryKeyOrName, version, variant)Registers a library's name and version for platform logging purposes.
<b>function(logCallback, ...)</b>
onLog(logCallback, options)Sets log handler for all Firebase SDKs.
<b>function(logLevel, ...)</b>
setLogLevel(logLevel)Sets log level for all Firebase SDKs.<!-- -->All of the log types above the current log level are captured (i.e. if you set the log level to <code>info</code>, errors are logged, but <code>debug</code> and <code>verbose</code> logs are not).
<b>function(name, ...)</b>
getApp(name)Retrieves a FirebaseApp instance.<!-- -->When called with no arguments, the default app is returned. When an app name is provided, the app corresponding to that name is returned.<!-- -->An exception is thrown if the app being retrieved has not yet been initialized.
<b>function(options, ...)</b>
initializeApp(options, name)Creates and initializes a FirebaseApp instance.<!-- -->See Add Firebase to your app and Initialize multiple projects for detailed documentation.
initializeApp(options, config)Creates and initializes a FirebaseApp instance.
initializeServerApp(options, config)Creates and initializes a FirebaseServerApp instance.<!-- -->The <code>FirebaseServerApp</code> is similar to <code>FirebaseApp</code>, but is intended for execution in server side rendering environments only. Initialization will fail if invoked from a browser environment.<!-- -->See Add Firebase to your app and Initialize multiple projects for detailed documentation.

Interfaces

InterfaceDescription
FirebaseAppA FirebaseApp holds the initialization information for a collection of services.<!-- -->Do not call this constructor directly. Instead, use initializeApp() to create an app.
FirebaseAppSettingsConfiguration options given to initializeApp()
FirebaseOptionsFirebase configuration object. Contains a set of parameters required by services in order to successfully communicate with Firebase server APIs and to associate client data with your Firebase project and Firebase application. Typically this object is populated by the Firebase console at project setup. See also: Learn about the Firebase config object<!-- -->.
FirebaseServerAppA FirebaseServerApp holds the initialization information for a collection of services running in server environments.<!-- -->Do not call this constructor directly. Instead, use initializeServerApp() to create an app.
FirebaseServerAppSettingsConfiguration options given to initializeServerApp()

Variables

VariableDescription
SDK_VERSIONThe current SDK version.

function(app, ...)

deleteApp(app) {:#deleteapp_cf608e1}

Renders this app unusable and frees the resources of all associated services.

<b>Signature:</b>

typescript
export declare function deleteApp(app: FirebaseApp): Promise<void>;

Parameters

ParameterTypeDescription
appFirebaseApp

<b>Returns:</b>

Promise<void>

Example

javascript
deleteApp(app)
  .then(function() {
    console.log("App deleted successfully");
  })
  .catch(function(error) {
    console.log("Error deleting app:", error);
  });

function()

getApps() {:#getapps}

A (read-only) array of all initialized apps.

<b>Signature:</b>

typescript
export declare function getApps(): FirebaseApp[];

<b>Returns:</b>

FirebaseApp<!-- -->[]

initializeApp() {:#initializeapp}

Creates and initializes a FirebaseApp instance.

<b>Signature:</b>

typescript
export declare function initializeApp(): FirebaseApp;

<b>Returns:</b>

FirebaseApp

function(config, ...)

initializeServerApp(config) {:#initializeserverapp_e7d0728}

Creates and initializes a FirebaseServerApp instance.

<b>Signature:</b>

typescript
export declare function initializeServerApp(config?: FirebaseServerAppSettings): FirebaseServerApp;

Parameters

ParameterTypeDescription
configFirebaseServerAppSettingsOptional <code>FirebaseServerApp</code> settings.

<b>Returns:</b>

FirebaseServerApp

The initialized FirebaseServerApp<!-- -->.

Exceptions

If invoked in an unsupported non-server environment such as a browser.

If FirebaseServerAppSettings.releaseOnDeref is defined but the runtime doesn't provide Finalization Registry support.

If the FIREBASE_OPTIONS environment variable does not contain a valid project configuration required for auto-initialization.

function(libraryKeyOrName, ...)

registerVersion(libraryKeyOrName, version, variant) {:#registerversion_f673248}

Registers a library's name and version for platform logging purposes.

<b>Signature:</b>

typescript
export declare function registerVersion(libraryKeyOrName: string, version: string, variant?: string): void;

Parameters

ParameterTypeDescription
libraryKeyOrNamestring
versionstringCurrent version of that library.
variantstringBundle variant, e.g., node, rn, etc.

<b>Returns:</b>

void

function(logCallback, ...)

onLog(logCallback, options) {:#onlog_fd46eae}

Sets log handler for all Firebase SDKs.

<b>Signature:</b>

typescript
export declare function onLog(logCallback: LogCallback | null, options?: LogOptions): void;

Parameters

ParameterTypeDescription
logCallbackLogCallback | nullAn optional custom log handler that executes user code whenever the Firebase SDK makes a logging call.
optionsLogOptions

<b>Returns:</b>

void

function(logLevel, ...)

setLogLevel(logLevel) {:#setloglevel_697d53a}

Sets log level for all Firebase SDKs.

All of the log types above the current log level are captured (i.e. if you set the log level to info<!-- -->, errors are logged, but debug and verbose logs are not).

<b>Signature:</b>

typescript
export declare function setLogLevel(logLevel: LogLevelString): void;

Parameters

ParameterTypeDescription
logLevelLogLevelString

<b>Returns:</b>

void

function(name, ...)

getApp(name) {:#getapp_1eaaff4}

Retrieves a FirebaseApp instance.

When called with no arguments, the default app is returned. When an app name is provided, the app corresponding to that name is returned.

An exception is thrown if the app being retrieved has not yet been initialized.

<b>Signature:</b>

typescript
export declare function getApp(name?: string): FirebaseApp;

Parameters

ParameterTypeDescription
namestringOptional name of the app to return. If no name is provided, the default is <code>"[DEFAULT]"</code>.

<b>Returns:</b>

FirebaseApp

The app corresponding to the provided app name. If no app name is provided, the default app is returned.

Example 1

javascript
// Return the default app
const app = getApp();

Example 2

javascript
// Return a named app
const otherApp = getApp("otherApp");

function(options, ...)

initializeApp(options, name) {:#initializeapp_cb2f5e1}

Creates and initializes a FirebaseApp instance.

See Add Firebase to your app and Initialize multiple projects for detailed documentation.

<b>Signature:</b>

typescript
export declare function initializeApp(options: FirebaseOptions, name?: string): FirebaseApp;

Parameters

ParameterTypeDescription
optionsFirebaseOptionsOptions to configure the app's services.
namestringOptional name of the app to initialize. If no name is provided, the default is <code>"[DEFAULT]"</code>.

<b>Returns:</b>

FirebaseApp

The initialized app.

Exceptions

If the optional name parameter is malformed or empty.

If a FirebaseApp already exists with the same name but with a different configuration.

Example 1

javascript

// Initialize default app
// Retrieve your own options values by adding a web app on
// https://console.firebase.google.com
initializeApp({
  apiKey: "AIza....",                             // Auth / General Use
  authDomain: "YOUR_APP.firebaseapp.com",         // Auth with popup/redirect
  databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
  storageBucket: "YOUR_APP.appspot.com",          // Storage
  messagingSenderId: "123456789"                  // Cloud Messaging
});

Example 2

javascript

// Initialize another app
const otherApp = initializeApp({
  databaseURL: "https://<OTHER_DATABASE_NAME>.firebaseio.com",
  storageBucket: "<OTHER_STORAGE_BUCKET>.appspot.com"
}, "otherApp");

initializeApp(options, config) {:#initializeapp_079e917}

Creates and initializes a FirebaseApp instance.

<b>Signature:</b>

typescript
export declare function initializeApp(options: FirebaseOptions, config?: FirebaseAppSettings): FirebaseApp;

Parameters

ParameterTypeDescription
optionsFirebaseOptionsOptions to configure the app's services.
configFirebaseAppSettingsFirebaseApp Configuration

<b>Returns:</b>

FirebaseApp

Exceptions

If FirebaseAppSettings.name is defined but the value is malformed or empty.

If a FirebaseApp already exists with the same name but with a different configuration.

initializeServerApp(options, config) {:#initializeserverapp_30ab697}

Creates and initializes a FirebaseServerApp instance.

The FirebaseServerApp is similar to FirebaseApp<!-- -->, but is intended for execution in server side rendering environments only. Initialization will fail if invoked from a browser environment.

See Add Firebase to your app and Initialize multiple projects for detailed documentation.

<b>Signature:</b>

typescript
export declare function initializeServerApp(options: FirebaseOptions | FirebaseApp, config?: FirebaseServerAppSettings): FirebaseServerApp;

Parameters

ParameterTypeDescription
optionsFirebaseOptions | FirebaseApp<code>Firebase.AppOptions</code> to configure the app's services, or a a <code>FirebaseApp</code> instance which contains the <code>AppOptions</code> within.
configFirebaseServerAppSettingsOptional <code>FirebaseServerApp</code> settings.

<b>Returns:</b>

FirebaseServerApp

The initialized FirebaseServerApp<!-- -->.

Exceptions

If invoked in an unsupported non-server environment such as a browser.

If FirebaseServerAppSettings.releaseOnDeref is defined but the runtime doesn't provide Finalization Registry support.

Example

javascript

// Initialize an instance of `FirebaseServerApp`.
// Retrieve your own options values by adding a web app on
// https://console.firebase.google.com
initializeServerApp({
    apiKey: "AIza....",                             // Auth / General Use
    authDomain: "YOUR_APP.firebaseapp.com",         // Auth with popup/redirect
    databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
    storageBucket: "YOUR_APP.appspot.com",          // Storage
    messagingSenderId: "123456789"                  // Cloud Messaging
  },
  {
   authIdToken: "Your Auth ID Token"
  });

SDK_VERSION

The current SDK version.

<b>Signature:</b>

typescript
SDK_VERSION: string