HomeAbout Us
Setup Firebase Cloud Function
developer
Setup Firebase Cloud Function
Kevin Mustafa
Kevin Mustafa
July 22, 2021
1 min

Preparations

First of all you have to create Firebase project in Firebase Console, for more informations about Firebase project you can learn more here. In this tutorial I will be using Node.js environment. You can check the supported Node.js version for Firebase here.

Now, I assume that you already create the Firebase project and have Node.js environment installed. Next step is you need to install the firebase CLI using:

npm install -g firebase-tools

Initialize local Firebase Project

After that, login into Firebase.

firebase login

Next, go to your local Firebase Project directory and initialize the firestore and cloud functions.

cd YOUR_FIREBASE_PROJECT_DIRECTORY
firebase init firestore
firebase init functions

Creating and Emulating the Cloud Functions

After that, Import required modules and then initialize the app inside your index.ts file.

/* index.ts */
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();

Now, you can create your public Firebase cloud functions using functions.https.onCall() and functions.https.onRequest() callback functions that can be used over https call inside your index.ts file.

Next, start the Firebase cloud function emulator in local environment using:

firebase emulators:start

Check the output of this command to get the URL format to call the cloud functions it will be looks like this:

http://localhost:5001/MY_PROJECT_ID/us-central1/

The port may be vary according to your local machine environment.

Deploying Firebase Cloud Functions

Deploying Firebase cloud functions to productions is a quite simple process you can just directly run this command:

firebase deploy --only functions

Congratulation! You have successfully creating and deploying your Firebase cloud functions, now you can access the cloud functions that you have created to your React application. If you don't have any React application yet you can follow this tutorial to create a React application using typescript and tailwind css.


Tags

#developer#open-source#web-development#web-servers
Kevin Mustafa

Kevin Mustafa

Indonesia

I am Kevin, nice to meet you.

Expertise

Related Posts

Top 7 Coding Challenges
Top 7 Coding Challenges
August 21, 2021
1 min
© 2021, All Rights Reserved.

Quick Links

About Us