Skip to main content
RapidDev - Software Development Agency
firebase-tutorial

How to Deploy Firebase Cloud Functions with the CLI

Deploy Firebase Cloud Functions using firebase deploy --only functions from the Firebase CLI. Before deploying, ensure your package.json specifies a supported Node.js version (18, 20, or 22), your code compiles without errors, and you are on the Blaze plan. Deploy specific functions with firebase deploy --only functions:functionName to speed up deployments. Common deployment failures include Node.js version mismatches, missing API enablement, and rate limits when deploying many functions at once.

What you'll learn

  • How to deploy all functions or specific functions with the Firebase CLI
  • How to set the correct Node.js version in package.json for deployment
  • How to troubleshoot common deployment errors like version mismatches and quota limits
  • How to use selective and group deployments for faster iteration
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner8 min read10-15 minFirebase Blaze plan, Cloud Functions v2, Firebase CLI 13.x+, Node.js 18/20/22March 2026RapidDev Engineering Team
TL;DR

Deploy Firebase Cloud Functions using firebase deploy --only functions from the Firebase CLI. Before deploying, ensure your package.json specifies a supported Node.js version (18, 20, or 22), your code compiles without errors, and you are on the Blaze plan. Deploy specific functions with firebase deploy --only functions:functionName to speed up deployments. Common deployment failures include Node.js version mismatches, missing API enablement, and rate limits when deploying many functions at once.

Deploying Firebase Cloud Functions with the Firebase CLI

Deploying Cloud Functions uploads your code to Google Cloud, builds it, and makes it available as HTTP endpoints or event-driven triggers. This tutorial covers the full deployment workflow: checking prerequisites, running the deploy command, deploying selectively, handling errors, and monitoring your deployed functions. You will learn the most common deployment pitfalls and how to fix them.

Prerequisites

  • A Firebase project on the Blaze (pay-as-you-go) plan
  • Firebase CLI installed and authenticated (npm install -g firebase-tools && firebase login)
  • A functions directory initialized with firebase init functions
  • At least one exported function in your functions/src/index.ts

Step-by-step guide

1

Verify your Node.js version in package.json

Firebase Cloud Functions require a supported Node.js runtime. Currently supported versions are 18, 20, and 22. Node.js 14 and 16 were decommissioned in early 2025. Check your functions/package.json for the engines.node field and update it if needed. This is the most common cause of deployment failures.

typescript
1// functions/package.json — check and update the engines field
2{
3 "name": "functions",
4 "scripts": {
5 "build": "tsc",
6 "serve": "npm run build && firebase emulators:start --only functions",
7 "deploy": "firebase deploy --only functions"
8 },
9 "engines": {
10 "node": "20"
11 },
12 "main": "lib/index.js"
13}

Expected result: The engines.node field in package.json specifies version 18, 20, or 22.

2

Build and deploy all functions

Run firebase deploy --only functions from your project root (not the functions/ directory). The CLI compiles your TypeScript code, uploads the bundle to Google Cloud, and creates or updates each exported function. The deployment process takes 1-3 minutes depending on the number of functions and dependencies.

typescript
1# Deploy all functions
2firebase deploy --only functions
3
4# What happens:
5# 1. Runs npm install in functions/
6# 2. Runs the build script (tsc for TypeScript)
7# 3. Uploads the bundle to Google Cloud
8# 4. Creates/updates each exported function
9# 5. Outputs the URL for each HTTP function

Expected result: All functions are deployed and their URLs (for HTTP functions) are printed to the terminal.

3

Deploy specific functions selectively

Deploying all functions can be slow if you have many. Use the --only flag with a specific function name to deploy just one function. You can also deploy multiple specific functions by separating names with commas. This is much faster for iterative development.

typescript
1# Deploy a single function
2firebase deploy --only functions:processOrder
3
4# Deploy multiple specific functions
5firebase deploy --only functions:processOrder,functions:stripeWebhook
6
7# Deploy functions along with Firestore rules
8firebase deploy --only functions,firestore:rules
9
10# Deploy everything except functions
11firebase deploy --except functions

Expected result: Only the specified function(s) are deployed, completing much faster than a full deployment.

4

Fix common deployment errors

The most common deployment errors are Node.js version mismatches, API not enabled, and quota exceeded. Here is how to identify and fix each one. Most errors include a link in the error message that helps you resolve the issue.

typescript
1# Error: "EBADENGINE" or "Unsupported engine"
2# Fix: Update engines.node in functions/package.json to 18, 20, or 22
3
4# Error: "Functions did not deploy properly"
5# Fix: Check the build output for TypeScript errors. Run:
6cd functions && npm run build
7# Fix any compilation errors, then deploy again
8
9# Error: "Quota Exceeded while trying to update"
10# Fix: Deploy in smaller batches (10 or fewer functions at a time):
11firebase deploy --only functions:fn1,functions:fn2,functions:fn3
12
13# Error: "Cloud Build API has not been used in project"
14# Fix: Enable the API at:
15# https://console.cloud.google.com/apis/library/cloudbuild.googleapis.com
16
17# Error: "Permission denied" or "Insufficient permissions"
18# Fix: Ensure you are logged in with the right account:
19firebase login --reauth

Expected result: Common deployment errors are identified and resolved.

5

Monitor deployed functions

After deployment, monitor your functions in the Firebase Console under Functions. The dashboard shows each function's trigger type, region, runtime, memory allocation, and recent invocation count. Click on a function to see its logs, errors, and performance metrics. You can also view logs from the CLI.

typescript
1# View recent logs for all functions
2firebase functions:log
3
4# View logs for a specific function
5firebase functions:log --only processOrder
6
7# Follow logs in real-time (like tail -f)
8firebase functions:log --follow
9
10# View logs in the browser
11# Firebase Console > Functions > Logs
12# or Google Cloud Console > Cloud Logging

Expected result: Function logs are visible in the terminal and Firebase Console for monitoring and debugging.

6

Delete unused functions

When you remove a function from your code and redeploy, the Firebase CLI prompts you to delete the orphaned function. You can also delete functions manually from the Firebase Console or CLI. Removing unused functions prevents unexpected invocations and charges.

typescript
1# The CLI prompts when it detects orphaned functions:
2# ? Would you like to proceed with deletion? Selecting no will continue
3# the rest of the deployments. (y/N)
4
5# Manually delete a function via CLI
6firebase functions:delete processOrder
7
8# Delete a function in a specific region
9firebase functions:delete processOrder --region=europe-west1
10
11# Delete from Firebase Console:
12# Functions > click function > Delete button

Expected result: Unused functions are removed, preventing unnecessary invocations and charges.

Complete working example

functions/src/index.ts
1import * as admin from "firebase-admin";
2import { logger } from "firebase-functions";
3import { onRequest } from "firebase-functions/v2/https";
4import { onDocumentCreated } from "firebase-functions/v2/firestore";
5import { onSchedule } from "firebase-functions/v2/scheduler";
6
7admin.initializeApp();
8
9// HTTP function — accessible via URL after deployment
10export const healthCheck = onRequest(
11 { maxInstances: 10 },
12 async (req, res) => {
13 res.json({
14 status: "ok",
15 timestamp: new Date().toISOString(),
16 });
17 }
18);
19
20// Firestore trigger — fires on new document
21export const onOrderCreated = onDocumentCreated(
22 {
23 document: "orders/{orderId}",
24 maxInstances: 5,
25 },
26 async (event) => {
27 if (!event.data) return;
28 const order = event.data.data();
29 logger.info(`New order: ${event.params.orderId}`, order);
30 }
31);
32
33// Scheduled function — runs on a cron schedule
34export const dailyCleanup = onSchedule(
35 {
36 schedule: "every day 03:00",
37 timeZone: "America/New_York",
38 maxInstances: 1,
39 },
40 async () => {
41 logger.info("Running daily cleanup");
42 // Cleanup logic here
43 }
44);
45
46// Deploy commands:
47// firebase deploy --only functions (all)
48// firebase deploy --only functions:healthCheck (single)
49// firebase functions:log --only healthCheck (view logs)

Common mistakes when deploying Firebase Cloud Functions with the CLI

Why it's a problem: Deploying with an unsupported Node.js version (14 or 16) in package.json engines field

How to avoid: Update engines.node to '18', '20', or '22' in functions/package.json. Node.js 14 and 16 were decommissioned in early 2025.

Why it's a problem: Running firebase deploy from inside the functions/ directory instead of the project root

How to avoid: Always run firebase deploy from the project root where firebase.json is located. The CLI needs this config file to know what to deploy.

Why it's a problem: Deploying 20+ functions at once and hitting API rate limits (Quota Exceeded error)

How to avoid: Deploy in batches of 10 or fewer: firebase deploy --only functions:fn1,functions:fn2,...,functions:fn10. Wait a few minutes between batches.

Why it's a problem: Not running npm run build before deploying, leading to stale compiled code being deployed

How to avoid: The Firebase CLI runs the build script automatically during deploy. If you see stale behavior, run cd functions && npm run build manually to verify your TypeScript compiles without errors.

Best practices

  • Always specify a supported Node.js version (18, 20, or 22) in functions/package.json engines field
  • Deploy specific functions during development with --only functions:name for faster iteration
  • Run npm run build locally before deploying to catch TypeScript errors early
  • Set maxInstances on every function to prevent runaway scaling and unexpected charges
  • Use firebase functions:log --follow to monitor function behavior after deployment
  • Delete unused functions to avoid unexpected invocations — the CLI prompts for orphaned functions during deploy
  • Enable the Cloud Build API before your first deployment to avoid the 'API not enabled' error
  • Test functions in the Firebase Emulator Suite before deploying to production

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

Show me the complete workflow for deploying Firebase Cloud Functions: checking the Node.js version, running the build, deploying with the CLI, deploying specific functions, and fixing common errors like EBADENGINE and Quota Exceeded.

Firebase Prompt

Deploy my Firebase Cloud Functions. Check that functions/package.json has engines.node set to 20, run firebase deploy --only functions, and show me how to deploy a single function with firebase deploy --only functions:functionName. Include the commands for viewing logs after deployment.

Frequently asked questions

Do I need the Blaze plan to deploy Cloud Functions?

Yes. Cloud Functions are a Blaze-only feature. The free Spark plan does not support function deployment. However, the Blaze plan includes a free tier of 2 million invocations per month.

How long does a deployment take?

A typical deployment takes 1-3 minutes for a few functions. Large projects with 20+ functions can take 5-10 minutes. Deploying a single function with --only functions:name usually takes under 1 minute.

Can I deploy functions to a specific region?

Yes. Set the region in your function options: onRequest({ region: 'europe-west1' }, handler). The default region is us-central1. Choose a region close to your users for lower latency.

What happens to in-flight requests during deployment?

Firebase uses a rolling update strategy. Existing function instances continue handling current requests while new instances spin up with the updated code. There is no downtime during deployment.

How do I roll back a bad deployment?

The fastest way is to revert your code changes and redeploy. Firebase does not have a built-in rollback feature for functions. For critical apps, consider using version control and CI/CD pipelines that can redeploy the last known good version.

Why does my function work locally in the emulator but fail after deployment?

Common causes: environment variables or secrets not configured in the deployed environment (they exist in .env.local but not in .env or Cloud Secret Manager), Node.js version differences between local and deployed, and network restrictions in the production environment.

Can I deploy functions from a CI/CD pipeline?

Yes. Use a Firebase service account token: firebase login:ci generates a token you can use in CI. Set the FIREBASE_TOKEN environment variable, then run firebase deploy --only functions in your pipeline.

How many functions can I deploy in one project?

There is no hard limit, but deploying more than 10-15 functions simultaneously can trigger API rate limits (Quota Exceeded error). Deploy in batches of 10 or fewer for large projects.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.