Firebase cloud function

Source: Medium
Web and mobile application often require back-end code to execute tasks like sending out notifications or processing long running tasks.
Firebase offers a scalable solution for running the back-end code in the cloud. Not in your devices. Cloud function action is called when the events are triggered in firebase.
Advantages of using firebase cloud function
No need to run and maintain your own server
You have an isolated code base for back-end code
You only get billed for the actual executing time of your code
The cloud infrastructure is highly scalable
Prerequisites
If we want to run the cloud function we need to install the below things
Install Node.js Link
Firebase CLI in your local machine
Firebase account
Installing Firebase CLI in local machine
npm install -g firebase-tools
Log in with your firebase account from CLI
firebase login
Once logged in successfully initialize firebase
firebase init


First, choose a project.
The next question you’re being asked is “Do we want to install dependencies with npm now?”. As we would like to add all necessary dependencies you need to say “Y” here or simply hit return as “Y” is the default setting.
Now you can see this screen in your terminal:

Once initialized you can navigate to your project and its structure would be like

In index.js file add the below code

It’s time to deploy our code
firebase deploy

If you’re opening up the current Firebase project in the back-end and click on the link Functions you should be able to see the deployed helloWorld function in the Dashboard:





