Register and login a user with JWT token

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right everything looks good now this video about this section of the video is going to be a little bit longer because I wanted to cover really a lot of stuff in this one so our action plan is ready all we need to do is Now understand that how we can actually uh first of all the encryption is one of the challenge in front of us and eventually one of the challenge will come up is we want to send this token into the user's cookie so let's see how we can do that the first one uh is really easy you can just use it use a package like a b Crypt and we want to use bcrypt.js not the bcrypt although that also works but this is an easier implementation much more abstract form of how we can do things and this is what I want so please search it for me and bcrip.js a really popular one in the community of JavaScript developers you can see the weekly downloads a lot of people use it so this is really easy one of it yes you can use inbuilt crypto module as well but this one is better it has lot more layers to go on further uh so that we can have better encryption going on so it's inbuilt crypto module randomly by it so all these detail you can study I'll not go much into this one this is how you go ahead and use this one so let's go ahead and copy this and love it absolutely love it I can do all in the browser I don't even have to open anything else uh so yes please allow pasting of this one so that's the part one of it that what we need and another part that we need I really need to learn the shortcut of how to move into the tabs because previously the alt tab was between switching the application now everything has happening in the browser I need to learn about how to move between the tabs before and after all right so the next one is actually cookie parser so we have a really popular package for this one cookie Dash parser the second one I don't know why the search is giving me all the second ones but this is the one that we need cookie parser again a really smart package acts as a middleware you might have noticed that and once you install that it allows you to actually access your cookie just like when you see requests request if you try to console log that it's a big object which allows a lot of requests to come up from the user maybe request.params that means all data that comes from the URL or maybe request.body or request.json.jsonrequest.body similarly we can also have a request.cookies just after adding this one so this is a fantastic package this is how you inject it and this is how you use it app.use cookie parser and that's all so let's go ahead and add this one so we'll just say hey bakerjs is you're installing this one so go ahead and install cookie parser copying pasting is always a good idea in this case so that we don't have the mistyping in the packages also I have committed the last changes as well by the way so let's see package.json and we have uh these Json web token the cookie parser and wake up JS so these two are already with us let's go ahead and see how we can do that okay first and foremost how to get all data all of your data is stored into either request.body but there could be request.params as well in case it is coming up from the URL which is another subject in itself but right now we know that everything is coming up from request.body which is an object not ordinary object a gigantic one and what all data you want to expect from the user to come up so you can go ahead and destructure that directly and can have this one we are defining that we want to have a first name last name email password is all what is going to come up now so far this has nothing to do with the user model that we have created because this is just something that is coming up from the front end so my first job is done get all the data from the body all right all the data should exist now this is where the validation checks actually comes up so I want to check whether all the users are there so I'll just say that hey if there is a email let's start one by one don't want to just skip the order otherwise it's a bad practice first name last name email and password password so all of this data is there so just want to have this one so if all of this data is present then do something so I'll just go ahead and replace it with the or sign so this means if first name is there uh or we might have the last name as well so we'll just go ahead and say or first name or last name email or password so if all of them are there then do something so all and you can go ahead and proceed with and as well I'll leave this as a simple assignment that which one you want to proceed you may want to go that hey uh now again remember this understand this very carefully if first name is present or there is a last name present or there is an email or there's a password I want to proceed if any one of them is present so what do you think let me know in the comments which one is a perfect is an and operator or an R operator yeah that's a tricky question all right so uh just go ahead and replace them with all because we want to check all of them should be present so there we go we go ahead and say hey this one should be and so there we go now we are checking for all the values first name last name email password all of them are present then move forward but the easier check would be that if I go ahead and select all of this and wrap them up inside a parenthesis and put up an or statement the negation sign so now this condition is checking if first it was checking if all of them are present now it is checking if all of them are not present even if one of them is missing then it's going to create and jump into the line number 19 of the structure of the code really simple all you want to do is in this case we want to send a response so we'll just say res dot send and we want to send a status first so let's go ahead and send a status status codes are really important maybe we'll have a separate video on that there is a code in case you want to structure study about them there is a nice very clear-cut documentation about this which is a status code and mdn actually shows it very nicely very precisely that hey here are all these informational code so in case maybe you want to have a redirectional message used between 300 to 399 server errors 500 to all of this client-side response means client has sent less data not so accurate data then use a response between them again which one to use 400 or 450 or 451 that's your internal matter of your organization just make anything as a standard throughout the organization and that's that will work so we'll just say 400 because client is sending the less data and then we'll be just sending a response a response could be in the Json format again depends on what your organization is making a standard that hey we always send the response in the text format or maybe Json format we do it Json basically I'll show you later on how we can do it in the Json but right now we'll be just saying that all fields are compulsory again you can write better messages than this one okay if this is all done and all good then obviously we need to check if user already exists now here is the most important part you can only check if the user exists or not uh through the Mongoose because Mongoose has the ability so we are already creating this user up here we have already exported that user so why not to bring this into our app.js and use everything from this guy because it has the access of it so let's go ahead and do that so first of all we are going to just grab the user uh so we'll just say hey user feel free to call it anything whatever you like and that will be coming up from a require and let's grab it from One Directory back we need to go into the current directory and inside the model then we have just one file which is user so now I have access to this user and if you remember user was an object uh like this is this entire export statement this Mongoose this user is Created from Mongoose so Mongoose is your database odm means it can query to the database it has access to this one so my job of check if user already exists can be simplified can be simplified a lot how we can do that we can actually make a query to this one again I told you whenever you make a database query always assume your database is in some another continent so always always go ahead and use a weight in front of all database calls it takes some time okay then we have access to this user and user can actually go ahead and query so there are a lot of query statements that you can learn through Mongoose the one which we are using is find one that could be find by ID and all of that right now I'm looking forward to find one based on what I want to check if user already exist or not and this should be based on email so let's go ahead and this is how you query like you write your where Clause not the accurate statement but where Clause so I want to search based on email now one thing you need to be absolutely clear since I'm writing an email here this email refers to this email which I got from request.body now if this is true then we should hold this into a variable so let's go ahead and call this one as existing user and let's go ahead and hold this now once we hold this then we have to check if the user already exists or not so if user exists that means we cannot move forward user is already registered so let's go ahead and do a simple if statement if there is existing suggest me please yeah existing user then we don't want to proceed and maybe we can borrow a code a piece of code here or maybe we can write a method uh to simplify it consider this as an assignment so whenever you send a response there could be a generalized method where you just send the Response Code as well as whatever the data you want to send as a Json or something so we'll send a 400 response uh 401 maybe whatever your organization is making is standard so all fields are compulsory instead of that we will say that a user already exists with this email so whatever makes sense you can go ahead and work on with that all right there we go we can remove this one all right so we have now proceeded on to this part that hey this is how we do that now the next part is how we can encrypt the password so encryption of the password we have installed the library but we haven't actually uh called the library so I'll just say just above the express or even after the express doesn't really matter we'll say hey I want to encrypt the things so I'll just say hey we call this as P Crypt and the bcrypt is going to come up from require and B crypt.js so now I have access to this bcrypt and I can quickly go ahead and look that hey how big it works maybe I don't know so B Crypt Js and this is how I can use bcrypt.js first of all I have to configure I don't think we need a configuration here is a user syntax so you have to provide a salt and a hash value and then you have to first require the baker we have done that then you have to provide a salt value the default is actually the 10 but there could be more and then there are couple of methods that how you can actually compare this and to check the password to Hash a password probably this is the one that we require and again there are a lot of methods how you can do that I'll show you a really easy way that how you can actually do that so what we want to use is auto generate assault and hash I think that is the one that we want to use so bcrypt.hash is what we want to use then you can provide whatever the password is and then you can provide the number of rounds you want to go for it and probably that's it we can actually have a callback function in case there is some error but we'll just go with that so that's nice okay let's see how we can encrypt that and here is the encrypt password so we are receiving from the user this password let's go ahead and encrypt this one so we'll call this one as a new variable but first this bcrypt is not an easy thing it's a cryptographic algorithm that runs through and maybe your server is not that heavy and it just doesn't generate it automatically so writing in a way it is always a good idea so let's go ahead and use Big Crypt and again the popular method of hashing the password so hash and if you just go ahead and look for it notice it says give me a string give me a salt and I'll just encrypt this one solved which is a string and the number of time and again this is an optional notice here the R so you can go ahead and skip this one so I'll just say hey take the password that was given to me by the user and rotate it for the number of 10 number of rounds so that is what we are going to be doing let's hold this into a variable so we'll just say a hash password or we'll call this one as my encrypted password password and there we go so we have this await and everything nicely going on so this is done we have encrypted the password told you it's not that much of a difficult now it's time that we save the user in the database all right let's go ahead and how we can save the user so again this is a database operation don't forget to put away why because it's in another continent all right so we'll just say user all right and we want to just create so there's a simple method that how we can create the user there we go and you have to pass on an object with all the details because it's a user so model expects what all the fields you give it this time it is referencing to the model that you are creating so we'll just go ahead and say first thing that we want to go ahead is first my field is first name which is mentioned in the model and I want to add a data of first name here now always remember this first name is something that I am extracting from the request.body but according to the new syntax of JavaScript JavaScript is smart enough that it can automatically look for that the names are same so I can just go ahead and work on with that similarly we'll just go ahead and say last name and we can use the shorthand method email is also there and we have this password now if we go ahead and save this as password did I mistyped it I'll just select it and see if I have mistyped it somewhere nope all right so if you go ahead and do this password it will automatically take this password so all of our effort of encrypting this password will go in vain we don't want to do that and that's why we'll be saying hey take the password reference from my encrypted password so this value is now getting used great all right but this doesn't actually uh this actually creates the values in the database so we will hold this into a variable so we'll just say const user there we go feel free to call it anything now whatever is saved in the database and whatever the response we have got we are storing that into a user variable uh so that is it but we want to also generate a token for the user and send it now one thing you might be remembering that we are not storing this token into this database we have to reverse the order so in this case we actually have to generate a token and all of that but I'll show you a better way discuss with that later on but right now remember we are not storing that token into the database so that is one thing you have to be cautious about now let's go ahead and generate a token and I'll show you some of the details about the token generation as well all right so I want to generate a token now in order to generate a token we have already installed a package known as Json web token but I have no idea how this package actually works so I'll just go up here and look for the documentation so Json web token did I wrote it correct nope JWT should be a clear one uh no I have to write it correctly Json web a token hope okay so this is how it goes on and let's search for it Json web token the usage is really simple and there is an example so you have to say that hey first require the Json web token okay let's go ahead and do that that should be the easiest of all uh come up here and instead of calling it as Json web token let's call it as short as Json web token JWT and again the require will come up here just like this and will be saying that hey let's go for a Json web token all right what are the next steps the next step is that in order to create a token you have to use JWT DOT sign and provide whatever the values are and then provide this s h h this is a secret that you have to provide the ideal situation is use the secret from the environment variable so you don't have to refer it again and again we can go ahead and do that now for this let's go up into code space actually into this I have to reload this so I'll do that a little bit later on so we can go ahead and work on with that and that's basically it that's all it takes to actually generate a token so let me provide you and by the way in case you got confused with what this is this is actually your payload means all the information that you want to encrypt into this payload and token so you can just put as much information as you like let's go ahead and try this out again code is really simple for that generating the token so what I'll say that hey let's generate a token so for that JWT DOT sign is the method there we go then you provide your payload notice nicely it says payload and and in the string format and then provide a buffer or a secret key JWT sign in option so there is a lot that you can do so what I'll do is I'll just hit an enter so that everything is in a separate line and easily understandable first is payload now payload what I'll say that hey I want to extract a user ID so I can go ahead and call this one as ID in the token or I can go ahead and call this one as user dot underscore ID whatever you like to call it just call it that I'll just say hey let's call it as ID in the payload that's it and we'll be saying that hey I'll say user dot underscore ID now from where this is coming up now remember this that we actually stored the user which got created in the database now this user in the mongodb has a lot of field of course the field that you have mentioned will be there but mongod DB in addition adds a property of underscore ID that is uniquely identifiable for every single entry that you make in the database so this is what the payload is but in case you want to add more field you can go ahead and add it for example maybe you want to add an email so we can go ahead and refer say email now this email you can bring it up from user.email that is always a good idea but since we are doing all of this stuff then we can actually refer to this email directly which is given by the user so again depends on what you really want to do and which one you think is a best practice my goal is to make sure that you understand every single line of code of what we are doing how we are doing it then you have to provide a secret so just put up a comma and provide a secret remember it was saying SSH which is a bad string so we should be properly giving up a better string probably something like from process.env.secret or something so let's go ahead and put up a comment here for you that hey we should be actually using something like process.env Dot dot JWT secret something like that so maybe you get a reference of how this is being done all right so once this is being done then we can go ahead and say that hey maybe you want to add more additional Fields so yes you can go ahead and add one more field if you press Ctrl space this will give you that hey what all I can add maybe encoding expires and headers issuer there's a lot that you can do up here I'll just say hey add me expires in and maybe I want to expire my token within uh two hours this is the syntax you can refer so this is how you actually create your token that's all you do let's store this token into a variable so we're going to go ahead and say const token there we go totally really simple okay uh oops okay so there we go now we have got this token stored now how to actually go ahead and keep this token so what I'm going to do is I have access to this user which was given to me but this user has a schema means it has a model that I've created and in that model I have got this token which I created it's not coming up from the database so I'm appending that and I'm storing this token value which I just generated there all right okay also what I want to do is I want to send this entire user object to the front end yes of course all information first name last name email password and the token which I just added into this big large user object but one thing I realized I don't want to send this password because although it is encrypted still don't want to send it to the user it looks weird so whenever you don't want to send any field you can go ahead and refer to that field for example password first name last name I don't know why is it suggesting Me Maybe I have 100 made a typo somewhere that's why it's referencing me yeah there we go gotcha so her password that's why it was referencing me again again have to fix this typo so password and we can make it undefined so as I was saying got distracted that if any field you don't want to send on the front end you can actually set it undefined it will not set it undefined in the database it is just an object that you are storing here into this file and you can make any property of that object as undefined it will not send it under the user so that's the basic of it all right a lot of work that we have done now it's time to go ahead and send this entire response onto the front end all right so how we can do that it simply res a DOT status so let's go ahead and have the status yes I know this is bothering you and there we go so we'll say that hey everything was great so 201 or 200 means everything got correct so this is the status and we don't want to just send the data we want to send a Json response in the Json response you can go ahead and add a Json object whatever the data you want to send up I just want to send this user now additionally maybe you want to send the token exclusively also then just go ahead and send the token as an object so whatever you want to send you can go ahead and send this one so this is the basics of how you actually go ahead and run your code in the back end step by step remember it was not complex lengthy yes but not complex and we just wrote a structure code that what you really want to do and we just proceeded on that now here comes the debate that yes maybe this is not a great approach maybe we don't want to send the token maybe we don't want to send the user maybe we want to store the token into the database also for further reference yes you can go ahead and do that now whatever makes sense to you my goal was first to introduce you to the basics of how these back-end infrastructures are are being written and at least an auth system I think we have successfully done this one all right let me show you one more approach because now I think you understand a lot of it and I think if I can give you an additional plan you can go ahead and work on with that so I'll just say hey this is my register similarly we can go ahead and say app dot post and let's go ahead and have a simple login route this time all right same steps repeatable that our database is another continent so having a sync we get a request and we get a response we send a response but we need a response object for that and now let's go ahead and figure out so first of all I want to collect all the users so this will be a database operation so I can try catch is a good idea we don't want to log into the error much so we'll just say hey let's just go ahead and log the error maybe you want to log the error messages maybe some custom response you can go ahead and do that or maybe we'll build some really complex uh burn application in case you have enough requests let me know and we can go ahead and do that so what is the action plan uh really simple get all data from user or from front end or from body or whatever you like to go ahead and do that once this is being done then find the user in the database so find user in DB DB okay if that is all done then matches password obviously so otherwise you might be sending the wrong password so match the password so password in our database is actually encrypted so whatever the user is sending it we have to encrypt it and thanks to jwt.jwt the big crypt.js it will again be same encrypted because we will be using the same secret so then we have to compare the strings so whatever users send we encrypted our database already hold the encrypted one we compare them pretty simple and once this is being done then uh we can go ahead and match the password if it matches then just uh send a token yeah that sounds great all right let's go ahead and do this this should be all super easy now and we can glide through all the values okay get all the data from users so we know that request dot body holds all of it body holds of it and we'll be saying hey cons this is a big object and there we go uh this time we expect that email and password will only come because it's a login route so that's that was super easy now we forgot to add a validation come on we forgot to add a validation so we want to check whether both the fields are there so let's go ahead and add a validation uh check right now we want to use the same validation check just we use in the register form you can make it more complex so we'll check that if user or you want to go with our nice catch and we want to go for user not user email my bad sorry email and we also want to have a password come on don't want to write it here password and we want to check both of them should be there so let's go ahead and work on with that so same logic wrap it up and say if both of them are not present then we want to send a response so we'll just send a response something like that uh so let's go ahead and say rest dot status and we will say that hey this is going to be a 400 if nothing was found so we'll just say fields are missing or something like that you can send a Json response for consistency but you don't know it and you can perform better there so we'll say uh email send all fields it's not all data I know that's a bad message but you can go ahead and write better message than this uh once this is all done that means I can find a user in the database definitely want to use the same uh this user for that for making this query so all we got to do is of course this is a database query don't forget that we'll say user dot find one we can actually use this find one pretty easy and we'll be finding it based on emails so let's go ahead and say that hey you take this email and if somebody is going to be getting fined out so we can go ahead and say const user it will be equal to a weight now what if the user doesn't exist I'll give this as an assignment to you if user is not there then what so go ahead and write a code for this one I'll assume that the user exists so again a small assignment for you so just go ahead and use that so assignment there we go you just check out a condition that if the user is not there then I don't want to proceed so go ahead and check that that's a nice assignment now coming up onto the part is how we are going to match the password now matching the password is actually super super easy you can use a weight syntax here obviously bakelip takes time so we're going to go ahead and say Hey Big Crypt now you want to compare and there's a super easy way bcrip actually gives you the way of how you can actually compare the password first is format is you have to provide the string and then you have to provide the hash value so I have to do nothing it basically literally asks you that give me the string and the hash and I'll compare it for you and I'll give it to you the password that comes from the user side and since I have queried the database already I have this access to user which will dump me all the database from that is coming up from the database side and I'll say hey there's a password since we are storing the hash password these are the all the two things that it required and it will just do the comparison for me so that is super super easy now the only problem is that we want to make sure that the user exists and the password is also correct now although in case you have done the assignment I've checked it then obviously you can proceed further and hold the result the true or false this actually gives you a Boolean value you can go ahead and store this and proceed further that's a one flow of how you can do this in case you want to do a hacky flow not a hacky flow it's a developer flow everybody uses it you'll find it in ton of databases and GitHub repository where people publish these kinds of code so we'll just cut this out and we'll match with another condition again if you don't want to use this condition totally up to you I'll say if the user exists that means and the password is correct so I'll just use an M person and then we'll use this one so again really really simple nothing to be worried about I'll just use a parenthesis now if the parenthesis is true so it will work if it is false it will not work so I'll just paste this one so this entire thing actually gives me at true or false a Boolean value you can read that in the documentation and this also needs to be there so if user is present that means database has given me some result not the undefined or null or something then I'll go and jump into this match password so this is doing two things at once again if you don't like this flow go one by one if and else there is nothing wrong in that part as well if this is all good I want to generate a token and I know already JWT can actually help me with that hey JWT just use a sign method to get me a token what are the payloads you want to give it to it so let's hit enter and the first payload that I want to give is say let's just provide an ID ID it will graph from user.underscore ID remember if I am coming here that means 100 user is there so I'm not worried on that part then obviously I have to provide uh other things like what is my secret so again we actually have to grab the secret from here and again it would be better if I just add this line up here in fact I can just copy all of this okay I have to go ahead and provide a better process.env JWT secret that would be better in fact if I can catch this up that would be better but you get the idea that why I'm actually giving it I can actually go ahead and use a better approach on this one all right so now once I have done this JWT DOT sign let's store that into a variable let's call this one as token there we go now if I'm reaching at this point that means I have access to this token so let's append this because remember we have access to this user but this user has encrypted password and token field is not there because it we didn't store that into database so we'll say that's user.token will get the value from token and also I don't want to set the password still so what I have to do really simple user.password undefined there we go now if this is all done now comes the important part is send token in user cookie this is where our cookie parser actually comes into the picture so cookie parser is a nice really nice parser what you can do is you can just install this and after that you have to just require that so let's do it one by one and I'll say hey I want to have a simple cookie parser access so I'll just say const and let's call this one as cookie parser or all lowercase would be good uppercase all right so cookie parser and we'll be saying require and we'll be saying oops cookie parser yeah that one now once you have this cookie parser you obviously 100 have to come up here it's mentioned the documentation that these are actually middleware so you have to write this line so that whatever the user cookies are I can have an access so remember I told you in the middleware section that the middlewares are nothing it's just something which happens in between so whenever a request is coming up the request might be in the Json format that's why we use app.use so that right in between our app is able to keep on is able to understand the Json format similar to this now we have the access that now our application should be able to understand cookies not only understand but able to interact with them that's why the cookie parser exist once you have this one here now I have here on this line have an access that I can go ahead and interact with anybody's cookies now in order to create the cookies if I go up here it's not really difficult to have your cookies notice here you can have a request.cookies I highly recommend that try out dump it out request.cookies and you can actually work on with that in order to create the cookies they actually mentioned that that hey how to create the cookies and all secrets and all that they are nicely mentioning it up here the secrets and options and all that so option is an object that is passed to cookie parser as a second option and you can read more for it and you have to provide values up here let me show you the code is actually super easy so how we craft the cookies is first of all this is actually the section where we are working on a cookie section cookie cookie section cookie section there we go okay so first of all we have to create an option now you can create it within inside that but it's actually much more easier and much more readable here so let's go ahead and create an options option whatever you like it's just an object there is nothing more it's just an object so first of all we have to provide that when is the cookie expiring so we can go ahead and say hey cookie go ahead and say expires it will not suggest you anything because these are options uh directly for the cookies so make sure you are cautious on that so we'll say that hey when is going to expires so for that you have to provide the date I will say hey new and date so this will use an option of date dot now so this will give me a date of exactly uh for today now the syntax of how we add this here is a nice secret for that how many days you want the cookies to go for three days all right then you have to convert that into the lowest unit so uh we'll say that hey there are 24 days 24 hours not days 24 hours in a day so multiply it with that then go ahead and multiply it with 60 so we boiled it down to minutes and then we boiled it down to seconds so go ahead and do that and then go ahead and make it a milliseconds so go ahead and multiply it with thousand so now this is the syntax that how you go ahead and do that maybe you want to keep it for one millisecond then go ahead and say thousand that's it if you want to keep it alive for maybe a minute so just go ahead and multiply it with 60. so this is minute this is ours this is uh so seconds and minutes and then hours and then number of days really simple syntax I hope you will not forget it from now all right so this is the first option that we go go ahead and provide it once this is all done then provide a comma one important factor that we want to give is HTTP only this makes your cookie secure not really secure the cookies are not encrypted but only server can actually manipulate this if this flag is on user cannot manipulate these cookies by going into the browser right clicking and all of that so they only can manipulate this cookies can be manipulated via the browser only so good options to have maybe we can have a long discussion on this one later on all right now let's go ahead and send this one so overs dot status everything looks good in this case so we're going to go ahead and say 200 and then we'll say hey this time just like we have all these functions we have access to this cookie as well thanks to the cookie parser so we want to send that hey what do you want to send in the cookies first of all I want to send a cookie on token the name of the cookie is going to be token the value that is going to take is going to be token all right now once this is all done then we want to send this option options so all these options are being sent and once this is all done then I want to send a Json response yes you can still Trail down the Json option what all the data you want to send through the Json uh usually in the production grade you will see something like this so there is something like success always something like this is true or false or whatever the response is coming up and maybe you want to send the token as well oops maybe you want to send the token as well maybe somebody is making a mobile app he doesn't have access to this cookies so in that case sending the token so that front-end developer or mobile developer know what to do further maybe you want to send the user entirely as an object maybe you want to do something with that or maybe in just one call you want to send more data really it depends on what you really want to do you can actually go ahead and do that so this is all and by the way did I wrote it into wrong section yes I wrote everything into my register section really bad uh should be making a cut out of it and this was generating a token this was a cookie section so let's go ahead and grab this out cut this out my bad happens to every developer and we're going to login section and we have generated the token token was generated now let's send it up into the cookie actually this is yep send the token in the cookie so let's go ahead and paste it up here so yes this is Cookie section we are creating uh options and sending it up so it should be all good if we haven't made any error or something like that all right so this should look good and we should be able to get the datas and everything all of that nicely all right so this looks good as of now but we still need to test our code at least let's see if our code actually runs or not in this case uh so let's go ahead and say npm start to actually see if we have made any typos or something or database is getting connected or not yeah at least it is running so ah don't want to open it browser because if you open it up in the browser this is how it looks like as of now come on open it up and we have a long list of how this is being built and done all right so there we go so this is our app that is working as of now so let's go ahead and copy this now we can make some queries from the thunderclines everything in the browser love it that everything is happening in the browser make a new request and there we go we want to make a request to this URL paste it up a really long one and we want to send a request to register and we want to send some data in the body so Json data and we'll be sending just first name first name and that first name is going to be uh let's just say hitesh and let's see a post request and see what happens because we have created a post route send this and it says 4045 method not allowed so looks like a register method is let's see what all response we are getting get and we want to send a post data yeah that should be and headers should be all good uh definitely need a little bit of more testing to be done that how this all Json content we need to send or probably we need to use a postman so definitely let me do some debugging onto this one that hey why we are not getting response here again codes sandbox these code spaces is a little bit new so I need to check this out but at least we have actually understood what the code we have written here definitely we can debug it so no worries on that part so let me catch you up in the next video and let me figure out what is going on all and let's try some requests through the postman as well let's catch up in the next video
Info
Channel: Hitesh Choudhary
Views: 28,439
Rating: undefined out of 5
Keywords: javascript, devops, cloud, github, codespaces
Id: -8OEfGQPJ8c
Channel Id: undefined
Length: 39min 20sec (2360 seconds)
Published: Tue Nov 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.