WEBVTT

00:03.790 --> 00:05.020
Hey, did everyone they.

00:05.020 --> 00:05.350
Sure.

00:05.350 --> 00:09.250
And in this video, we are going to bring in our Dot E and V configuration files.

00:09.250 --> 00:13.270
So the secrets as well as we are going to learn how to write the basic model.

00:13.270 --> 00:18.580
Now, this model is not going to be too complex, rather very basic, but there will be a room for more

00:18.580 --> 00:21.340
further upgradation so let's go ahead and get started with that.

00:21.460 --> 00:25.450
Now, first and foremost, I'm going to go ahead and create a new file and again, make sure you are

00:25.450 --> 00:27.640
into the root of your folder, nowhere else.

00:27.640 --> 00:30.970
It should be same level as the package that Jason is.

00:31.120 --> 00:33.580
So go ahead and write a dot, e and V.

00:33.610 --> 00:38.890
Now, this brings a very important thing that most of the time you'll be able to see this file in the

00:38.890 --> 00:41.230
VTS code and you'll be able to open it up.

00:41.230 --> 00:43.690
In some cases this is a hidden folder.

00:43.690 --> 00:48.010
So especially on the windows, you might have to turn off the settings for showing the hidden files

00:48.010 --> 00:48.520
and all of that.

00:48.520 --> 00:50.170
So be cautious with that.

00:50.170 --> 00:54.130
Usually anything that starts with the dot is not visible by default.

00:54.130 --> 01:00.100
You can run the command of ls space dash l a on the Linux and the Mac systems windows.

01:00.100 --> 01:01.360
There is definitely a command.

01:01.360 --> 01:04.110
I don't remember it right now, but you might want to change the settings.

01:04.120 --> 01:05.710
It just right click on properties.

01:06.070 --> 01:06.380
Okay.

01:06.400 --> 01:08.140
Once we have we are into this one.

01:08.140 --> 01:12.430
We are going to first go ahead and say this is my API port or you can just go ahead and directly write

01:12.430 --> 01:13.570
port, whatever you name.

01:13.570 --> 01:15.460
It doesn't really matter too much.

01:15.460 --> 01:19.090
We're going to go ahead and say that the port we are using is processed E and V.

01:19.180 --> 01:25.420
We obviously will have a later on Mongo URL, so we're going to call this one as mongo URL.

01:25.810 --> 01:30.490
Again, no debate about calling it as you or I or you URL, whatever it is that you like, you can go

01:30.490 --> 01:35.320
ahead and call this one and we can also have a couple of more, but we're going to come back later on.

01:35.320 --> 01:39.010
Right now, in fact, we don't need mongo URL because we haven't set it up.

01:39.010 --> 01:42.110
So let's go ahead and call this one as simply Port OC.

01:42.160 --> 01:47.170
This is all great that you have this port being defined, so this now needs to bring it into here.

01:47.320 --> 01:49.840
But you might be saying, hey, we are not using it here.

01:49.840 --> 01:57.160
So why we are bringing in now whenever these dot config are there, they have not just these ports but

01:57.160 --> 01:58.540
they have other applications.

01:58.540 --> 02:02.740
So it makes so much of sense to bring them at least one time into your main app.

02:03.340 --> 02:07.660
You can bring it into index also, but at least in the app they actually make sense.

02:07.870 --> 02:13.360
So we don't need to hold this into any available because we are not bringing it any as as of the time.

02:13.360 --> 02:18.970
So you can go ahead and simply go ahead and say, hey, I want you to require and the syntax.

02:18.970 --> 02:23.320
Remember we told you we discussed a little bit about the syntax into the presentation.

02:23.320 --> 02:28.000
So this is Dotti and V and then we have to simply use the config method of that.

02:28.660 --> 02:34.480
If your file is not in the root directory of DMV, then here comes another property which is the path

02:34.480 --> 02:36.640
and the name of that E and V file.

02:36.640 --> 02:37.930
So this is how it goes on.

02:37.930 --> 02:42.850
Now, usually such required statement are at the top, not compulsory, and it's not going to bother

02:42.850 --> 02:44.560
in this case the flow of application.

02:44.560 --> 02:45.970
But this is how we do it.

02:46.180 --> 02:46.360
Okay.

02:46.510 --> 02:48.250
Is it going to change anything as of now?

02:48.250 --> 02:48.820
No, nothing.

02:48.820 --> 02:54.280
Because we are not using anything from here but in the index or JS, this needs to come up as a little

02:54.280 --> 02:54.850
bit different.

02:54.850 --> 02:56.740
This port now needs to go up here.

02:56.860 --> 03:00.940
Okay, so are we going to create a variable and then pass it on like that?

03:00.940 --> 03:05.560
Like something like we previously did something like port and then processed or D and V.

03:05.560 --> 03:11.560
No, we don't need to do it actually, because most of the application don't even allow you to set the

03:11.560 --> 03:12.400
port variable.

03:12.400 --> 03:17.410
So whenever you just go ahead and look for it, there will be no port variable in your E and V file

03:17.410 --> 03:20.290
in the production, so you don't need to create even a variable up here.

03:20.320 --> 03:21.670
Now, that's totally up to you.

03:21.670 --> 03:26.830
So what we're going to do is we're going to go ahead and say, Hey, I want to bring in a port variable

03:26.950 --> 03:29.590
and this port variable is going to come up from.

03:31.750 --> 03:34.930
Process Dot E and V.

03:35.110 --> 03:38.830
Now this is exactly the same as writing process.

03:38.830 --> 03:40.870
Dot E and V dot port.

03:40.900 --> 03:41.860
Exactly same.

03:41.860 --> 03:42.960
No difference at all.

03:42.970 --> 03:47.530
I'm just restructuring it and storing that into a more easy access variable.

03:48.490 --> 03:48.970
Y.

03:48.970 --> 03:53.320
I don't need to say the require of this app and everything because as soon as your app loads up and

03:53.320 --> 03:55.050
your index loads up, this is all good.

03:55.060 --> 03:59.260
You get the idea what I'm trying to say, not trying to oversimplify the things.

03:59.260 --> 04:00.220
Then there we go.

04:00.220 --> 04:02.110
We just define the port and there we go.

04:02.110 --> 04:07.420
Now it says, Hey, running at Port 4000, but I can go into the E and V and can say, Hey, now you'll

04:07.420 --> 04:09.010
be running at Port 4001.

04:09.010 --> 04:10.330
Save this again.

04:10.330 --> 04:12.280
Node one is not checking my dot DMV.

04:12.280 --> 04:14.200
This shouldn't be checking it also.

04:14.290 --> 04:21.370
But if I go ahead and restart my server with that node now it's saying it's still saying port 4000 because

04:21.370 --> 04:22.720
we haven't changed that.

04:23.020 --> 04:23.590
My bad.

04:24.010 --> 04:27.640
In the index we are not using we are using hardcoded values.

04:27.640 --> 04:29.050
So let's use a dollar.

04:29.080 --> 04:31.510
There we go and define the same port.

04:31.510 --> 04:35.140
Save that it automatically checks E and V as well.

04:35.170 --> 04:38.170
So we're going to go ahead and do that now.

04:38.170 --> 04:39.400
Let's change this one.

04:39.820 --> 04:42.220
It's nice that Node one is actually checking.

04:42.220 --> 04:43.450
No, it's not checking.

04:43.450 --> 04:43.950
Okay.

04:45.160 --> 04:46.690
And there we go, 4000 back.

04:46.720 --> 04:46.960
Okay.

04:46.990 --> 04:50.170
So this part is all done and looks okay.

04:50.170 --> 04:51.880
Now we can go ahead and close all of this.

04:51.880 --> 04:52.990
Now our app is working.

04:52.990 --> 04:56.650
Our Dotti and V projects are also being injected nicely.

04:56.860 --> 05:00.850
Moving on now, let's come back on to the part where we design our model.

05:00.850 --> 05:04.240
So how we design our model is is really easy.

05:04.240 --> 05:07.330
It's not that much of a difficult, especially in this case.

05:07.720 --> 05:12.160
So how we go with that, remember for designing the models we have Mongoose.

05:12.160 --> 05:18.040
So it's always a good idea to recommend or refer the documentation of Mongoose so we can see there are

05:18.040 --> 05:21.850
schemas and there is a schema type, so we need to consult with both of them.

05:21.850 --> 05:23.470
A schema type will define that.

05:23.470 --> 05:25.210
What type of schemas can we create?

05:25.210 --> 05:28.030
We can create some documents and a whole bunch of other things.

05:28.030 --> 05:29.710
Right now let's go with the schema.

05:29.950 --> 05:34.300
So starting this little bit, it gives you that you can go ahead and import mongoose.

05:34.300 --> 05:40.540
And just like we have created app from Express, we can go ahead and bring out the schema from the Mongoose

05:40.540 --> 05:45.520
and then we can define the block schema which can have all the properties that we want to define, and

05:45.520 --> 05:46.600
that's pretty much it.

05:46.600 --> 05:51.100
Now later on, if you're going to scroll a little bit, then you have to pass it on like this as well.

05:51.100 --> 05:56.590
So you need to call this one as create an object from the model and pass on what you want to call the

05:56.590 --> 06:00.400
model as well as what schema you are using that you have just defined above.

06:00.400 --> 06:02.140
So everything is coming from the docs.

06:02.350 --> 06:04.810
Okay, let's go ahead and work on with that.

06:04.810 --> 06:10.270
So we're going to go ahead and call this one as Mongoose is going to be saying, hey, I want you to

06:10.270 --> 06:17.050
require Mongoose now you de structure the schema or you're not and that's totally up to you.

06:17.050 --> 06:18.070
I usually don't.

06:18.070 --> 06:24.970
So I'm going to call this one as user schema and we're going to go ahead and say, Hey, new mongoose

06:25.000 --> 06:26.080
dot schema.

06:26.500 --> 06:30.460
Again, this is exactly the same as you saw in the documentation here.

06:30.460 --> 06:34.900
In the documentation, they are de structuring it and calling it as directly schema and passing on an

06:34.900 --> 06:35.890
object inside it.

06:35.890 --> 06:37.960
In my case I say mongoose dot schema.

06:37.960 --> 06:40.720
They are really basic JavaScript, nothing much more than that.

06:41.320 --> 06:42.760
And here what you're going to write.

06:42.760 --> 06:49.510
So first thing that we are going to need is going to be first name and this first name is going to be

06:49.510 --> 06:49.960
an object.

06:49.960 --> 06:55.450
Usually all of the properties inside the schema or object and you can pass on so many things inside

06:55.450 --> 06:56.050
this one.

06:56.200 --> 06:59.050
The first one that we're going to say this is compulsory.

06:59.050 --> 07:02.740
You have to write in what is the type of that data number string.

07:02.740 --> 07:04.900
You can read more about that in the docs.

07:05.440 --> 07:10.210
We are also going to say that if nobody passes on me the first name, I'm going to set the default as

07:10.210 --> 07:10.450
null.

07:10.450 --> 07:16.060
You can pass on default whatever you actually like and you can pass on fields like required to true.

07:16.090 --> 07:17.500
That means it is required.

07:17.500 --> 07:18.220
We're going to do that.

07:18.220 --> 07:19.480
So don't worry.

07:19.660 --> 07:21.880
Let's go ahead and copy this one.

07:21.880 --> 07:26.950
So again, I love to use the shortcuts, so let's go ahead and change this one to last name.

07:27.640 --> 07:29.200
This is going to be a type of string.

07:29.200 --> 07:31.750
The null is exactly same, so that is fine.

07:32.320 --> 07:33.460
What else do you want?

07:33.460 --> 07:34.960
Let's go ahead and copy this one.

07:34.960 --> 07:38.020
We're going to say that I am interested in grabbing the email.

07:38.050 --> 07:44.740
The type is string, but the default cannot be null in this case, but rather this should be required.

07:45.250 --> 07:47.020
Or we can handle the required a different way.

07:47.020 --> 07:49.570
But let's go ahead and say that this should be unique.

07:49.570 --> 07:54.400
This can also go with your username, also that your username should be unique, but in this case it

07:54.400 --> 07:56.560
makes sense to have the email as unique.

07:56.860 --> 08:02.800
And you can also go ahead and write something like this that you want to have required to true.

08:02.830 --> 08:08.020
Then if this is not there, it can go ahead and say, Hey, this is required even further.

08:08.020 --> 08:12.940
You can go ahead and down, write something required is true and you can pass on a message just like

08:12.940 --> 08:16.990
we saw that, hey, if this is required is true, somebody don't pass me up.

08:16.990 --> 08:19.000
I'll show him that error message.

08:19.120 --> 08:20.170
So we'll do that.

08:20.170 --> 08:20.740
Definitely.

08:20.740 --> 08:23.830
Don't you worry on that part, but we'll do that a little bit later.

08:23.980 --> 08:30.820
Now, moving on, we are going to go ahead and say I want to store password also.

08:31.210 --> 08:34.590
A storing the password in the clear text format is really a bad idea.

08:34.600 --> 08:37.690
We won't be doing it, but as of now, let's just go ahead and declare that.

08:38.020 --> 08:43.330
And finally, last but not the least is going to be the token which will help you to understand so many

08:43.330 --> 08:44.290
of the things.

08:44.380 --> 08:46.120
Let's go ahead and say type.

08:46.120 --> 08:48.540
And that's going to be a simple string.

08:48.550 --> 08:55.330
Now, there are more properties that can come up here like token expires and token generated on and

08:55.330 --> 08:57.280
a whole bunch of other things that can come up.

08:57.280 --> 09:02.530
I will definitely discuss some of the strategies with you that what strategies can come up with forgot

09:02.530 --> 09:08.110
password or saying that your user is now validated by clicking the link in the in the mail and all of

09:08.110 --> 09:08.560
that.

09:08.860 --> 09:11.440
We'll discuss the strategies of that, but not right now.

09:12.180 --> 09:12.360
Okay.

09:12.580 --> 09:16.570
So this is the schema design, but remember, this is just a design of schema.

09:16.570 --> 09:21.220
You haven't exported an object which is following this schema, so that is important.

09:21.550 --> 09:26.860
So we're going to go ahead and say, hey, module dot exports.

09:26.860 --> 09:31.840
And this is going to say that, hey, I want to use Mongoose for everything and I want to create a model

09:31.840 --> 09:32.920
from this schema.

09:33.100 --> 09:34.660
What do we call this model?

09:34.660 --> 09:37.870
We are going to call this model as simply a user.

09:37.870 --> 09:42.790
But the problem is, no matter if you write it down, uppercase or lowercase mongoose automatically

09:42.790 --> 09:44.440
brings everything into the lowercase.

09:44.440 --> 09:47.380
In fact, MongoDB also does the same via their driver.

09:47.380 --> 09:52.420
So you can just go ahead and write this user, but you are also going to notice when we bring it into

09:52.420 --> 09:56.110
any other file we actually denoted by uppercase U as user.

09:56.110 --> 09:59.200
So again, it's totally up to you behind the scene in the database.

09:59.200 --> 10:00.790
This is all in lowercase.

10:01.420 --> 10:01.600
Okay.

10:01.690 --> 10:04.090
And further what schema this user will be following.

10:04.090 --> 10:05.650
That's just what we have designed.

10:05.650 --> 10:09.790
User schema told you it's really easy and really, really simple.

10:09.820 --> 10:13.390
You want to add in more country, maybe your university, maybe your age.

10:13.390 --> 10:15.010
You can all go ahead and do that.

10:15.280 --> 10:18.460
In case you want to study a little bit more on that, you can go ahead and see.

10:18.460 --> 10:24.700
These are the permitted schema types, string numbers, date buffer for files, boolean, all of that.

10:24.700 --> 10:26.620
You can directly go ahead and inject that.

10:26.620 --> 10:29.440
But I think this is all good for at least this video.

10:29.440 --> 10:31.300
Let's go ahead and catch up in the next one.
