In this lesson, we're going to talk about
server setup and why we need to use Firebase functions for our backend API.
When we're building an application,
we need to have some way to handle data and logic on the server side.
One way to do that that we have been
following is to set up a server on our local machine, also known as localhost.
However, it's important to know
that localhost servers cannot be accessed by our users.
In other words, our user won't be able
to make requests to our server if it's running on localhost.
That's why we need to create our API endpoint somewhere on the cloud.
This is where Firebase functions come in.
Firebase Functions is a serverless platform that allows us to write
and deploy backend code without managing servers.
With Firebase functions,
we can create API endpoints that our user can access from anywhere.
So why would we use Firebase functions?
Well, there are a few reasons.
First, Firebase Functions allows us
to write and deploy backend code quickly and easily.
We don't need to worry about managing
servers or scaling our infrastructure as our user base grows.
Firebase takes care of all of that for us.
Second, Firebase functions integrate seamlessly with other Firebase services.
For example, we have already used Firebase
authentication to handle user authentication.
And if you wanted to manage a database,
you could use cloud Firestore to store all your data.
All of these services work together
seamlessly, making it easy to build and deploy our applications.
Now that we know what Firebase functions is and why it's useful, let's set it up.
The first thing that we need to do to set
up Firebase functions is install Firebase tools.
For that, we're going to have to install it globally.
So let's type in our terminal npm install,
give it the global flag, and say Firebase Tools.
Now let's let this run.
And now that it's complete,
what we can do is run Firebase login so that we log into our account.
If you have been following this course
for a while, then you already have a Firebase account.
Otherwise, you might have to create it.
So I'm just going to press Firebase login
and I'm going to say that we can allow the error reporting information.
And now on my browser,
it tells me to choose an account for Firebase CLI.
And I'm going to choose this one because that's where I have my project set up.
And I will allow this. Great.
So my login has been successful.
And now if I close this here,
I'm going to see a message that I logged in successfully.
Now that we are logged in into the Firebase,
what we need to do is set up this project to connect to Firebase.
And for that, we're going to have to type inside the root of our project.
Okay?
So wherever you have your files, just style Firebase init.
And once we're done with that, we're going to have a bunch of feature
choices from Firebase and what we really need is Firebase functions.
And to select this,
you're going to have to press space first and you're going to see this green dot
appear here and then just say that that's all the choices that we want.
So we're just going to press Inter and we're going to create a new project.
And I'm going to call this project lesson three API Connection.
And the name for my project would be lesson Three API Connection Name.
Okay, great. So now our Firebase Cloud project should
be set up for us and we're going to have to wait for this to finish.
Great.
So now our Firebase project is available already and here's the link for it.
And now we're being asked more questions.
What language would you like to use to write cloud functions?
And we're using JavaScript, so that's what I'm going to select.
And it's asking about Eslint to catch probable bugs and enforce style.
We don't really need this, so I'm just going to say no.
And yeah, we do want to install
the dependencies with NPM now, so I'm going to reply with Y and then
press Enter and it started installing for me.
Great. Now that that's done,
you're going to see new functions folder appear in your projects.
That's going to have all the Firebase set up that we need.
We can just go to our link and see our Firebase project setup.
And if I open my Firebase here,
you're going to see that lesson three API Connection name has been created for me.
And if we want to see our functions, this is where it's going to be located.
But we haven't created any functions yet.
We just created the project right now.
And in the next lesson, we're going set up the functions.
We'll transfer our current setup onto Firebase functions.
So stay tuned for that.
Thanks so much for watching and I'll see you in the next one.