firebase-admin.app package

Firebase App and SDK initialization.

Functions

FunctionDescription
applicationDefault(httpAgent)Returns a credential created from the Google Application Default Credentials that grants admin access to Firebase services. This credential can be used in the call to initializeApp().Google Application Default Credentials are available on any Google infrastructure, such as Google App Engine and Google Compute Engine.See Initialize the SDK for more details.
cert(serviceAccountPathOrObject, httpAgent)Returns a credential created from the provided service account that grants admin access to Firebase services. This credential can be used in the call to initializeApp().See Initialize the SDK for more details.
deleteApp(app)Renders this given App unusable and frees the resources of all associated services (though it does *not* clean up any backend resources). When running the SDK locally, this method must be called to ensure graceful termination of the process.
getApp(appName)
getApps()
initializeApp(options, appName)
refreshToken(refreshTokenPathOrObject, httpAgent)Returns a credential created from the provided refresh token that grants admin access to Firebase services. This credential can be used in the call to initializeApp().See Initialize the SDK for more details.

Classes

ClassDescription
AppErrorCodesApp client error codes and their default messages.
FirebaseAppErrorFirebase App error code structure. This extends PrefixedFirebaseError.

Interfaces

InterfaceDescription
AppA Firebase app holds the initialization information for a collection of services.
AppOptionsAvailable options to pass to initializeApp().
CredentialInterface that provides Google OAuth2 access tokens used to authenticate with Firebase services.In most cases, you will not need to implement this yourself and can instead use the default implementations provided by the firebase-admin/app module.
FirebaseArrayIndexErrorComposite type which includes both a FirebaseError object and an index which can be used to get the errored item.
FirebaseErrorFirebaseError is a subclass of the standard JavaScript Error object. In addition to a message string and stack trace, it contains a string code.
GoogleOAuthAccessTokenInterface for Google OAuth 2.0 access tokens.
ServiceAccount

Variables

VariableDescription
SDK_VERSION

applicationDefault(httpAgent)

Returns a credential created from the Google Application Default Credentials that grants admin access to Firebase services. This credential can be used in the call to initializeApp().

Google Application Default Credentials are available on any Google infrastructure, such as Google App Engine and Google Compute Engine.

See Initialize the SDK for more details.

Signature:

exportdeclarefunctionapplicationDefault(httpAgent?:Agent):Credential;

Parameters

ParameterTypeDescription
httpAgentAgentOptional HTTP Agent to be used when retrieving access tokens from Google token servers.

Returns:

Credential

A credential authenticated via Google Application Default Credentials that can be used to initialize an app.

Example

initializeApp({credential:applicationDefault(),databaseURL:"https://<DATABASE_NAME>.firebaseio.com"});

cert(serviceAccountPathOrObject, httpAgent)

Returns a credential created from the provided service account that grants admin access to Firebase services. This credential can be used in the call to initializeApp().

See Initialize the SDK for more details.

Signature:

exportdeclarefunctioncert(serviceAccountPathOrObject:string|ServiceAccount,httpAgent?:Agent):Credential;

Parameters

ParameterTypeDescription
serviceAccountPathOrObjectstring | ServiceAccountThe path to a service account key JSON file or an object representing a service account key.
httpAgentAgentOptional HTTP Agent to be used when retrieving access tokens from Google token servers.

Returns:

Credential

A credential authenticated via the provided service account that can be used to initialize an app.

Example 1

// Providing a path to a service account key JSON fileconstserviceAccount=require("path/to/serviceAccountKey.json");initializeApp({credential:cert(serviceAccount),databaseURL:"https://<DATABASE_NAME>.firebaseio.com"});

Example 2

// Providing a service account object inlineinitializeApp({credential:cert({projectId:"<PROJECT_ID>",clientEmail:"foo@<PROJECT_ID>.iam.gserviceaccount.com",privateKey:"-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"}),databaseURL:"https://<DATABASE_NAME>.firebaseio.com"});

deleteApp(app)

Renders this given App unusable and frees the resources of all associated services (though it does *not* clean up any backend resources). When running the SDK locally, this method must be called to ensure graceful termination of the process.

Signature:

exportdeclarefunctiondeleteApp(app:App):Promise<void>;

Parameters

ParameterTypeDescription
appApp

Returns:

Promise<void>

Example

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

getApp(appName)

Signature:

exportdeclarefunctiongetApp(appName?:string):App;

Parameters

ParameterTypeDescription
appNamestring

Returns:

App

getApps()

Signature:

exportdeclarefunctiongetApps():App[];

Returns:

App[]

initializeApp(options, appName)

Signature:

exportdeclarefunctioninitializeApp(options?:AppOptions,appName?:string):App;

Parameters

ParameterTypeDescription
optionsAppOptions
appNamestring

Returns:

App

refreshToken(refreshTokenPathOrObject, httpAgent)

Returns a credential created from the provided refresh token that grants admin access to Firebase services. This credential can be used in the call to initializeApp().

See Initialize the SDK for more details.

Signature:

exportdeclarefunctionrefreshToken(refreshTokenPathOrObject:string|object,httpAgent?:Agent):Credential;

Parameters

ParameterTypeDescription
refreshTokenPathOrObjectstring | objectThe path to a Google OAuth2 refresh token JSON file or an object representing a Google OAuth2 refresh token.
httpAgentAgentOptional HTTP Agent to be used when retrieving access tokens from Google token servers.

Returns:

Credential

A credential authenticated via the provided service account that can be used to initialize an app.

Example

// Providing a path to a refresh token JSON fileconstrefreshToken=require("path/to/refreshToken.json");initializeApp({credential:refreshToken(refreshToken),databaseURL:"https://<DATABASE_NAME>.firebaseio.com"});

SDK_VERSION

Signature:

SDK_VERSION:string