Hey, did everyone they.
Sure.
And in this video, we are going to bring in our Dot E and V configuration files.
So the secrets as well as we are going to learn how to write the basic model.
Now, this model is not going to be too complex, rather very basic, but there will be a room for more
further upgradation so let's go ahead and get started with that.
Now, first and foremost, I'm going to go ahead and create a new file and again, make sure you are
into the root of your folder, nowhere else.
It should be same level as the package that Jason is.
So go ahead and write a dot, e and V.
Now, this brings a very important thing that most of the time you'll be able to see this file in the
VTS code and you'll be able to open it up.
In some cases this is a hidden folder.
So especially on the windows, you might have to turn off the settings for showing the hidden files
and all of that.
So be cautious with that.
Usually anything that starts with the dot is not visible by default.
You can run the command of ls space dash l a on the Linux and the Mac systems windows.
There is definitely a command.
I don't remember it right now, but you might want to change the settings.
It just right click on properties.
Okay.
Once we have we are into this one.
We are going to first go ahead and say this is my API port or you can just go ahead and directly write
port, whatever you name.
It doesn't really matter too much.
We're going to go ahead and say that the port we are using is processed E and V.
We obviously will have a later on Mongo URL, so we're going to call this one as mongo URL.
Again, no debate about calling it as you or I or you URL, whatever it is that you like, you can go
ahead and call this one and we can also have a couple of more, but we're going to come back later on.
Right now, in fact, we don't need mongo URL because we haven't set it up.
So let's go ahead and call this one as simply Port OC.
This is all great that you have this port being defined, so this now needs to bring it into here.
But you might be saying, hey, we are not using it here.
So why we are bringing in now whenever these dot config are there, they have not just these ports but
they have other applications.
So it makes so much of sense to bring them at least one time into your main app.
You can bring it into index also, but at least in the app they actually make sense.
So we don't need to hold this into any available because we are not bringing it any as as of the time.
So you can go ahead and simply go ahead and say, hey, I want you to require and the syntax.
Remember we told you we discussed a little bit about the syntax into the presentation.
So this is Dotti and V and then we have to simply use the config method of that.
If your file is not in the root directory of DMV, then here comes another property which is the path
and the name of that E and V file.
So this is how it goes on.
Now, usually such required statement are at the top, not compulsory, and it's not going to bother
in this case the flow of application.
But this is how we do it.
Okay.
Is it going to change anything as of now?
No, nothing.
Because we are not using anything from here but in the index or JS, this needs to come up as a little
bit different.
This port now needs to go up here.
Okay, so are we going to create a variable and then pass it on like that?
Like something like we previously did something like port and then processed or D and V.
No, we don't need to do it actually, because most of the application don't even allow you to set the
port variable.
So whenever you just go ahead and look for it, there will be no port variable in your E and V file
in the production, so you don't need to create even a variable up here.
Now, that's totally up to you.
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
and this port variable is going to come up from.
Process Dot E and V.
Now this is exactly the same as writing process.
Dot E and V dot port.
Exactly same.
No difference at all.
I'm just restructuring it and storing that into a more easy access variable.
Y.
I don't need to say the require of this app and everything because as soon as your app loads up and
your index loads up, this is all good.
You get the idea what I'm trying to say, not trying to oversimplify the things.
Then there we go.
We just define the port and there we go.
Now it says, Hey, running at Port 4000, but I can go into the E and V and can say, Hey, now you'll
be running at Port 4001.
Save this again.
Node one is not checking my dot DMV.
This shouldn't be checking it also.
But if I go ahead and restart my server with that node now it's saying it's still saying port 4000 because
we haven't changed that.
My bad.
In the index we are not using we are using hardcoded values.
So let's use a dollar.
There we go and define the same port.
Save that it automatically checks E and V as well.
So we're going to go ahead and do that now.
Let's change this one.
It's nice that Node one is actually checking.
No, it's not checking.
Okay.
And there we go, 4000 back.
Okay.
So this part is all done and looks okay.
Now we can go ahead and close all of this.
Now our app is working.
Our Dotti and V projects are also being injected nicely.
Moving on now, let's come back on to the part where we design our model.
So how we design our model is is really easy.
It's not that much of a difficult, especially in this case.
So how we go with that, remember for designing the models we have Mongoose.
So it's always a good idea to recommend or refer the documentation of Mongoose so we can see there are
schemas and there is a schema type, so we need to consult with both of them.
A schema type will define that.
What type of schemas can we create?
We can create some documents and a whole bunch of other things.
Right now let's go with the schema.
So starting this little bit, it gives you that you can go ahead and import mongoose.
And just like we have created app from Express, we can go ahead and bring out the schema from the Mongoose
and then we can define the block schema which can have all the properties that we want to define, and
that's pretty much it.
Now later on, if you're going to scroll a little bit, then you have to pass it on like this as well.
So you need to call this one as create an object from the model and pass on what you want to call the
model as well as what schema you are using that you have just defined above.
So everything is coming from the docs.
Okay, let's go ahead and work on with that.
So we're going to go ahead and call this one as Mongoose is going to be saying, hey, I want you to
require Mongoose now you de structure the schema or you're not and that's totally up to you.
I usually don't.
So I'm going to call this one as user schema and we're going to go ahead and say, Hey, new mongoose
dot schema.
Again, this is exactly the same as you saw in the documentation here.
In the documentation, they are de structuring it and calling it as directly schema and passing on an
object inside it.
In my case I say mongoose dot schema.
They are really basic JavaScript, nothing much more than that.
And here what you're going to write.
So first thing that we are going to need is going to be first name and this first name is going to be
an object.
Usually all of the properties inside the schema or object and you can pass on so many things inside
this one.
The first one that we're going to say this is compulsory.
You have to write in what is the type of that data number string.
You can read more about that in the docs.
We are also going to say that if nobody passes on me the first name, I'm going to set the default as
null.
You can pass on default whatever you actually like and you can pass on fields like required to true.
That means it is required.
We're going to do that.
So don't worry.
Let's go ahead and copy this one.
So again, I love to use the shortcuts, so let's go ahead and change this one to last name.
This is going to be a type of string.
The null is exactly same, so that is fine.
What else do you want?
Let's go ahead and copy this one.
We're going to say that I am interested in grabbing the email.
The type is string, but the default cannot be null in this case, but rather this should be required.
Or we can handle the required a different way.
But let's go ahead and say that this should be unique.
This can also go with your username, also that your username should be unique, but in this case it
makes sense to have the email as unique.
And you can also go ahead and write something like this that you want to have required to true.
Then if this is not there, it can go ahead and say, Hey, this is required even further.
You can go ahead and down, write something required is true and you can pass on a message just like
we saw that, hey, if this is required is true, somebody don't pass me up.
I'll show him that error message.
So we'll do that.
Definitely.
Don't you worry on that part, but we'll do that a little bit later.
Now, moving on, we are going to go ahead and say I want to store password also.
A storing the password in the clear text format is really a bad idea.
We won't be doing it, but as of now, let's just go ahead and declare that.
And finally, last but not the least is going to be the token which will help you to understand so many
of the things.
Let's go ahead and say type.
And that's going to be a simple string.
Now, there are more properties that can come up here like token expires and token generated on and
a whole bunch of other things that can come up.
I will definitely discuss some of the strategies with you that what strategies can come up with forgot
password or saying that your user is now validated by clicking the link in the in the mail and all of
that.
We'll discuss the strategies of that, but not right now.
Okay.
So this is the schema design, but remember, this is just a design of schema.
You haven't exported an object which is following this schema, so that is important.
So we're going to go ahead and say, hey, module dot exports.
And this is going to say that, hey, I want to use Mongoose for everything and I want to create a model
from this schema.
What do we call this model?
We are going to call this model as simply a user.
But the problem is, no matter if you write it down, uppercase or lowercase mongoose automatically
brings everything into the lowercase.
In fact, MongoDB also does the same via their driver.
So you can just go ahead and write this user, but you are also going to notice when we bring it into
any other file we actually denoted by uppercase U as user.
So again, it's totally up to you behind the scene in the database.
This is all in lowercase.
Okay.
And further what schema this user will be following.
That's just what we have designed.
User schema told you it's really easy and really, really simple.
You want to add in more country, maybe your university, maybe your age.
You can all go ahead and do that.
In case you want to study a little bit more on that, you can go ahead and see.
These are the permitted schema types, string numbers, date buffer for files, boolean, all of that.
You can directly go ahead and inject that.
But I think this is all good for at least this video.
Let's go ahead and catch up in the next one.