Firebase Cloud Functions is a new feature offered by the Google platform and announced in 2017.

This new functionality allows you to create functions written in JavaScript, in a Node.js environment, which are invoked by Firebase events (When writing to the database, when a user is created, when a file is uploaded, etc). This allows us to have a quite complete Backend as a Service solution with Firebase.

The Cloud Functions are composed of 3 levels in what refers to Cloud Computing :

& nbsp; & nbsp; • & nbsp; & nbsp; Infrastructure as a Service (IaaS): At this level you have full access to the virtual machine where you can choose the Operating System and install what you want. The advantage is that you have total freedom and the disadvantage is that you need to control many things (Security, Updates of S.O., environment, etc ..) Some examples of IaaS services would be:
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Amazon EC2
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Google Cloud Compute Engine
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Digital Ocean

& nbsp; & nbsp; • & nbsp; & nbsp; Platform as a Service (PaaS):
In this second level you do not have to worry about the Operating System or the relative security patches, you simply focus on your App (backend + frontend) and deploy it in the environment that you offers the provider, the vast majority allow all kinds of languages ​​(Node.js, Python, Ruby, Java, etc ...) Some examples of PaaS services are:
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Google Cloud App Engine
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Heroku

& nbsp; & nbsp; • & nbsp; & nbsp; Functions as Service (FaaS): This third level completely abstracts you from the operating system, from the development of the full backend and from the maintenance of a monolithic system. With the functions, you can have your Backend divided into microservices that would be the different functions and each of them would be responsible for a specific task. The services that offer this right now are:
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Amazon Lambda
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Google Cloud Functions
& nbsp; & nbsp; â—¦ & nbsp; & nbsp; Cloud Functions for Firebase

What can I do with Cloud Functions?

Una Once placed in a situation, let's see what kind of things Cloud Functions allow us to do, specifically those provided by Firebase.

& nbsp; • & nbsp; & nbsp; Notifications: We can send push notifications to our users' devices by joining Firebase Cloud Messaging and the database trigger that jumps when we write in a certain record, for example when a user has a new "follower":

& nbsp; • & nbsp; & nbsp; Message filtering: By joining the triggers of the database with the Cloud Functions again we can make it possible to write a message in a database registry, to "sanitize" it (remove HTML or malicious JS code, hide information type emails or phone numbers, etc ...) and write it "clean" in the database:

& nbsp; • & nbsp; & nbsp; Image processing: Combining Firebase Storage triggers with the database and the Cloud Functions, we can make each time a user upload an image to the Storage, download it, reduce it in size and put it back in Storage and write a record in the database. All with a function.
And many more that are triggered if you join the Machine Learning APIs that Google Cloud has (Vision, Video, Speech, Translate, etc ...) But that is the subject of another post:)