WEBVTT

1
00:00:00.160 --> 00:00:01.860
In this lesson, we're going to talk about

2
00:00:01.890 --> 00:00:06.860
server setup and why we need to use
Firebase functions for our backend API.

3
00:00:06.890 --> 00:00:08.700
When we're building an application,

4
00:00:08.730 --> 00:00:13.300
we need to have some way to handle
data and logic on the server side.

5
00:00:13.330 --> 00:00:15.620
One way to do that that we have been

6
00:00:15.650 --> 00:00:21.460
following is to set up a server on our
local machine, also known as localhost.

7
00:00:21.490 --> 00:00:23.100
However, it's important to know

8
00:00:23.130 --> 00:00:27.740
that localhost servers cannot
be accessed by our users.

9
00:00:27.760 --> 00:00:30.260
In other words, our user won't be able

10
00:00:30.290 --> 00:00:34.900
to make requests to our server
if it's running on localhost.

11
00:00:34.930 --> 00:00:39.340
That's why we need to create our API
endpoint somewhere on the cloud.

12
00:00:39.370 --> 00:00:42.540
This is where Firebase functions come in.

13
00:00:42.570 --> 00:00:46.980
Firebase Functions is a serverless
platform that allows us to write

14
00:00:47.010 --> 00:00:50.860
and deploy backend code
without managing servers.

15
00:00:50.890 --> 00:00:52.420
With Firebase functions,

16
00:00:52.450 --> 00:00:57.980
we can create API endpoints that our
user can access from anywhere.

17
00:00:58.010 --> 00:01:01.460
So why would we use Firebase functions?

18
00:01:01.490 --> 00:01:03.940
Well, there are a few reasons.

19
00:01:03.970 --> 00:01:06.540
First, Firebase Functions allows us

20
00:01:06.570 --> 00:01:10.620
to write and deploy backend
code quickly and easily.

21
00:01:10.650 --> 00:01:12.820
We don't need to worry about managing

22
00:01:12.850 --> 00:01:17.770
servers or scaling our infrastructure
as our user base grows.

23
00:01:17.800 --> 00:01:21.820
Firebase takes care of all of that for us.

24
00:01:21.850 --> 00:01:27.620
Second, Firebase functions integrate
seamlessly with other Firebase services.

25
00:01:27.650 --> 00:01:30.340
For example, we have already used Firebase

26
00:01:30.370 --> 00:01:33.290
authentication to handle
user authentication.

27
00:01:33.320 --> 00:01:35.460
And if you wanted to manage a database,

28
00:01:35.490 --> 00:01:39.210
you could use cloud Firestore
to store all your data.

29
00:01:39.240 --> 00:01:41.180
All of these services work together

30
00:01:41.210 --> 00:01:46.060
seamlessly, making it easy to build
and deploy our applications.

31
00:01:46.090 --> 00:01:51.540
Now that we know what Firebase functions
is and why it's useful, let's set it up.

32
00:01:51.560 --> 00:01:53.360
The first thing that we need to do to set

33
00:01:53.390 --> 00:01:57.820
up Firebase functions is
install Firebase tools.

34
00:01:57.850 --> 00:02:00.540
For that, we're going to have
to install it globally.

35
00:02:00.570 --> 00:02:04.540
So let's type in our terminal npm install,

36
00:02:04.570 --> 00:02:08.450
give it the global flag,
and say Firebase Tools.

37
00:02:08.480 --> 00:02:11.820
Now let's let this run.

38
00:02:11.850 --> 00:02:13.580
And now that it's complete,

39
00:02:13.610 --> 00:02:22.100
what we can do is run Firebase login
so that we log into our account.

40
00:02:22.120 --> 00:02:24.020
If you have been following this course

41
00:02:24.040 --> 00:02:26.540
for a while, then you already
have a Firebase account.

42
00:02:26.570 --> 00:02:29.660
Otherwise, you might have to create it.

43
00:02:29.690 --> 00:02:33.940
So I'm just going to press Firebase login

44
00:02:33.970 --> 00:02:41.060
and I'm going to say that we can allow
the error reporting information.

45
00:02:41.090 --> 00:02:45.300
And now on my browser,

46
00:02:45.330 --> 00:02:48.460
it tells me to choose
an account for Firebase CLI.

47
00:02:48.490 --> 00:02:53.220
And I'm going to choose this one because
that's where I have my project set up.

48
00:02:53.250 --> 00:02:55.420
And I will allow this.
Great.

49
00:02:55.450 --> 00:02:57.860
So my login has been successful.

50
00:02:57.890 --> 00:02:59.900
And now if I close this here,

51
00:02:59.930 --> 00:03:04.100
I'm going to see a message
that I logged in successfully.

52
00:03:04.130 --> 00:03:07.060
Now that we are logged
in into the Firebase,

53
00:03:07.090 --> 00:03:11.020
what we need to do is set up this
project to connect to Firebase.

54
00:03:11.050 --> 00:03:15.980
And for that, we're going to have
to type inside the root of our project.

55
00:03:16.000 --> 00:03:16.540
Okay?

56
00:03:16.570 --> 00:03:21.260
So wherever you have your files,
just style Firebase init.

57
00:03:21.280 --> 00:03:24.660
And once we're done with that,
we're going to have a bunch of feature

58
00:03:24.690 --> 00:03:29.020
choices from Firebase and what we
really need is Firebase functions.

59
00:03:29.050 --> 00:03:30.060
And to select this,

60
00:03:30.080 --> 00:03:33.860
you're going to have to press space first
and you're going to see this green dot

61
00:03:33.890 --> 00:03:38.610
appear here and then just say that that's
all the choices that we want.

62
00:03:38.640 --> 00:03:42.980
So we're just going to press Inter
and we're going to create a new project.

63
00:03:43.010 --> 00:03:51.800
And I'm going to call this project
lesson three API Connection.

64
00:03:52.720 --> 00:04:00.680
And the name for my project would be
lesson Three API Connection Name.

65
00:04:01.240 --> 00:04:04.920
Okay, great.
So now our Firebase Cloud project should

66
00:04:04.950 --> 00:04:10.260
be set up for us and we're going
to have to wait for this to finish.

67
00:04:10.280 --> 00:04:10.740
Great.

68
00:04:10.770 --> 00:04:18.020
So now our Firebase project is available
already and here's the link for it.

69
00:04:18.040 --> 00:04:21.580
And now we're being asked
more questions.

70
00:04:21.600 --> 00:04:24.860
What language would you like
to use to write cloud functions?

71
00:04:24.890 --> 00:04:28.140
And we're using JavaScript,
so that's what I'm going to select.

72
00:04:28.160 --> 00:04:33.420
And it's asking about Eslint to catch
probable bugs and enforce style.

73
00:04:33.450 --> 00:04:37.040
We don't really need this,
so I'm just going to say no.

74
00:04:37.360 --> 00:04:40.540
And
yeah, we do want to install

75
00:04:40.570 --> 00:04:44.620
the dependencies with NPM now,
so I'm going to reply with Y and then

76
00:04:44.650 --> 00:04:48.980
press Enter
and it started installing for me.

77
00:04:49.000 --> 00:04:50.700
Great.
Now that that's done,

78
00:04:50.720 --> 00:04:54.180
you're going to see new functions
folder appear in your projects.

79
00:04:54.210 --> 00:04:59.080
That's going to have all
the Firebase set up that we need.

80
00:04:59.480 --> 00:05:06.940
We can just go to our link
and see our Firebase project setup.

81
00:05:06.970 --> 00:05:10.500
And if I open my Firebase here,

82
00:05:10.530 --> 00:05:14.860
you're going to see that lesson three API
Connection name has been created for me.

83
00:05:14.880 --> 00:05:18.500
And if we want to see our functions,
this is where it's going to be located.

84
00:05:18.530 --> 00:05:21.220
But we haven't created any functions yet.

85
00:05:21.250 --> 00:05:23.300
We just created the project right now.

86
00:05:23.330 --> 00:05:26.180
And in the next lesson,
we're going set up the functions.

87
00:05:26.200 --> 00:05:28.920
We'll transfer our current
setup onto Firebase functions.

88
00:05:28.950 --> 00:05:30.340
So stay tuned for that.

89
00:05:30.360 --> 00:05:33.000
Thanks so much for watching
and I'll see you in the next one.

