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
Verify your Node.js version in package.json
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.
1// functions/package.json — check and update the engines field2{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.
Build and deploy all functions
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.
1# Deploy all functions2firebase deploy --only functions34# 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 Cloud8# 4. Creates/updates each exported function9# 5. Outputs the URL for each HTTP functionExpected result: All functions are deployed and their URLs (for HTTP functions) are printed to the terminal.
Deploy specific functions selectively
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.
1# Deploy a single function2firebase deploy --only functions:processOrder34# Deploy multiple specific functions5firebase deploy --only functions:processOrder,functions:stripeWebhook67# Deploy functions along with Firestore rules8firebase deploy --only functions,firestore:rules910# Deploy everything except functions11firebase deploy --except functionsExpected result: Only the specified function(s) are deployed, completing much faster than a full deployment.
Fix common deployment errors
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.
1# Error: "EBADENGINE" or "Unsupported engine"2# Fix: Update engines.node in functions/package.json to 18, 20, or 2234# Error: "Functions did not deploy properly"5# Fix: Check the build output for TypeScript errors. Run:6cd functions && npm run build7# Fix any compilation errors, then deploy again89# 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:fn31213# 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.com1617# Error: "Permission denied" or "Insufficient permissions"18# Fix: Ensure you are logged in with the right account:19firebase login --reauthExpected result: Common deployment errors are identified and resolved.
Monitor deployed functions
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.
1# View recent logs for all functions2firebase functions:log34# View logs for a specific function5firebase functions:log --only processOrder67# Follow logs in real-time (like tail -f)8firebase functions:log --follow910# View logs in the browser11# Firebase Console > Functions > Logs12# or Google Cloud Console > Cloud LoggingExpected result: Function logs are visible in the terminal and Firebase Console for monitoring and debugging.
Delete unused functions
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.
1# The CLI prompts when it detects orphaned functions:2# ? Would you like to proceed with deletion? Selecting no will continue3# the rest of the deployments. (y/N)45# Manually delete a function via CLI6firebase functions:delete processOrder78# Delete a function in a specific region9firebase functions:delete processOrder --region=europe-west11011# Delete from Firebase Console:12# Functions > click function > Delete buttonExpected result: Unused functions are removed, preventing unnecessary invocations and charges.
Complete working example
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";67admin.initializeApp();89// HTTP function — accessible via URL after deployment10export const healthCheck = onRequest(11 { maxInstances: 10 },12 async (req, res) => {13 res.json({14 status: "ok",15 timestamp: new Date().toISOString(),16 });17 }18);1920// Firestore trigger — fires on new document21export 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);3233// Scheduled function — runs on a cron schedule34export 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 here43 }44);4546// 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.
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.
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.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation