Hey, did everyone share?
And in this video we will be creating our first application, which is the auth system.
Now, let me remind you one more time.
We have already studied not just about Mongoose, but also about the Dot, D and V.
So all that we have studied is now going to go into this project.
Then that's how we'll be doing.
Another big reminder that we are not going to separate the entirety of the project into all multiple
files.
That's what I love to do.
But if I'll do it right now, it might create confusion some of the for some of the absolute beginners.
So we won't be doing that.
We will be rather separating it one by one, step by step, a little bit in this section, a little
bit in the next own section.
And just like that.
But don't worry, I'll tell you how the scalability is maintained and how other developers can come
in and still can have an overview of how the project is structured out.
So for this, let's go up here so I can actually go ahead and bring this up.
We can actually minimize this.
We don't need it right now.
Let's go ahead and clean this up and I have already some stuff, so I'll go one directory back and do
LRS.
So these are a couple of my projects that we have built up in the last section.
Now let's go ahead and create a new directory and we will be calling this up as ae auth system.
That's nice.
Okay.
Now once I go into this AE auth system, I need to create a a package here.
The packages are JSON file.
So I'm going to go ahead and say NPM in it.
We are not interested right now in answering all the questions.
So we'll just say dash y to accept all the default.
Yes, there is a way to change the default as well, but that's a little bit out of the scope.
Probably a crash course somewhere on the YouTube later on.
Okay, once this is done, then I obviously want to install some of the libraries.
Express is definitely going to be one of them, but I will skip now from from now onwards, I'll skip
the swagger part because I think you can do it now.
We have done quite an extensive detail on writing the documentation, so I won't be adding the swagger.
Now, we also have studied a little bit about the dot envy, so that is what we need to now inject.
And apart from that we also going to have a mongoose which is again ODM.
We have studied a little bit now we want to study more in depth about it.
So these are the basic ones that we need to install now.
Okay, this is that's quite fast this time.
So we're going to go ahead and open up our code editor here.
And this shouldn't take too much of the time here.
So I trust this.
And there we go.
Okay.
So this is all what we got up here.
And there we go.
Now in here, we're going to have a package of JSON file.
Let's go ahead and create a start script.
Now, in the START script, we are going to go ahead and say Node, which will be firing up indexed
or us, because obviously we want to push it up.
Now, this is all great, but I don't want to keep on reloading my server, so I want to install the
Node one as well.
So I'm going to go ahead and say NPM install, but with the Dash dx of Node one, let's go ahead and
install that also.
So it's going to take a little bit time.
And again, I think I should use the in-built terminal now.
Now what we can do is we can actually go ahead and put up a comma and duplicate this line and can simply
go ahead and say that I want to have an NPM.
Instead of saying NPM start, we are going to have an NPM run dev as a command.
And in this one, this is going to be governed by Node one.
There we go.
Node one will run indexed args file.
Make sure to remove the trailing comma here.
This is all great.
Now what this is happening or what we are doing is whenever you deploy an anything on the server, it
just runs the one command always which is NPM start.
So a dependency this time is not going to bother this again.
There are so many strategies that we can work on with that, but you get the idea what we are doing.
Okay, once we are done with that, now we need to create a couple of folders and file.
Now specifically, I'm going to go ahead and create an index.
JS But also I will be creating an app.
JS And I'll tell you the reason why we are going to do it in a minute.
Okay, so this is all good, this is all great, but we need to create a couple of more folders where
all the things are going.
Now, remember, we need to connect with database also we need to put up our env file.
Also we will be creating our models also and there can be more folders.
But this is the bare minimum basics that we need to go now.
Okay, so for this, what I really prefer is actually do it through the terminal because if I do it
from here, it sometimes put folders all inside and I don't really like that one.
So we're going to go ahead and use my terminal again.
If you don't know the terminal commands or anything, don't sweat it out.
It's all okay.
You can just use the system, but make sure your structure looks like this.
I'll show you in the finder as well.
So this is all what we have now.
I'm going to go ahead and create a couple of directories.
So the first directory that we are going to have is all the models, or you can just call it as model
however you like.
There is no wrong or there is no right in this one.
Apart from this we have the model and then we are going to have some of the config now putting up the
dot in the file.
In the config or not, that's your call.
I wouldn't be putting it.
I would be putting it into the project route.
But still, there are some files that need to go and later on we are going to write some middleware
and we're going to talk about them as well.
So let's go ahead and create that directory as well once you do this.
Now these directories are here under the project route.
Now apart from this, we need to create a couple of files as well.
So in the model, we are going to create a file which is going to be simple user dot JS.
Now you want to keep it as all lowercase, all uppercase.
It's up to you.
Let's go ahead and use the lowercase again.
A Totally your decision.
It's not going to bother anything at all.
So this is the basic.
Now touch is a command which creates an empty file for me.
Again, you might be having different one and I will be creating another file into into the config that
will say database JS.
This will be responsible for connecting with the database and then we are going to have a middleware.
So we're going to have a middleware.
We are going to call this one as all dot JS.
Now why we are creating so many of the files.
Yes, there will be usage of all of this, but actually creating all these files because I know what
strategy I'm following up is actually a good structure.
So in the config, I have database Node.js.
In the middleware we have ordered JS, there is nothing in these files and in the model we are having
user OC Going back, we will be touching just the app dogs.
As of now we have installed everything that we kind of need for now, so let's go ahead and work on
with that.
So remember the first thing that we are going to do is create an express.
So we're going to call X Press that is going to be coming up from require.
And let's go ahead and say express.
Now after that, we go ahead and create an app which is created by Express just like that.
And there we go.
Now it can have multiple routes, so we're going to go ahead and have a simple basic route, not length
app dot get just like that and we'll have a home route and this home route will be having a comma and
just like that request and response and there we go.
And we're going to simply say that resource send and in here we are going to go ahead and simply say
in the edge one that hello from earth.
AWD system dash ae.
There we go.
And again, make sure you don't forget that this entire X1 needs to go in the double code that is absolute
required.
But one thing extra that we'll be doing in this file is instead of saying, listen here, we're going
to go ahead and simply say that module DOT exports and we're going to go ahead and say AB while we are
doing this.
We could have just said, listen directly here.
Yes, we could have.
But eventually you're going to notice that sometimes this file gets so much of big with the middle layers
and the roots and a whole bunch of other thing that it is better to keep your listening operation and
all of that into a separate file.
This is a good recommendation, so go ahead and just export this one.
Remember in the package dot JSON, we saw that our node mom and the node are running the index file.
So we are exporting this from the dogs and here we can go ahead and simply say, hey, I want to go
ahead and import the app again, just like we were exporting using the require statement, we can do
same, but this time instead of requiring from an installed library, we can go ahead and say from the
current directory, just get me an app.
Once this is being done, I can now go ahead and say listen and in here we're going to go ahead and
say, hey, let's just listen on the port, 4000.
Yes, we will be taking care of port in a minute.
Not right now.
We're going to go ahead and simply say, hey, let's run this one like this and say console, dot,
log.
And we will be saying server is running at port 4000 with of course Dippin Dots.
Okay, so this is all done.
This is all good.
Let's go ahead and see if we are able to set up this match so far.
So we're going to go ahead and say npm run dev because we want to keep it running up using the Node
one.
So we see that some of the crashes so it says app dot get is having some the issue.
Let me go ahead and quickly see that why app get is having some issues there we go.
Should be all happy now and server is running on the port.
Come on, don't go anywhere.
Let me bring up my.
Screen.
And there we go.
Let's go ahead and try localhost 4000.
Hello from our system.
Okay, so so far this is looking absolutely fantastic.
We have broke broke up the entire file into not too much, but at least some of that in the next video.
We're going to continue from here.
And let's catch up in the next video.