Tuesday, May 15, 2018

Android - Set-up Firebase Cloud Functions.

Web and mobile application often require back-end code to execute tasks like send push notifications, mail and update user information.
Firebase has a functionality which is called Cloud Functions. Firebase offers a scalable solution for running back-end code in the cloud. Running code in the cloud has various advantages:

1. You don't need to run and maintain your own server.

2. You do have an isolated code base for back-end code.
3. You only get billed for the actual executing time of your code,
4. The cloud infrastructure is highly scalable.
  
 Introduction of Cloud Functions.

In the following tutorial, I'm going to install all the tools that are we need for Cloud Functions development. Let's start it.

1. Download Node.js and install it.



2. Set environment variable of Node.js installed location.

 





2. Install Firebase CLI (Command Line Interface)

Open run->cmd and hit npm install -g firebase-tools





3. Now login with your google account: run->cmd->firebase login. Maybe it will redirect on default browser for login on google account. So, do it carefully.

If you facing firebase login issue, you can try these.


firebase login --no-localhost
firebase login:ci --interactive
firebase login --interactive
firebase login:ci --no-localhost

If you successfully log in it. you will move here.



4. Create a project directory folder where you will find the cloud function of the project. like i have created AndroidStudioProjects folder.
5. Now, open cmd and run firebase init functions command.



It will show all project that you have created on firebase console or you can create new project on firebase
console from here.


6. When it's done you'll find three new things in your project directory:

1. "functions" folder
2. .firebaserc file
3.  firebase.json file



Building the Firebase Cloud Function

Now, Let's do some code for the cloud that will execute. For it, i'm going to install Visual Studio code and open index.js. 




You can build the Cloud Functions in a file name index.js. The index.js file is located inside the "functions" folder that you just created by initializing Cloud Functions.

Here's the Cloud Function: that will work on the firebase server.



Deploying the Cloud Function.

Once you created cloud function, deploy it with firebase deploy --only functions command to Firebase. Be patient this can take a while.







So, Here all that we need to start cloud function development. But if you still have any doubt, please feel free to clarify that in the comment section below.


Share:

Get it on Google Play

React Native - Start Development with Typescript

React Native is a popular framework for building mobile apps for both Android and iOS. It allows developers to write JavaScript code that ca...