WEBVTT

00:00.170 --> 00:03.190
Okay, so we're ready to get started creating our app.

00:03.200 --> 00:06.790
We're going to be making heavy use of the net CLI in this course.

00:06.800 --> 00:13.760
It's going to help us quickly and efficiently scaffold our microservices and allow us to add to our

00:13.760 --> 00:17.060
application as we develop it over time very easily.

00:17.060 --> 00:20.390
And it's super simple to install if you don't already have it.

00:20.390 --> 00:27.620
Just make sure you run NPM install G for global the Nestjs CLI.

00:27.860 --> 00:33.140
So if you get a permissions error when installing the CLI, just make sure you run this command in pseudo

00:33.140 --> 00:34.820
mode and enter your password.

00:34.820 --> 00:40.520
So after we have the CLI installed we are going to use it to generate a new project and we're going

00:40.520 --> 00:47.060
to call this sleeper, this Airbnb clone, we're going to call it Sleeper with an R, feel free to call

00:47.060 --> 00:52.070
it whatever you'd like and we'll go ahead and scaffold the application for this app.

00:52.070 --> 00:59.360
I'm going to make use of NPM as my package manager because it is the quickest as it caches your node

00:59.360 --> 01:03.150
modules and makes it a lot easier to run installation.

01:03.150 --> 01:09.090
So after our project is fully initialized, we're going to CD into the sleeper directory and we can

01:09.090 --> 01:16.500
simply run NPM run, start to make sure that our application back end server will start up and we can

01:16.500 --> 01:19.560
see that our NEST application has successfully started.

01:19.560 --> 01:25.020
Okay, so I've gone ahead and opened up the project in VS code, which is the code editor I will be

01:25.020 --> 01:25.680
using.

01:25.680 --> 01:32.310
And of course by default we have the bare bones of a nestjs application out of the box with our Main.ts

01:32.310 --> 01:40.440
file, creating the nest application through the app module and then listening on HTTP port 3000 for

01:40.440 --> 01:43.530
incoming requests and out of the box.

01:43.530 --> 01:50.190
We have a single app dot controller, which is a get route that simply will call the app service and

01:50.190 --> 01:52.220
return a Hello world string.

01:52.230 --> 01:57.840
Okay, so I've also gone ahead and now opened up Postman, which we will use in this course to test

01:57.840 --> 02:02.850
out HTTP requests against our Nestjs application.

02:02.850 --> 02:06.150
You can use whichever HTTP client you'd like.

02:06.150 --> 02:12.480
We're going to run an HTTP localhost 3000 get request at our server and we should get that.

02:12.480 --> 02:18.000
Hello world response back because of that app dot controller so we can see that our app is fully up

02:18.000 --> 02:19.560
and running and ready to go.

02:19.560 --> 02:28.770
So back in our terminal I've exited out of the nest server and we are ready to get started on our application.

02:28.860 --> 02:34.980
The first part of our application is going to be building out a common library that all of our different

02:34.980 --> 02:43.550
microservices can use for common operations like database access, authentication, logging and more.

02:43.590 --> 02:49.950
The benefit of this approach is that we only need to write this common code one time and then we can

02:49.950 --> 02:56.070
import these modules that we're going to create into each different microservice and reuse that so that

02:56.070 --> 02:58.590
we don't have to rewrite it over and over again.

02:58.590 --> 03:01.500
For all of these common cross-cutting concerns.

03:01.500 --> 03:07.740
Now the nest CLI makes this really easy for us, so we're going to convert our existing standalone project

03:07.740 --> 03:17.670
into a mono repo where we'll have this common shared module alongside with each one of our microservice

03:17.670 --> 03:19.230
apps that we're going to create.

03:19.230 --> 03:21.180
It's very simple to get started.

03:21.180 --> 03:28.260
We are just going to run, nest, generate library, and then we can give the name of the library.

03:28.260 --> 03:34.080
So in this case, I'm going to call the library common because that's where all of our common code between

03:34.080 --> 03:36.750
these different applications is going to live.

03:36.750 --> 03:44.670
We can stick with the default app prefix and we can see that NEST has added this new Libs directory

03:44.670 --> 03:48.840
with our common lib and then updated some different files here.

03:48.840 --> 03:54.090
The nest CLI JSON, our package.json and the TS config.

03:54.090 --> 03:57.000
So let's go back into VS code and take a look.

03:57.000 --> 04:05.520
We can see this new libs directory here that has a ts config dot lib dot json that is extending our

04:05.520 --> 04:06.870
root ts config.

04:06.870 --> 04:14.490
So our root nestjs ts config is going to be shared amongst this common module library as well as all

04:14.490 --> 04:20.880
of our different applications and we can see the paths here that our application can use to access our

04:20.880 --> 04:21.960
common library.

04:21.990 --> 04:28.590
Next, if we go into the nest CLI JSON, we can see we have a project section now where we actually

04:28.590 --> 04:33.810
have our common library here specified with some metadata about it.

04:34.580 --> 04:42.260
And lastly, if we go into the new common library, we can see we have a common module out of the box

04:42.260 --> 04:50.210
with a common service and a root index.ts that is exporting these so that external applications can

04:50.210 --> 04:52.040
import them and use them.

04:52.040 --> 04:58.880
So in this lecture we have bootstrapped our application and converted it into a mono repo so that we

04:58.880 --> 05:00.530
can easily share code.

05:00.560 --> 05:08.330
We are now ready to start building out our common library so that we can reuse code amongst our microservices

05:08.330 --> 05:11.770
and make developing our backend very easy.

05:11.780 --> 05:14.270
Let's jump right in and I'll see you in the next one.
