Firebase project deployment functionality for deploying code, configuration, and resources to Firebase projects.
Deploys Firebase project resources to the cloud. Supports selective deployment of specific services.
/**
* Deploy Firebase project resources
* @param targets - Array of deployment targets to deploy
* @param options - Deployment configuration options
* @returns Promise resolving when deployment completes
*/
function deploy(
targets?: Array<"database" | "storage" | "firestore" | "functions" | "hosting" | "remoteconfig" | "extensions" | "dataconnect" | "apphosting">,
options?: Options & {
/** Only deploy specified targets (comma-separated) */
only?: string;
/** Deploy all except specified targets (comma-separated) */
except?: string;
/** Force deployment without confirmation */
force?: boolean;
/** Deployment message/description */
message?: string;
/** Skip functions pre-deploy hooks */
skipFunctionsPredeployTrigger?: boolean;
/** Export data before deploying database rules */
export?: string;
}
): Promise<{
status: "success" | "error";
hosting?: {
site: string;
url: string;
expireTime?: string;
};
functions?: Array<{
name: string;
status: "deployed" | "failed";
httpsTrigger?: {
url: string;
};
}>;
}>;Usage Examples:
const client = require("firebase-tools");
// Deploy everything
await client.deploy(undefined, {
project: "my-project"
});
// Deploy only hosting
await client.deploy(["hosting"], {
project: "my-project",
message: "Deploy new website version"
});
// Deploy functions and firestore
await client.deploy(["functions", "firestore"], {
project: "my-project",
force: true
});
// Deploy using --only syntax
await client.deploy(undefined, {
project: "my-project",
only: "hosting,functions:myFunction"
});
// Deploy everything except database
await client.deploy(undefined, {
project: "my-project",
except: "database"
});Deploys Firebase Realtime Database rules and indexes.
database.rules.json, .indexOn rulesDeploys Firebase Storage security rules.
storage.rulesDeploys Cloud Firestore security rules and indexes.
firestore.rules, firestore.indexes.jsonDeploys Cloud Functions code and configuration.
package.jsonDeploys static website files to Firebase Hosting.
public/)Deploys Remote Config templates and parameters.
Deploys Firebase Extensions configuration.
Deploys Firebase Data Connect services and schemas.
Deploys Firebase App Hosting applications.
Deployment behavior is controlled by firebase.json configuration:
{
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"runtime": "nodejs20"
}
],
"hosting": {
"public": "dist",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
},
"remoteconfig": {
"template": "remoteconfig.template.json"
}
}Deployment can fail due to various reasons:
Common Error Patterns:
try {
await client.deploy(["functions"], { project: "my-project" });
} catch (error) {
if (error.status === 403) {
// Permission denied
console.error("Insufficient permissions for deployment");
} else if (error.status === 400) {
// Bad request - likely syntax error
console.error("Configuration error:", error.message);
} else {
// Other deployment errors
console.error("Deployment failed:", error.message);
}
}