Cloud functions for Firebase - Complete Tutorial (incl. Firebase Emulator)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay guys so welcome back again so in this video we'll be talking about cloud functions for firebase so the first question is that what are cloud functions so basically cloud functions provide you with serverless framework to automatically run your backend code or your microservices in response to events that are triggered by https request or certain events triggered by your firebase project that is for example if a user registers inside your firebase project that is if you are using firebase authentication then you can trigger a function when a user registers or when a user is deleted from your firebase authentication system and similarly we can also trigger events whenever we write documents inside our firestore database that is in case if you are using firestore database as a database for your project then we can also trigger functions and moreover we can create scheduled functions like cron jobs that run at a particular interval of time or at a certain date and time so without wasting any time let's dive into our code and let's see that how do we create these cloud functions so let's go to our terminal and here we see that we are inside this directory called fire functions so currently it is an empty directory as you can see here so let me clear out the console once again so the first thing you need to do is to install firebase tools globally on your system so for that what you need to do you need to simply do npm install hyphen g firebase hyphen tools to install firebase tools or that is the firebase cli globally on your system but i am not doing it because it is already installed so let me stop it and now to check whether the tools have been installed successfully what you can do you can simply type in firebase hyphen hyphen version to check the firebase version cli you are running on your system so here i am at 9.6.1 so now the next step is to authenticate ourselves with firebase so how do we do it it is very simple we simply need to do firebase login simply like this and as we can see that i am currently logged in with this user so let me show you the login process for that i need to log out here first so firebase logout and now i'll do firebase login again so firebase login again and now let's see that what will happen and now it asks us whether we want error reporting so let me simply press no here and a tab will open in our browser and here you need to choose an account to continue to firebase so here let me choose my account and now it would be completed in a moment and now we simply need to click on allow and now our login is successful so we can close this tab and we can go back and now we see that we are getting this message here that is successfully logged in with use this user id that is with this email so now let me again clear out the console here and now what we will do we will create a new project inside our firebase console and this is the same console with the same user that is with the same email address so here what we need to do we simply need to add a new project here so let me simply click add project and here we can provide in the name of the project so let's simply call it firebase functions simply like this and now let's click on continue and we do not want to enable google analytics here so let me uncheck this thing here and now let's simply click on create project and now it will take a moment or so to create your project so now the project is ready so let's click on continue once again and now we are inside our project here and if we click here inside functions we see that our functions there are no functions inside this functions tab here so let's set up our functions here inside this project so how do we do it let's go back to our terminal here and here we are inside this directory called fire functions and this can be any empty directory inside your system so every ls here the directory is empty so firstly what we need to do we simply need to do firebase init simply to initialize a new firebase project inside this directory that is called fire functions so now let's press enter and now it asks us that what all features that is what all firebase features we want to implement inside this project so since we are only interested in functions so let's go select this functions and let's simply press spacebar to select functions here though you can use other features also that is you can also deploy rules for your firestore database here but currently we are only interested in functions here so let's simply select functions and let's press enter and now it asks us to select a project so we can use an existing project or we can create a new project but since we already created a project right right now that is this firebase function so we will use this project so let's simply select this thing here that is use an existing project and now it gives us a list of projects in our inside our firebase dashboard so here what we need to select we need to select this project that is firebase functions so now let's simply press enter here and now our project would be set up in a moment so now we need to select the language which we want to use inside our cloud functions that are to write our cloud functions so for this i am going to select javascript so let's select it and now do we want to force eslint so we will select no and i would highly recommend you to select no here if you don't know that what eslint is for so let's simply select n here that is no and then we want to install the dependencies yes obviously we do want though it only installs two dependencies that is the firebase functions and the firebase admin sdk so now the initialization is complete and now let's clear out the console here and let's open a vs code here so here we see that we have these three files and this functions folder here so we have this firebase.json file which is currently an empty file we have the dot get ignore files it is only for git purposes so if we have a look at this firebase source file that is firebase rc file we see that here we have the projects and the default project is this fire functions project and now let's have a look at this functions folder and here inside this functions folder we have a couple of files that is the node modules folder that is typically used inside node.js applications and then again we have a git ignore file then we have the index.js file a package.json file and a package.json file so if we have a look at this package.json file we see that we only have two dependencies here that is the firebase admin that is the admin sdk and the firebase functions dependency that is firebase functions so now let's have a look at this index.js file and here we see that functions is imported or this it is required from firebase functions that is the dependency here so now before writing any function what i'll do i'll start my emulator that is the firebase emulator locally on our system because it is super handy and it is super easy to use firebase emulator whenever you are in development mode and you are trying to create functions so for that what we need to do we need to go back to our project here that is inside the root folder of our project so here what we need to do we need to simply do firebase init emulators simply like this and let's press enter and now it asks us that what all emulators do we want to have so we want to have an authentication emulator because we want to see how a function is triggered whenever someone authenticates with our application so therefore we want an authentication emulator also we want the function simulator and the firestore emulator and the pub sub emulator so now let's simply press enter and now it asks us both for each of the emulator source you can simply press enter enter enter again and again because it will take the default ports for the emulator to run and now it asks us whether you want to enable the emulator ui of course we do so let's press y and now for the emulator ui let's leave an empty port to choose an any available port so do we like to download the emulator so yes we do want to download the emulators and now the emulators have been downloaded so now how to start the emulator we simply need to do firebase emulators colon start so now let's press enter and in a moment our emulators would be up and running and we will be seeing them inside our browser so we see that the emulators are up and running so we can visit this url that is local host port 4000 and we see that our emulator is up and running and we have the authentication emulator we have the firestore emulator the function simulator and the pub sub emulator and this emulator is mostly used for scheduled functions so if we go to the authentication emulator we can add a user here and let's go back and if we view the logs here that is the function simulator we'll be seeing that what all functions we have deployed here so now let's go back to our vs code and here what i'm going to do i'm going to write a very simple first function which triggers on an https request so for that what we need to do we simply need to export a function here that is exports dot and the name of the function so let's call our function hello world simply like this and then this should be equal to functions and this functions is required at the top here and then dot https because we are handling the http functions and then here we have a method or a function that is on request and here we have the typical request and response handler simply like this and these functions which you write here that is inside this on request thing they basically follow the express.js type of syntax so here what we can do here we can simply send back a response so rest dot send and here we can simply say hello from firebase function simply like this and there should be no w in hello so now let's save this and this is the request object and this is the response object so we have saved this function and let's go back we see that our function is initialized at this url that is in http function initialized and this all we are seeing inside the logcat here so we see that our function hello world is deployed to this url that is http localhostport5001 and something something something so let's click here and let's go to this url so let's see so we see here that we are getting this message here that is hello from firebase function so if you open the emulator suit also so we see here also that is http http function is initialized and the url is this url so now you know that how to write a very simple https function so let's take it one step further so now what if you want to handle other type of request that is other type of http request because currently we were only handling the get request that is whenever you make a request to a url inside a browser it typically sends a get request so how how can you handle a post request a delete request a put or patch request it is pretty simple to do so what you can do you can simply uh do it like this that is again i'm creating a new function here just to be explicit so let's call it m api or let's call it api simply like this this should be equal to again functions dot https dot on request and here we have the request comma response and this should be in parentheses simply like this and here we can use the switch statement to select the case depending on the type of http request that is made to this url so we can use switch and here we can switch to request dot method simply like this and then here we will have our cases that is case one would be get request like this and then we can simply break here that is break like this and here we can simply send back a response so rest.send and let's let's simply send back that get request that is it was a get request simply like this so let me write it here that it was a get request and now let's simply create other cases also so now let me simply copy this case from here and let's create other two cases or three cases so this should be a post request and we can change this get to post simply like this or we'll do something else inside this post request but let it be for now and here we can simply call it a delete request that is an http delete request and let's simply paste delete here and then we also have our default case that is to handle other cases as well so here we can simply say rest.in it was a default a request simply like this and now inside this post request what i want is that that i want to send the incoming post request body back to the client instead of simply sending back it was a post request what we can do we can have the body that is the request body or we can extract the request body like this so we can say const body equal to request dot body simply like this and if you are coming from the express.js background then it this should be very familiar to you that is this is how we handle request body inside express applications so here what we can do here we can simply send back body simply like this if we save this file here and if we go back here inside our terminal we see that this function that is from api function is already deployed on our local host and if we visit this url we see that we are getting this message that is it was a get request so let's see that how do we see other kinds of requests so for that what i'm going to do i'm going to create a new file inside my functions folder and i'm i'm using this package here that is this i'm using this package here that is this extension inside va school that is called risk client and basically it allows us to make api calls using different kinds of http verbs that is get post put patch and delete and we do not need to leave our terminal here to check the api so let's close this from here and for this to work what we need to do we need to create a new file inside the functions folder so let's see into the functions folder and now i'll create a new file here that is called dot http simply like this and now we can close this terminal here and now we have this file that is rest.http and here we can simply write our get request so the request would be get and the url we can get it from here that is this is the url so let me simply copy the url and let's go back here inside our terminal or inside vs code and let's paste it here and let's simply make a get request so we see that we are getting this message here that is it was a get request so similarly we can also make a post request so let me copy the url again and let's simply paste it here so let me paste it here and this should be a post request and now to separate this get in post request we need to use three hashes and now for post request let's simply send in a content type header so content type would be application json that is the type of request body we are sending and here we can simply say name would be truly methyl like this and here we can also provide in college and the college would be iit guwahati simply like this and let's simply send a post request to this url that is to the function so let me make a request here we see that we are getting back this response back that is coming from request.body because if we have a look at index.js file we see that inside the post request we are simply sending back the body that is request.body so now let's close this and now we can also make our delete request so let me simply copy this again and let's paste it here and now let's separate it and this should be a delete request and let me paste it one more time and let me paste it one more time and this should be a put request or a patch request whatever you want to have so now let me simply send this request that it has a delete request so we are getting back a response it was a delete request and if we simply make a put request we'll be getting the default response back so as we can see here that is inside the default uh case we are simply sending back that it was a default request so this is how we handle different type of http verbs inside your of cloud functions and moreover we can use a whole express application inside cloud functions also and not in this video i'm talking about that how do you handle express application inside cloud functions but this is how you can handle simple things and now let me show you one more thing that is you can use each and every npm package inside cloud functions so for that we are inside the functions folder here so let me clear out here and if we do ls here we are inside this functions folder that is inside this functions folder not in the root folder of our firebase project but inside the functions folder and here what we can do we can install any npm dependency here so for simplicity let me simply install a dependency called axios like this so let's simply do npmi xeos and now we have this dependency inside our package.json file as we can see and now we can use this dependency to make a get request to another url so firstly let me simply require axios at the top here and here this should be equal to require axios and now inside the get request we were simply sending back a get request but instead what we want to send back we want to call our url that is we want to call this url that is placeholder api and we want to get this user from this api and this is a public url that is jsonplaceholder.typecode.com which is a fake rest api for testing purposes so i'm using this api and here to this url i want to make a get request to get this json back from this api and then we want to send it back to the client using our functions so here what we can do we can simply say const response equal to await axios dot get and here we need to pass in the url and since we are using await here we need to mark this function as async so let's mark it as async function and here instead of sending back a single string here what we need to send we simply need to send response dot data because in axios the response.data thing contains the actual json that is coming back from the from the api so if we save this and if we go to this url that is this url that is our api url so let's open this url so we see that we are getting back this response that is coming from the placeholder api though we did not call this api directly but instead we called our function and a function made a request to this api and then that response from the api has been sent back to the client so i think you know that what i meant here so this is how you can handle http request inside your functions so now let's have a look at something else and that is how do we handle events triggered from firebase features so let's go to our overview here and now here what i'll do i'll simply go to this authentication emulator and here what i'll do i'll simply try to add a user here so let the display name be john doe and let his email be john doe at gmail.com and password would be one two three four five six so let's simply save this so now we see that we have this user here inside our firebase emulator so what we wanted here is that that whenever a user is created either inside firebase console or a client that is your firebase client is creating a user or a user tries to register on your site we want to have a function to be triggered so that we can send a welcome email to that user so how do we do it it is pretty simple to do we need to go back to our index.js file that is inside the functions folder and here what we will do we will export another function here so we will simply say exports dot and again you need to provide in a function name and here i am simply providing in a function name that is called user added simply like this this is the name of the function and then what we have here we have the functions dot auth dot user dot on create and on delete so we want to handle the on create event and here what we have we simply have the user that is created inside your firebase authentication system so here what you can do we can simply write in like console dot log user created or let me use backtext here and let me use the template string here that is user dot email is created simply like this and here what we need to do we need to return something and here we need to resolve the problem so we can simply say return promise dot resolve simply like this and similarly we have an event for on delete event of the user so let's simply copy this function here and let's simply paste it here and this function's name would be user deleted simply like this so that in case the user is deleted you can send him an email that why have you deleted your account from our from our project so so you can do something like that and here we can simply say user dot email deleted simply like this and instead of the oncreate event we have the on delete event here simply like this so let's save this thing from here and let's go back to our firebase emulator here and if we go to our terminal here we see that two more functions have been initialized that is the auth functions that is user added and user deleted so let's see that in console here that is firstly what i'm going to do i'm going to add in a user again so the display name would be truly methyl and let's provide an email here so let me simply provide in my email here so at gmail.com password would be one two three four five six so let's save it and we see that our user is created here but if we go to our terminal here we see that truly method gmail.com is created and this is coming from this function here that is user added function so now let's try to delete a user so let's try to delete john doe so let's simply click here and let's delete it so let's simply click delete here and if we go back to our terminal we see that john doe gmail.com is deleted and this all is happening locally on our system but once we deploy the functions to our firebase project then these functions would also be triggered on your production environment so now let's see that how do we trigger events on firestore collections so for that what we need to have we need to export more functions here that is on firebase collection events so here what we can do we can again export function here that is exports dot document or let's simply say fruit added simply like this because we want to name our collection fruits so this should be again equal to functions dot firestore dot document and here we need to provide in the path of the document so here i'm going to call my collection name fruit so i'm calling it like this and then we have the document id simply like this and then inside this document we have these kind of options or these four functions that is on create on delete on update on right so let's handle each of the functions so here what i'll say on create and then what we have here here we have the snapshot and the context so we'll have the snapshot here and the context like this and then we can do anything we want to do whenever a document is created inside this fruits collection so here what we can do we can simply log in the snapshot data so we can simply say console.log snapshot dot data simply like this and then we can simply return something here and here we can simply again return promise dot resolve simply like this so let's save this and if we go to our firebase emulator and if we try to create this collection called fruits and if we try to add a document inside this fruits collection then this function should be triggered so let's go here and we see that this function that is fruit added has been initialized as a firestore function so let's go here inside our emulator and let's go to firestore and let's start a collection here so the collection name should be fruits because only then that function should be triggered so let's click on next let me provide in a field name here and the value would be mango so let's save this so we see that we have this document called with this document id and these are the fields so if we go to our terminal here we see that we we are getting this thing here that is named mango and this is coming from snapshot.data so let's quickly try to handle the other two types of functions that is the on update function and on delete functions so let me simply copy this function from here and let me paste it here and this should be fruit deleted simply like this and then instead of the oncreate thing we have the on delete event like this and then again what we can do we can simply log this thing here that is this is this item is deleted and again we can copy this function from here and let me paste it here and instead of the deleted event we want to have the updated event that is if the document is updated and instead of the on delete we have the on update event that is on update function here so let's save these things here and this should be instead of deleted it should be updated simply like this or what more we can do inside this updated function we can simply log in the before and after values so we can say console.log and here we can see that before like this and here we can simply get the before value using snapshot dot before dot data like this and let's copy this thing and let's paste it here and this should be after that is after updation and this should be after simply like this so let's save this and let's go back here to our terminal so we see that two functions have been added here that is fruit deleted and fruit updated so firstly let's try the updated event so let's go back to our emulator let's try to change this name from mango to banana so let's click here let's change this mango to banana let's save this so this has been updated and if we go to our console we see that the before snapshot was this thing here that is named mango and after snapshot was this thing here that is named banana so now let's try to delete this document so let's simply click here and let's simply delete document so let's click on delete so the document is deleted and if we go to our terminal we see that this name banana has been deleted so this is how you handle events from firestore so now let's see the last type of functions and that are scheduled functions so for that what you need to do we need to export one more type of function and here i am simply calling it scheduled function so scheduled function and this name can be any name so here to make a to create a schedule function what you need to do you need to simply use functions dot pops up dot schedule and here you can pass in two types of things firstly you can pass in the app engine ml strings or you can pass in the chrome expression so to run a function every minute let me simply pass in 5 stars that is to run a function every minute and then we have the on run event here and here inside this thing here we have the context simply like this and here what we can simply log we can simply log here that is i ran at i am running it every minute so we can simply log it here that is console.log that is i am running or executing every minute simply like this and then you simply need to return something here and we can return null from here so let's save this so if you don't know that how to write cron expressions then you can go to the site here that is crontab.guru and here to you can find simple examples of writing cron expressions so 5 stars means that is to run at every minute if you click on examples here we see that we have many more cron expressions that is if we want to run a cron job every 5 minutes we can simply click here and we can see that what should the expression be like so you can simply copy it and you can simply paste it inside your scheduled function here that is inside this string so now let's save this and if we go to our console here or inside our terminal we see that this pops up function is initialized but this is not firing every minute and that is a glitch inside this firebase emulator that is we cannot fire puffs up scheduled functions inside our emulator so for that we need to deploy a project to firebase console so let's see that how do we deploy our functions to firebase console that is our firebase project that is the project that we have created here because if we go to the functions tab here and if we reload the page then we should not be seeing any functions inside this functions tab here because the functions have not been deployed they were only running locally on our system so let's see that how do we deploy them so let's go back and let's open a terminal here and let me clear out here and here what we need to do we need to go to the root folder so let's clear out and what we need to do we need to simply say firebase deploy simply like this but in case you only want to deploy functions then you can simply say only functions because we know that when we initialize this project we could have initialized other things also apart from functions like rules for firestore rules for authentication rules for storage but if you only want to deploy functions then you can simply pass in this thing here that is firebase deploy only functions and moreover if you only want to deploy a single functions that is if you only want to deploy this hello world function and not the others then you can simply use colon and you can simply pass in the name of the function that is simply like this so then only this function would be deployed and not others would be deployed but here i want to deploy all the functions so let's simply remove this colon and hello world from here and now let me simply press enter and most likely it should give me an error here so let's wait for a couple of seconds and let's see the error what the error is and we see this thing here that is we are getting an error and the error is very simple to fix that is our project should be on the blaze plan that is pay-as-you-go plan to deploy our functions so if we go to our project here we see at the down here that we are on the spark plan that is the free plan so we need to upgrade this project to use the place plan so let's simply click on upgrade here and here we need to select this plan that is place pay as you go so let's simply select this plan and we need to purchase it so now we see that we have successfully upgraded our project so let's simply click cross here and now we are on the blaze plan and most likely that if you haven't set up billing on your firebase console or inside your google platform then you must be getting some pop-ups to enter your credit card information and so on and so forth and then you can upgrade to the place plan so let's go back back and now we are on the blaze plan so we won't be getting this error so let's simply clear out the console here and now let's simply use this command again that is firebase deploy only functions and now it should take a couple of minutes to deploy each and every function of yours to firebase project so while it is deploying why not let's go to our project here and let's enable some things here that is we need to check for authentication so let's enable authentication here because we haven't enabled authentication inside this project so let's simply click on get started and we need to enable the email and password authentication so let's click here let's simply enable the email password authentication and this trigger that is the firebase function on authentication triggers would be triggered on any of the sign in providers but here i am simply using the email and password provider so let's now go to the cloud store that is cloud firestore and let's enable this database also that is cloud firestore and now let's simply click create database and we need to start it in test mode so that there should be so that the rules are not there that is it should be open to everyone so let's simply click on next and here let me simply enable it and it would take a couple of minutes so why not let's go back and let's see the deployment in progress of the functions so it is still deploying so let's again go back and let's set up the firebase project or let's create a document inside our firestore collection while the functions are deploying so we see that we have this cloud fire store so let's simply start a collection here called fruits and now let's click on next and here let's simply use an auto id and the name would be this thing here that is a field name and the value would be mango because i love mangoes so let's simply save this and we have this document inside our firestore collection here and now let's go to the authentication tab and let's add in a user here so let the email will be john doe at gmail.com password would be one two three four five six so let's simply add in the user here and now we have this user here and now if we go back we see that this function deployment is still in progress so let's wait and let's go to this functions here and let's see that what all functions have been deployed till now so we see that these functions have been deployed that is the api the hello world function have been deployed and this is the url so let me zoom in a little bit so we see that this is the url for this function so let's simply double click it and let's simply copy it or let's simply go to this url that is hello world so we see that your client does not have permission from the server so why is it so so let's wait for a couple of more minutes let's try this function that is this url so let's go to this url that is api and we see that this api call is working that is we are making a get get request to this url to our api and we are getting back this response that in turn comes from the json api placeholder so let's copy this url and let's go back and let's try to use this url inside our risk client and let's try to make a post request to this url so let me paste this thing here and this is a live url and not a local host url but this is a live url so let's make a post request with these fields as the body so let's make a request so we see that we are getting back this response back that is the request dot body thing here so if we make a delete request here by using the same url we should be getting that it was a delete request and now let me simply make a put request here by using the same url and we see that it was a default request so this url is working that is the api url so now let's try the hello world but before that let's go back and let's see that what is the problem here so we see that we have successfully deployed this hello world fruit updated user deleted fruit deleted scheduled functions fruit added so we have some functions error here that is firebase deploy had errors with the following function that is scheduled function so we'll try to redeploy that scheduled function so let's see that that what's the problem there so we'll fix that in a moment but let's see that how other functions are working so now let's try to go to the hello world uh url so let's go to this url and we see that we are getting back this response that is hello from firebase function so this is also working so now let's go to the logs here and let me open this authentication thing in another tab and let me also open this cloud firestore in another tab so we have the firebase logs here and let me minimize it so let's go to this thing here that is this authentication thing here and let's try to add in one more user here the user's email would be truly methyl at gmail.com password would be one two three four five six so let's simply add in a user and now at the very same time what i'm going to do i'm simply going to delete this john doe user so that we can see both the log statements at the same time that is we have two events that is the on user created event and on delete event so let's delete this account that is john doe gmail.com so let's simply delete it so the account has been deleted so let's go to the logcat of our firebase functions so here we see that the function is not triggered yet and it takes a moment or so to trigger a function so we see that we get this message here that is truly methyl.gmail.com is created and the function execution started and the function execution took so many milliseconds so let's see this thing also that is after a few seconds or a couple of seconds we have this log message also that is john doe gmail.com is deleted so we see that both the functions have been called as soon as we added and deleted a user from our authentication system so let's go to this cloud file store and let's try to add in a document so let's try to add in a document the name would be name field name would be name the value would be banana so let's save this let's go to the mango field here or the mango document here let's try to update the field name or the value from mango to grapes let's update it and here for this banana field or this banana document let me try to delete this document that is this document which has a field and value with name and banana so let's simply delete this document so that we can see all the three functions in progress so let's go back to our logcat here and it would take a couple of seconds so we see that we have added a fruit the name was banana then we updated a fruit that is before was mango and afterwards grapes so we have this event so the delete event is yet to fire that is the document deleted event so now we have the deleted event also that is name banana has been deleted so now we see that all our functions are working but but only the publisher function is not working that is a scheduled function so let's go back and let's try to redeploy the function so we see that we have we can use this statement that is firebase deploy only functions scheduled function so now to redeploy this function that is scheduled function what we can do we can simply use it use this thing here that is firebase deploy only functions and here we can simply pass in the name of the function that is scheduled function simply like this to only deploy this function that is the scheduled function so let's simply press enter and let's wait for a couple of seconds and let's see that we are able to deploy this function this time most likely this time the function should be deployed so let's cross our fingers and let's wait so let's go back here and let's have a look at the functions tab here once again and let's see that what is happening here and and we see that we have a scheduled function here and this should be a successful operation and let's have a look at the logs here because we are only seeing the we are only going to see the log messages from the function that is schedule function so yes we see that our scheduled function is deployed and we see that we have a message here or a log message here that is i am running or executing every minute and that was the log statement inside our scheduled function and it executed at 942.02 and it should execute at 943.03 so let's wait for a minute and we see that we should be getting that message also so it should be in a moment or so that we should be getting this message again so let's go back once again to a terminal so we see that we have this thing here that is deploy complete so we have successfully deployed our scheduled function though we already verified that inside our firebase console but here also we see that we have this deploy complete so let's go back and it should take a moment or so for the scheduled function to trigger again so we see that we get this trigger again that is scheduled function i am running or executing every minute at nine forty three over the first one was 942 o2 and it is 943 o1 so this is how we deploy our functions to our firebase project and this function that is the scheduled function would keep on running every minute until and unless you stop it so how do you stop a function so it is very simple you can simply click on the three ellipses here and here you can simply click on delete function or what you can do you can go back to your project and here to delete each and every function which you don't want inside your firebase project you can simply comment those functions out from there so here i'll simply comment out each and every function so let me minimize this thing from here and i'll only keep this function available that is hello world so that only hello world should be deployed and all the other functions should be deleted and here what we need to do we simply need to use the same command that is firebase so let me clear up the console first so firebase deploy only functions and let's press enter and it would ask you that whether you want to delete all the other functions so it would take a moment or so so we see that we are getting this message here that is these functions should be deleted so whether we want to proceed with deletion of the for functions so let's press y and enter so now we it is deleting these functions that is apart from this hello world function so we see that we are getting this message here that is successful delete operation for each of the functions apart from this hello world function and let's uh wait for a couple of second or let's go back to our console here and let's try to reload this page that is functions and most likely likely the functions have been deleted here so we see that only hello world remains here and it is up and working so we can verify it also that is this is up and working and now let's go back and let's uh check the terminal here so this deployment should be complete in a moment or so but you got the point that how do you remove functions so let's try removing this function as well from the firebase console so let's simply click on this ellipses here that is the vertical ellipses and simply click on delete function so let's click on here and let's simply delete the function here and now we see that our functions tab is empty because we do not have any functions inside the functions thing here so this is how easy it was to create your own firebase functions that can be triggered on http request on firebase events like the authentication event like the document added event or the deleted event inside your firestore database or you can write scheduled functions so this is how easy it was so if you have liked the video do hit the like button if you haven't subscribed to the channel turn on do subscribe to the channel if you have liked the video and if you want to support me you can support me on patreon or paypal so thank you bye tata take care and have a good day and have a nice day
Info
Channel: yoursTRULY
Views: 16,959
Rating: undefined out of 5
Keywords: Yourstruly, cloud functions, how to create cloud functions, firebase cloud functions tutorial, tutorial on firebase cloud functions, deploying firebase cloud functions, how to use firebase emulator locally, firebase cloud functions, how to write cloud functions
Id: gA6WGYQWrKc
Channel Id: undefined
Length: 43min 52sec (2632 seconds)
Published: Mon Mar 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.