How to deploy your first firebase function

  • by
  • Installing Node.js
  • Set up Node.js for Firebase
  • Initialize Firebase SDK
  • Creating your first Http function
  • Deploying to Firebase function.
  • Execute the firebase function

Installing Node.js

Install Node.js from https://nodejs.org/en/download/

For Ubuntu -: How to Install Node.js 12 on ubuntu 20.04

Setup Node.js for Firebase

Install firebase tools using below command.

npm install -g firebase-tools

Initialize Firebase SDK

Login to firebase using.

firebase login

Now initialize your project using

firebase init

Follow the onscreen options and select appropriate options.

Enter Y for Do you want to install dependencies with npm now?

After everything is done you will see ✔ Firebase initialization complete!

Now you will see a functions folder created under the directory.

Creating your first Http function

Now open the functions folder or index.js file in your favorite text editor created from previous command.

You will see this default code inside index.js file.

Now uncomment the whole file code from line 3 to 9 you will get this.

Deploying to Firebase function.

To start deploy your function to the firebase server run the following command.

firebase deploy --only functions

After successfully deploying your function, the Firebase CLI outputs the URL for any HTTP function endpoints. In your terminal, you should see a line like the following:

Function URL (helloWorld): https://us-central1-MY-PROJECT.cloudfunctions.net/helloWorld

Execute the firebase function

Run the endpoint using curl or browser you will see the output -: Hello from Firebase!

Congratulation your first firebase function deployed and run.

Leave a Reply

Your email address will not be published. Required fields are marked *