Hey, did everyone.
They sure.
And welcome to another video.
In this video, we are going to finally start our journey.
We have already designed our model and all the features that we wanted to to work in the model.
Now, let me again remind you that the user model usually is the most difficult one after that, the
products and orders or whatever else you are selling or trying to build an application that doesn't
go with that much of complexity that we have worked on with these methods.
But again, if something makes sense to you that yeah, this is something which needs to go as a method
inside the model itself, please don't hesitate and always put that up there.
So let's go up here now further down the road now we need to create a lot of routes and methods controllers
for that.
And again, I cannot just blindly go ahead and write all these methods.
I need to have a plan that what we are going to build up.
So in this case, what I have done is I have tried to kind of a mind map the things that how this is
going to work.
So in the previous one, we saw that we have a models, we will be working on user product and order
and we have placed some sticky notes on that.
Now these mind mapping actually always vary on based on what software I'm using or what kind of things
I mean.
But again, they remain almost the same.
So we have done with this model.
Now obviously each model is going to be following up some routes that when you visit these routes,
this model will be mainly controlling these routes or will be affected by this route and there will
be some controller associated with them.
Now, there is no such big need of writing the name of controller.
In case you do that, that is fantastic.
Please go ahead and do that.
Now, in this case, I have given some of the routes that I want to user to have a sign up functionality,
a login, log out slash forgot password where he can request an email to have an instruction of how
to reset the password.
This is where we are going to learn about sending the emails and a whole lot of other things.
And after that there is a slash password, slash research, slash token.
You can name the route, whatever you like to have.
The whole idea is to grab this unique string that we created earlier and I want to grab it from the
URL itself.
And then if the string matches with my database string, I will allow I will also request the password
in the body as well so that everything can be resettled in the back end.
Then this is going to be the user itself.
So you want the information about all the information about the user itself.
We will be allowing that this is where we are going to study about middleware and something interesting.
And after that, if user want to update the password and if the user want to update any other information
now, is there a need to separate these root?
Probably not.
You can actually just give a same page to the user that if he sends the password, just do this.
If he doesn't send the password or send something else to update, you can allow that.
But I'm going to keep them separate because this actually makes sense a little bit more to me and will
make to you as well eventually in the future.
Okay.
So let's go ahead and set up the basic signup route and we'll talk more onto that.
So let's go back up here.
Now, the first thing is we are going to work on the controller, so let's go up here.
So notice we have created the model for already there is already a home controller for that and we will
be working on now is user controller.
So I'll be saying user controller dogs of course.
Now in this controller we don't need much, but we will be working on the model user quite a lot.
So let's go ahead and bring that up.
Now, this is kind of a functionality, not functionality, but kind of a regular data life thing of
the user that always bring these models with the uppercase letter.
This is kind of a convention and we are going to go ahead and say, hey, we want to require it and
this will be one directory back inside the models and we have this user.
So now we have this user again, we will be using it later on, not right now.
So let's go ahead and export a method.
So I'm going to go ahead and say export dot, sign up.
This is a basic functionality.
Now before we go ahead and do this, sign up.
Actually, I would like to comment it for a second.
We also need to bring up one other thing which is inside the utils.
In case you remember, we have not in the utils in the middle where we are wrapping up around everything
into this big promise.
So we will be doing that now.
So let's go ahead and import this big promise.
So let's call this one as simply const big promise that will be coming up from require.
Just like that one directory.
Back inside the middleware, we have this big promise.
Now, this is all up here.
Let's go ahead and uncomment this one.
So export sign up.
And remember, we are wrapping up around everything inside this big promise.
So let's go ahead and say, hey, this is a big promise and wrap everything around it.
Now, inside this, you write your regular very basic method.
Again, we will be working with the connecting with the database.
And database is always on another continent.
So we'll be working with the async and then writing our regular method.
But make sure you also say that this is a request response and we also go ahead and pass on the next.
We won't be using it, but maybe our promise might need it.
And just for your information, the actual format is actually like this.
We have the errors, the request and request and the response, and then we have the next.
Since we are not using the error or we don't have any kind of a special handler for the error.
So that's why we are working on this match only.
But in some cases you might also see that part also.
So let's go ahead and just wrap the function just like that.
Told you a big promise is a thing which you create once and you forget about it.
If anything goes wrong, it will handle it very nicely, but otherwise you just don't worry too much
on that.
I'll just add a comment here and that's it.
We will be working on signup functionality in a minute, but first I want to go ahead and work on the
roots itself.
So let's go ahead and move on to the Roots.
We'll create a new file which will handle all of our user roots.
So we're going to call this one as just a user is.
Now we need to create a router here.
So again, router will be coming from the express itself.
So shouldn't be a much of a worry.
So let's go ahead and say, hey, I need X Press and Express is going to be coming from require express
and let's go ahead and grab a router, not the app app.
We do that in the app.
JS But this time we need just the router.
So we're going to go ahead and say, hey, give me a router and router will be coming from Express Dot.
And again, this is a capital root for a router and worse.
And the very first thing we always do is export this router.
I have seen people forgetting quite a lot about it.
That's why I recommend everybody that as soon as you create the router, go ahead and export that and
do rest of the things later on.
So there we go.
We have now this router now coming on.
We need to create a route where we can use that sign up method that we have worked on.
So first let's bring up that.
So we're going to go ahead and say, hey, I want to bring some methods and these methods will be coming
up from let's go ahead and say, hey, I want to go ahead and work on require from one directory back.
We have controllers and inside that we have this user controller.
Okay.
So what is the one method that we are exporting right now, which is just the sign ups?
So as soon as I say this, they should actually suggest me hopefully in theory.
So if I go ahead and say sign up, okay, now let's create a route based on this signup.
So router dot route and we are going to say that what route you want to have, I will say that this
is going to be simply sign up.
That's basically it.
And as soon as the sign up comes up, there should be a verb there.
So that verb in this case is going to be post again.
The data is coming up.
We are putting that data in the database as well so it makes sense to have a post route.
So what is the functionality which will handle this post route?
Simply the sign up, that's it.
That's how you create the routes and we'll be creating a lot more in the future.
But there is one more thing.
This router is not yet being imported to dogs, so this needs to be done here as well.
So let's go ahead and work on with that.
So this is where we import our all of our routes.
So we're going to go ahead and say that, hey, I want to bring up a user.
And that will require.
Let's go into.
Come on, let's go into roots.
Come on.
Suggest me.
There we go.
And inside that, we have this user.
Now, all I have to do is inside my router middleware.
I'm going to make a copy of this and I will say that, hey, this will be handled by the user.
So now what will happen if somebody visits local host, colon, whatever the port you are having in
my case, 4000 so localhost slash column 4000 slash API slash V1 slash sign up, then he'll be able
to see that.
Now, just to make sure that we actually test this out nicely, I'm going to go ahead for a moment.
I'm going to turn this up into a git.
And here I'm going to go ahead and simply send a response.
So I'm going to say Rez Dot send.
And I'm going to go ahead and send up a simple signup route so that we can at least test out these things.
Now for testing, we're going to be firing up the postman.
So let's go ahead and bring up the postman, because it makes sense now to have this postman up and
running for us.
Okay.
So I will create a new collection and everything up here.
So let's go ahead and first create an environment.
So let's go ahead and create an environment called this as t shirt store.
And inside this, let's add a variable.
Let's call this one as domain.
And the value is going to be http colon slash slash local host slash API slash V one.
So this is like the basic of all the stuff that I have.
And after that, I'll be putting it up.
So I think this is all what we are going to have and.
Let's place it into t shirt store.
Okay.
We can save that now.
Now, let's go ahead and create a new collection of the APIs, because this is important and sometimes
we need to place that into separate folder.
It's a good thing.
So we're going to call this 1st shirt.
Store.
And we are going to be changing the environment to the t shirt store.
That is fantastic.
Now, let's go ahead and close all of these guys.
No, I don't want to save this.
And inside this one, we are going to create a new folder, add a folder, and I'm going to call this
one as simply user.
So all the requests that are based on the user will actually go up here.
So I'm going to go ahead and say add request.
There we go.
And this one is going to be for sign up.
For sign up.
As of now, we have get, but we are going to definitely modify it a little bit.
So we're going to go ahead and say, hey, I want to have.
This domain.
And after that domain, we are going to go ahead and simply say, slash, sign up.
Now let's go ahead and hit a send on this one and it says, hey, the connection was refused.
Did I set it up correctly?
Let's go ahead.
Did we got a request?
No.
Our server is running.
Let's go ahead and quickly check that.
What is messing up in this one?
My bad.
I forgot to just add a port number after the localhost.
So I go back again into the environment and again it sometimes takes a little bit while to actually
set up the environment.
Once you set it up, it's all great.
We'll be saying 4000 slash API slash, let's go ahead and save this one.
So variable is now saved.
And that's a beauty about having an environment variable that if you have like so many of the requests
going on, suddenly you decide to change that.
Now it's 5000 port.
You can just change it in one place and it just works everywhere.
Let's go ahead and send it up.
It still says there are some issues, so it looks like there are some more of these issues.
Let me go ahead and try to figure them out one more time.
Okay.
So it turned out that when I just don't use the variable, I just simply send local host 4000 slash
API slash v one.
The sign up route actually works fine.
So probably there is something which I'm not able to see.
I just want to convert this much of the thing slash tilde v one into available.
So let's go ahead and copy that.
And let me just try to create another variable.
Probably I'm missing something which I'm not able to figure it out.
But again, no issues.
We can just go ahead into environment, click on the next and we want to create this one.
So I'm going to call this one as t shirt store.
And this is a new environment for T Shirt store itself and this variable will be available here.
I'm going to call this one as simply my domain.
Maybe there's something which I'm missing.
So initial value and the current value is going to be same.
Hopefully, let's save this one and let's try to get another route up here.
So let's go ahead and close this one and send another request to get same get request.
And we'll be saying that, hey, I want to use something like my domain.
And after that slash sign up, let's go ahead and see if we are able to see something.
Okay.
It says I cannot get the sign up.
Probably I misspelled that.
Okay, sign up.
And now we get this sign up route.
So probably there is something which I was missing and I was not able to locate that.
So that is totally fine.
I'm going to go ahead and close this one because I don't need this.
This is fine as my domain.
I'm going to go ahead and save this one.
So this one will go into the t shirt store and inside the user itself.
So setting this up is always going to be helpful and we don't need this my sign up route now, so I'm
going to go ahead and remove the above one.
So let's go ahead and delete this, delete that.
Now also, I'll select this route up here and we're going to rename this one again.
Renaming is super easy, so I'm going to go ahead and rename this one.
I'm going to call this one as simply sign up.
There we go again.
Renaming doesn't mean where you are sending the request itself.
It doesn't really bother that part.
So we're going to call this one as my domain.
Again, it's really the same again.
I prefer that using the variable makes life a little bit easier.
In case you don't want to, you can simply go ahead and use HTTP colon 4000 slash API slash V one.
So this is the sign up route and we can also verify that by using our same dummy route.
So this is what it is.
Now I'll check back again into sign up and there we go.
Now in definitely in the reality, we'll be changing it into a post request, so I'll just save it up
here.
Notice the request changes up here.
Let's do all the changes up here as well.
So let's go into user and this is not the get this is actually a post route and sign up will be handling
this one.
So this is all the setup that we got so far in the next video, we'll be actually working on signing
up a real user.
Let's go ahead and catch up in the next video.