0
0
Firebasecloud~5 mins

Function deployment in Firebase - Commands & Configuration

Choose your learning style9 modes available
Introduction
Deploying functions means sending your code to the cloud so it can run when needed. This solves the problem of running code without managing servers or worrying about uptime.
When you want to run backend code triggered by events like HTTP requests or database changes.
When you need to add features to your app without updating the app itself.
When you want to run code that scales automatically based on demand.
When you want to avoid managing servers and focus only on your code.
When you want to quickly fix or update backend logic without downtime.
Config File - firebase.json
firebase.json
{
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
  }
}

This file tells Firebase where your function code lives under the functions folder. It also configures hosting settings if you serve a website. The ignore list prevents unnecessary files from being uploaded.

Commands
Logs you into your Firebase account so you can deploy functions to your project.
Terminal
firebase login
Expected OutputExpected
✔ Success! Logged in as your-email@example.com
Sets up the functions folder and configuration files in your project to prepare for writing and deploying functions.
Terminal
firebase init functions
Expected OutputExpected
=== Functions Setup === ✔ Functions folder: functions ✔ Language: JavaScript ✔ ESLint: No ✔ Install dependencies: Yes Firebase initialization complete!
Uploads and activates your functions code in the cloud so they can start running when triggered.
Terminal
firebase deploy --only functions
Expected OutputExpected
=== Deploying to 'your-project-id' === i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint ✔ functions: Finished running lint. ✔ functions: Finished running predeploy script. ✔ functions[helloWorld]: Successful update operation. ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/your-project-id/overview
--only functions - Deploys only the functions part without affecting other Firebase services.
Shows all the functions currently deployed in your Firebase project to verify deployment.
Terminal
firebase functions:list
Expected OutputExpected
Function Name: helloWorld Status: ACTIVE Trigger: HTTP Region: us-central1
Key Concept

If you remember nothing else from this pattern, remember: deploying functions sends your backend code to the cloud so it runs automatically when triggered.

Common Mistakes
Running 'firebase deploy' without logging in first
The deploy command fails because it cannot authenticate your account.
Always run 'firebase login' before deploying to authenticate your session.
Not running 'firebase init functions' before deploying
Without initialization, the functions folder and config files are missing, so deployment fails.
Run 'firebase init functions' once to set up your project before deploying.
Deploying without specifying '--only functions' when you only want to update functions
This can unintentionally deploy other Firebase services, causing longer deploy times or unwanted changes.
Use 'firebase deploy --only functions' to deploy only your functions.
Summary
Run 'firebase login' to authenticate your Firebase account.
Initialize your functions setup with 'firebase init functions'.
Deploy your functions code using 'firebase deploy --only functions'.
Verify your deployed functions with 'firebase functions:list'.