How To Make Routes In NodeJS | Models in Node JS | Blog Application MERN-5 | Intellipaat

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone I am R makani and I welcome you all to fifth video under our mon tag blog project series and in this video I'll be helping you guys learn how to create routes in nodejs as well as how to create models in nodejs basically guys in this video we are going to complete the backend schema of our entire block project here now before we start this session I would request you guys to enable both the Subscribe button and the bell icon for our intellipath YouTube channel that being said let's get started so first of all we will start by importing few things uh just like we have done for our user so I'm copying all of this routes over here uh from our user to our commment J okay so let's just recheck once we have imported Express we have um used our router we have uh imported user from our models we have imported bcrypt we have imported post we have imported comments and verifi token Js from our verified token file Okay so so I guess this are all the files we need uh first of all whenever we are you know dealing about with the comment section so there are few things first uh you will be able to create a comment you can you will be able to comment on someone's post and uh you will be able to update that particular uh comment and uh you will be able to delete that particular comment from your your account but when you are looking at the third person's perspective let's say I am creating an account and you are commenting on my particular blog so you can edit delete and create okay and I only have rights to see that particular post right or let's say comment so the comment and the post uh will have the same kind of logic but uh when we are talking about the comment there are few options to update create and delete and the other one is to view so all the things all the functionalities will going to be see just that the post have some more extra features and extra type of data uh fetching okay so we will see that later when we will talk about how to create a post but um right now let's start by creating a comment so let's say create and U uh just like we have done in the previous video router. poost we are uh you know sending some data to the back end that's why we are using a post over here okay and U over here we will write create create is the Endo okay and uh we will also verify token first to comment on any uh post we have already done okay so for that we will be needing verify token and this operation will be a sync inside that we will have a request and response see I have already taught everything um every uh thing related to this in my previous video so if you haven't watched that video I highly recommend you guys to watch that particular video and then jump to this part okay so inside my try and cash block as I have mentioned that uh we use try and cash block whenever we are dealing with a back end and uh Tri block execute the code if it encounters any error it jumps to the cat block and inside cat block we handle the error okay so let's say response. send status s 500 dot Json error so till now everything is same what we have done in our previous videos okay now inside our create comment uh what are the things you guys think that will be uh needed over there so first of all we will create a you know we will pass the data inside our body whenever we are creating any comment okay and then we will save that particular part so uh there will be two operations first one is to create and another one is to save so let's do that first of all I'm creating one constant variable over here and in that I'm writing new comment comment like this is equal to new comment comment like this and inside that we will just request do body so we have passed this data in our body now we will save that particular data so let's say saved commment so you guys might be wondering why I'm writing this big names for my you know variables I can give short names as well but the thing is uh whenever I'm you know debugging my code it is very easy to debug this code why uh let's say your error is in save Saed let's say you have created a variable saved now you are wondering in which file I have created that particular saved variable and where the error is so instead of that writing uh saved comment will give you more idea whenever you are trying to debug so that's why I'm taking name as saved comment and uh uh in response we will set the status as 200 which is Success dot Json saved commment like this so we have completed our uh create now we will move to our update so let's give update over here let's say update now in case of update what are the things we need so whenever we are updating anything so first of all we will be needing that particular ID of the user or let's say IDE of anything ID of the post or something like that okay so inside that particular users account of that particular ID we will find that uh comment first and then we will give them the option to update it right so for that um here the case will be similar like when we are updating the users detail right if you remember if you don't let me just show you so um over here uh we are deleting the user huh this is the update user right so over here you can see that uh we have put request we have uh taken the ID verified to and inside that uh we are updating we are checking the password and we are updating the particular password if the password is updated in that case we are hashing the password again but in comment we we won't be uh using any hashing or salt or anything like that we just be needing this part okay so I hope this part was clear to you so that the comment section is more clear to you okay so here I'm writing uh a code for our update part so let's say router Router dop put and inside that we will take ID first so how we take ID back slash uh colon ID and uh over here we will write verify token again it will be a sync operation we will send request and response as a parameter and uh inside this again we will have a try and catch block catch will have error will throw error so response. status as 500 do Json error now inside our triy block what we will first do we will save that particular updated comment in one variable so let's create that first okay let's move piece by piece with this so let's update variable update comment sorry and uh here we will write comment do find by ID and update okay now in update we will write uh request do params do ID comma inside the curly braces I'm getting my uh set you know body so let's say first we have to request the body so this body is basically the already return comment okay and in another part we are giving new is equal to true now this code is going in Json format okay like this now after doing this much we will set a response do status 200 do Json updated Commander like this so uh let me just try and explain you what is happening over here so if you um we have created first our updated uh variable we have created a new variable inside that first we got the whatever uh was earlier return inside our body and then we have updated with the new thing okay and then we pass that particular thing inside our back end so this find by ID so it will find by ID and update whatever which is return return to it okay so with this we have completed our update part also let's move to delete so let's say delete tab now uh similarly uh the way we did for our user we will do for our um comment also so over here again we will be needing a ID so I have just uh you know accepted the auto suggestion over here and uh we also have this C okay now inside this the usual try and catch block this will have error and response dot set status 500. Json and inside that we will pass the error now inside a dry block what do you think we will be uh needing over here so what we will do first we will find the user by using its ID and then we will simply give the command to delete it so there is only uh one command you have to remember that is find by ID and delete that's it you don't have to do anything over here so first of all we will wait to get all the information then we will write comment dot find by ID and you can see this update option right now now we will write delete delete request Pam's ID that's it nothing else over here and over here we will write request uh response. status 200 Json and inside this we will write comment deleted now we have completed with our delete part also now we have to fetch all the commands for the third party user or for the same user also okay uh so over here uh I'm just writing get comment okay so let's first create our router. get now uh over here uh whenever we are you know fetching the particular comment so we want the comment of that particular post only so for that we will be using a post ID so let's say post slash colon post ID so whenever the user will be creating any post we will also send the post ID to it so this we will see in the model okay whenever we will be creating our models in that case we will see what are the you know things we need to uh add to our database okay and have to add that we will also see that now over here now try catch like this now let's say response. status 500 Json error now inside our Tri block what we will do we will create one Constant Comment variable is equal to a wait so this commment variable will contain all the comments okay so I'm just making it comments it will make more sense right a wait comment do find now what we need to find we need to find the post comments by using post ID so let's say post ID I guess P was Capital huh post ID right post ID column request perams post ID right now we will set our response do status as 20 200 and Json we will pass comments over there okay okay so we have completed our get comments as well now we will export this particular model so let's say model do export is equal to router like this so we have completed our Command JS as well now before moving to the Post uh let's first create one more folder which will store all the images which we are uploading inside our post uh or okay so over here inside my backend folder you can see I'm creating one more folder and I'm just creating an empty folder over here okay and naming it as images like this and you don't need to do anything inside that we will just move to our post now now similarly uh we will create our post GS right now I'm just closing this terminal I'm copying this whole code because we are not going to make major changes whenever we are creating the post so as I have mentioned the logic of post and comment is almost same when it comes to the database but when we will see the you know front end and the models the at that time you will see the major differences okay so I'm keeping everything as it is and I'm just making the changes so uh first one we are creating the post so for the creating the post uh I'm using the same uh route as a create verify token request response everything is going to be same and instead of this new comment I'm just making it as a new post okay as mentioned for the better you know debugging uh uh what happened okay first of all uh over here uh we going to need our new post first here and here it will be post not comment okay so let's just write as post like this over here again we will uh write new post like this and here it will be saved post and here again we will change the spelling as po post like this rest things will be same again here um over here inside our update so make sure you have made this changes there are very small changes this new post here it will be post and uh this will be saved post and in Json we will be uh writing save post okay and here it will be new post so that was the only changes in our uh create section similarly for update section we will just change wherever we have written the uh comment to the post okay so same the we will be needing the ID and everything it's just that the uh it's post not comment so over here also we will write post like this and uh let's just check the spelling it's B capital so we'll write P Capital over here like this here uh find in update everything will be same okay here it will be updated post let me just verify it uh whether we need to uh change anything else or not so first of all uh we have created one variable as update post and inside that we have um await post we have done that request parms by ID everything everything is same body new true everything is fine I guess um this should do okay okay now similarly we will do for the delete so inside delete first of all we will fetch whatever the data is so we will await for the Post over here then the data then we also have to delete all the comments which we are um getting on that particular post so for that we also have to delete the particular coms so here is the major change uh because if we are deleting the particular post we also have to delete the comments over there so let's say delete manyu so delete manyu is used to delete more than one things okay so let's say post ID like this uh here also P will be Capital like this and uh column request params ID like this uh and here we will pass post delete okay H this is good now similarly for the get post over here it will be post now whenever we are uh talking about the get post so there are uh few things to keep in mind first there will be some post details right then there will be all the post so you have to show all the post on your front page let's say we are showing all the post so for that uh we have to um pass that particular endpoint that is slash that is homepage uh where you will be able to see all the post you have created right and um then there will be a user particular post so let's say in my account I have created 10 post and I want to see what kind of post that I have created so so uh that post will be fetched using the user ID and then the particular post whatever we are looking for okay so there are three things first uh to Showcase all the post second with the whole detail inside a single post page and there will be user specific post so we will start by uh getting the post details okay so for getting the post details here I'm just keeping this as it is uh or you can uh just remove this because uh this we are going to change it so I'm just removing this part and over here I'm just writing get post detail details like this for that we will create a router do get and we will get using the ID obviously so let's say ID like this and a sync like this and uh over here we will request comma response and aror function try cach block these things are same only okay status 500 is some error now inside a tri block so um over here we will get the post details by its particular ID okay so um let's say inside our back end there will be so many uh post and there will be so many details so how can you get particular post detail by getting the ID right so for that I'm creating one variable as post this will store all the post details a wait post [Music] dot find by ID so find by ID and request parms ID okay now we will set the status as 200 like this Json over here we will pass the post okay so by doing this you can get all the post detail now get the all the post okay so for that I'm writing get post like this and uh for that uh the end point we will be creating is a homeage so for that uh creating one route and it will be the get operation because we are getting the post and uh Slash which represents our homepage or the main page the operation will be as sync obviously request response now inside this again try crash [Music] block now inside Tri block so um first of all um I need to find the post based on the filter also okay so there will be two types of filters first a search one and then some selected options will be given to you and you can uh select that particular option and filter your post accordingly okay so uh for that I'm creating one constant variable as a search filter now why I'm creating the search filter over here or the variable over here so that whatever the user is giving the data in the front end it will also I also have to pass that particular data to the back end to match that right so for that I'm going to use Rex okay uh you can also call it as a regular expression so uh you just need a basic regular expression knowledge over here okay so I'm using a Rex over here sorry okay I'm typing this again okay uh I'm using the basic rexs over here like this and um inside that we will pass the query query like this do search search comma options options and inside that we'll pass I now outside this uh search filter what I'm doing is I'm creating one more uh constant variable as post so this variable will store all the post which the search has returned okay a wait await post doind uh here it won't be by ID it's just a find and inside that we will pass that particular query which we have stored Okay so query do search question mark if it is present over there in that case red search filter call null if it is not we will return return null over here okay and in response we will set the status status as 200 and whatever the post we got we will pass that okay over here uh here we have created post so here creating posts okay so that it uh will be easier to resolve the errors now the last one uh user specific post so what do you think will be the logic for our user specific post so first of all we have to get the ID of that particular user and inside that particular user's ID how many post are created right so what we will do in case of the user we will uh also Al keep one column of the post so we don't have to do anything we just have to find the user by using the user ID and we will get the whole object of the post we have created okay so it's very simple uh let's try to uh achieve that let's say router. getet over here the end point will be user because we will already be using uh will be inside our user and uh inside user we will have us user ID and a sing operation send request and response response aror function try cach block response. status 500 error fine now inside this I'll create one constant variable of the post okay is equal to await post. find now on what basis we are finding the post on basis of our user ID so let's see user ID column request parents user ID like this now we will set our status as 200 S2 200. Json whatever the post we got we will pass that and with that we have completed our uh user uh sorry post route as well okay and we have already exported this particular route so I guess we are done with with all the routes now it's just we have to create the models for this particular routes so here uh for now for the instance I'm closing all the tabs which are open and we will just focus on the you know uh models and why I'm thinking that I have created this particular files inside my uh models instead of my routes okay so no worries about that I'm just uh dragging this particular file over here move and uh the post file as well I'm moving it over here I'll just say no for this one and I'll just rename so sorry okay here also I'm changing the uh file's name over here just making it to P post requireed models um okay now uh over here let's just uh check okay okay I guess everything is fine over here uh we just have to create two more files inside our model folder okay so I'm just closing this routes and I'm closing all of these particular uh tabs which are open so let's say close all and inside my model I'll be creating two more files okay so first of all it's post. JS again I'm creating this file inside my routes I don't want to do that I want to create that particular file inside my model so let's say post. JS like this and uh over here comments. JS like this so uh we have three uh models and we have to create this particular three models okay so um how can you create the models or what do you think will be there inside our models so models is nothing but a mongodb schema okay so what are the fields you want to store inside your particular schema and everything is written inside our model so it is very very very easy to uh write the models I'll show you how to do that first of all we will start by creating our users model okay so let's say uh const uh whenever we are Crea creating a model in that case we always have to use over here okay so let's import over here okay I don't really remember that we have installed the or not so to be sure let's install this again or whatever you what you can do is you can just move to our package loog Json and over here you will find all the dependencies so if I'll just go over here and find so over here you can see I have downloaded the so I don't have to redownload it okay fine good for us right now I'll close this package Jon so whenever you are uh not sure about the package you have installed or not let's say um you took 8 days to create this particular project or completing this particular series and you forgot that whether you have downloaded the particular module when I was teaching or not and uh you want to make sure of it you can directly go to our package log Json and there you will find all the dependencies returnable okay now um to create a user schema we will create one uh variable first and inside that we will create a user schema like this schema is equal to new dot schema schema like this and inside that we will pass our Json objects okay so uh first of all this will be our name of the object which is uh username and uh this are the functionalities or whatever you can say the what kind of user name will be so uh basically the usern name will be of a type string so we'll mention that so let's say string string the uh is it necessary to give the user name yes obviously it is necessary so we will write over here that required is equal to true now let's say uh the username should be unique um maybe maybe not so let's just make unique is equal to true in this case uh you can use false as well over here if you want I'm just making uh unique as true okay so if the username is getting repeated our website will not save that particular data or not able to you know it will not allow the user to go through the website okay Simply Now email inside email similarly it will be uh type string required and unique okay obviously the email address is going to be unique right no comments on that same we have password so let's say password password will be uh string because uh why I'm taking strings over here uh so that we can store digits and letters together inside our password okay so that's why I'm taking the passwords over here and uh last one will be bio you can skip this part if you want but I I'm keeping it it's completely your choice okay so if you want to add functionality of getting the bio you can do that and uh password I haven't given unique over here because uh maybe two people can have the same passwords right two people can share the same kind of password let's say my password is 1 2 3 4 and your password is also 1 2 3 4 so in that case my password is not unique my password is required only okay now after doing this much I also want to get the time stamp of the user particular user when they have created the particular account so let's say time stamp time stamp U is equal to true just true I want the whole time stamp okay now after doing this much we will export this particular module so let's say module. export and over here we will write do model model and over here we will pass user user comma user schema like this so this is how you can export your particular schema I guess now you know how to create your schemas and everything right uh why this is showing that the values is never read uh have I make any mistake have I make any mistakes okay let me just copy this particular part and I'll just paste that over here instead of this okay still it is showing uh it's unused I guess uh there are no errors over here but it is just showing uh that the user schema is not defined if it does not work we will debug is later but right now let's just create our post. JS and uh in our post. JS what are the fills do you think that we will be needing so first of the first of all obviously uh we have to give a title uh just like the name so let's create a post schema over here schema like this and uh over here we will write new do schema like this and inside this first of all we will give the title then there will be some description then there will be photo a username user ID and categories okay and obviously the time stamp so um everything is just similar uh just that the you know the headings or you can say the name of the objects are different from the previous one okay uh call uh I'm just copying this particular part okay like this to here okay so I don't want any two blogs with the same title that's why I have given unique over here you can avoid that as well if you want and uh I'm creating uh DC for my description uh like this colon object and inside that I'm giving uh type string required true unique true okay everything is true now similarly we will have the photo over here photo like this and uh over here inside photo now inside photo uh the type will be string uh required yes photo is required and uh photo should be unique not necessary people can use the same photos for my particular blog okay now uh username name is required not necessary be to unique now there will be user ID why I am taking username and user ID because I want to uh you know organize my post in that such a way that uh the particular user can see his or her own post okay so that's why I'm uh mentioning the username whenever I'm storing the data inside my back end I'm storing my uh you know user ID and username everything inside my back along with the post so that's why I'm uh taking the username over here also the user ID let's use user ID so uh we have seen how to filter the post right uh over there we have used this particular user ID let's say type will be string and required will be true now after the user ID there will be categories so there will be certain categories of uh blogs we have already seen when we have U seen the demo and if you don't know uh what we have created in the demo I suggest you all to uh watch our first video of this particular series and you will get the idea how beautiful product we are going to create now inside categories the type of the category will be array why array if you will ask me then uh let's say I'm creating one blog of U on basis of um mon stack development let's say okay and that particular mon stack development blog will also belong to the full stack development right that will also belong to the react that will also belong to the um nodejs as well right so that's why I'm taking multiple categories on one block okay so we will give the option to select the particular categories as well but uh that's why I'm creating the uh you know type as array and over here we will store the time stamps as well so let a time stamp time stamp and we will make this as a true just like we did earlier now after doing this much uh we will export this so let's say module module do export is equal to Mango do model over here we will first take posts post after that post Gema see over here it didn't give that the post is not used and everything okay post is declared but not used but I don't know why in case of the user they're giving that the um user is not declared I don't know it may be some glitch or something uh which is happening over here otherwise we have written the same thing inside our comment as well in the post as well okay now um okay I have by mistake return comment inside the post okay so let's say uh let's copy let's cut this and paste it inside post fine now last Model we have to create is comment so I'm just closing this down because I'm missing with the code okay so as usual first we will import our so let's say cons see uh whenever you are coding it's okay to make you know small errors here and there okay it happens with me all the time when I'm uh coding when I was creating this particular project at that time also sometimes we write the you know wrong logic or you can say inefficient Logics it happens but um you know coding skills come with the practice so let's say you were creating some project and you fail at completing that particular project it's not important that you feel it's what important is you try to create that particular project and the most important part is you will try creating react projects and there will be some point you just want to give up on it just don't do that because whenever uh we are starting with any coding uh let's say any kind of coding let's say it's a competitive coding or uh web development anything you will always face some challenges and then you will always feel like giving up but trust me guys don't give up on this you know um when I get the most happy about all of this when my you know code runs successfully and it actually makes an impact so just don't give up on it now inside our comment schema let's start by creating a comment so what kind of uh data should com and hold comment will hold U whatever the comment we are typing so let's say I'm just copying this particular part because I don't want to write this again and again okay it's okay to copy paste though whenever you're coding but not the whole code come on now uh first one we will have a comment then we will have author of that particular uh comment so let's give author over here author will be required not unique now comment will be um having two more things which will be post ID and user ID so post ID of the particular uh post the you know third person is commenting on and the user ID of that particular person who is commenting okay so um this author will have the ID of the person who has created Creed the post post ID is the ID of that particular post and user ID is the ID of that particular user who is commenting on it okay so I hope this schema is clear to you I know this sounds bit confusing but I guess it's not that difficult to understand as well okay uh post ID will be uh string and required okay similarly I have user ID that two will be uh string and required again we will have the time stamps over here so we'll give time stamps true after this we will export this so let's say module do exports is equal to what happened do model comment comment schema you can see this Auto suggestion coming up over here okay like this so uh with that we have completed our models as well so so uh now the only thing left is to add this particular uh models and routes inside our index.js so right now if you will uh run this this particular part won't work whenever you will add this particular file inside your index.js then and then only it will work why so because whenever we are hitting npm Run start it's only firing our index.js so if you want to try that I can show you that as well so let me just open my terminal so let's see new terminal and over here I'm already running my back end so if I just close this particular back end and if I rerun this particular code so let's say npm Run start and over here you can see my node one is starting node one started index.js app is running on P 8 8,000 and database is connected so if I'll just move to my browser let's say I'm getting this ID and let's say Local Host 3,000 and I'll move to the 8,000 from here only see on 8,000 like this okay so it shows cannot get fine we haven't written anything nothing to get now what do you think if I'll just write post over here it will show me any post no because there is nothing to show why there is nothing to show because we haven't returned this particular code inside our index.js so to make this run we have to write that particular um code inside are index.js so if I'll just uh complete my code inside my index.js in this page you will see the blank page you want get this cannot get message as well why because we haven't created any post nothing to show so none I hope this is clear to you now let's move ahead and uh complete our index.js and with that we will be completing our whole back in So inside of my index.js is uh there are few things we have to create over here okay starting with the middle wees so what are the middle Wares middle Wares is nothing they just you know um handles our request and response so let's do that so whenever we are creating uh you know middle wees we basically uh do it with the uh config and everything okay so over here I'm just mentioning middleware middleware and over here we will be writing the code so right now I'm just uh killing the terminal closing it and uh uh over here we will uh start by using this particular image folder so that we can um upload image or get the image or to get the path of that particular image so um let's first do that and uh now uh let's write app. use path of that particular folder my folder is right inside my backend folder so index.js is also inside my backend folder so that's why I'm just writing slash images you can see over here express. static now we will get the path and we will join that particular path what happened path. join what is happening okay path do uh let me just write the whole thing okay path do join then uh we will give the directory name over here so underscore D name Tab and I'm removing this particular part and I'm giving uh back slash images and this won't be add this will be comma over here images like this now we will also log course like this now after that uh we will pass all the authentication uh over here okay so let's say app. use and to do that we will use cookie passer okay now we will add all the routes so let's say app. use first one will be let's say API SL comma a like this now I'm just copying this particular uh part okay so in my keyboard uh control D is to copy the line where my cursor is okay so you can also set up this particular shortcuts when um uh you are working with the vs code you can just directly go to the settings and from here uh you can see this U keyboard shortcuts and from here you can uh change your keyboard shortcuts okay so right now let's uh move ahead uh instead of this oath I'm making user as my another endpoint so let's say users then I have the post post like this and then I have the comment coms like this now after this uh I also have to change this particular part so this will be user route then this will be my post route and this will be my comments route now after this uh I'll write the logic to upload a image so let's say im G now we are uploading this particular image inside our folder which is present inside my uh dis storage right so for that let's say constate storage is equal to remember we talked about the molter in our um two videos back whenever we were setting this particular um backend environment so we will be using MTA to upload a image and to get the image okay so let's say destination and over here we will make our uh request response call so request comma file file comma F so you can directly copy paste this particular code from our multer um documentation as well but I'm just uh choosing to write this particular code and this is the similar code which is present over there okay so you can refer this particular that particular code as well if you want you can also refer the documentation so let's say file Name colon request comma file comma FN so inside the body we will be passing uh our whatever the image we got okay so in the body I'm passing this particular image now this is how we get the image now we have to upload that particular image as well right so we have stored our image inside our storage named variable now we have to upload this particular image so we can upload the image using the molter again so let's say const upload is equal to molter and over over here we will use our storage call and storage like this and over here we will write app. poost now we have to send this to backend so that's why we have to write API SL upload so this particular API so whenever we will be uh throwing this particular API the uploading process will get started so when we can upload this particular um image when we have stored that particular image inside our storage named variable right so uh if you directly write slash upload so this will not work because we don't have stored any kind of images over there single and over here we will write file comma why single because I want only one image per post request response now response do status 200 do Json image up load successfully image uploaded successfully okay all right so I guess we are done with our back end I don't think anything is uh remaining we have created all the odds we have uh created all the end points and we have seen how to you know create the particular backend so if you want to test this particular API we can test this API inside our Postman tool so let's move ahead and try to test this particular apis which we have just created so I'm just launching my Postman over here and again if you don't have Postman you can uh get the postman by downloading it I have shown you from where to from where to download the postman so I'm opening my terminal again and I'm running my particular uh you know backend service so that my API starts running okay you can see uh it says the server is crashing because there is no path. join okay okay let's let's resolve this particular error so this error is coming over here let's see what's wrong with it so it says path. join images and uh express. static okay it's not path. Json it's path. join see that's why I don't trust uh more on this Auto suggestions again it's uh giving me an error why okay let's try to resolve this okay there is some uh error over here path is not defined it says path is not defined didn't we Define the path we didn't so we have to define the path over here we have to say const path requireed path like this now we also have not imported our you know cookie pars and everything so I completely forgot to do that let's do that so let's say const cookie parcer is equal to require cookie parer and we also have to download this particular uh things also okay we haven't done that so we will do that and uh we will have Au route route is equal to require is equal to require back slash uh from our routes slash o for our o route s sarly I'm just copying this three more times and over here we will have user route route slash user over here user over here then we have comment or you can say post and here it will be post over here it will be comment comment route and uh I'm removing this particular out from here and this will be comment like this so um I guess we have um got all the routes right okay so we have to install the cookie parser and the path okay let's do that so I'm just closing this particular terminal you can see see uh it is still giving the error because the module is not found you can see over here uh cook parer is not found Let's uh get the cook password okay so I'm just opening another terminal CD backen and BM cookie password see it's still not finding some uh modules with module. comand where route user .js so inside this particular route uh this will be small C it cannot find comment. JS why it cannot find comment. JS let's say comments. JS fine SL SL verify to again it's crashing what's wrong have we exported our uh models in comment. JS yes we did exported this okay okay so where it cannot find it cannot find inside a post post. JS this post. JS okay I cannot find comment model okay let's change this slash the comment. JS fine now now tell me now give me the error I'll solve uh cancel I'll just write RS over here to restart the server okay okay it's again giving me the error what is the error over here again again now uh inside my comment. Js it cannot find the comment I don't know why I'm getting this error because everything I have return is same only okay so I have made the spelling mistake when I was writing uh the comments earlier and it was not able to find that particular folder okay okay so every I have to make the changes so let's do that it's okay we will do it inside my routes comment. JS I have just resolve that particular error okay this is creating error now you can see uh my server is running on 48,000 databases connected successfully and and with that we have successfully completed all of our backend functionalities and I don't think there is any left uh inside our backend part uh we will also test this particular API when we will create the front end and we will uh make the connection of our front end uh with backend and we will also uh test all the apis using Postman as well as uh using our front end application as well so in next video uh we will see how to create our frontend functionalities and uh we will see how to to create our components how to uh you know um connect our backend with front end and everything in our upcoming videos we have already uh created our few components um and we have already created um structure for our particular application and in next video we will be completing the components and pages and we will be adding lot more functionalities and we will be creating exciting UI so for that keep following this particular playlist and I'll see you guys with the next tutorial till then keep coding T bye-bye just a quick info guys intellipath offers a fulltech developer course which enable you to learn textech from both front end and backend through this course you will gain handsone experience with the skills and Technologies such as SQL Java data structure JavaScript HTML CSS nodejs and react under the guidance of industrial professionals with this course we have already help thousands of professional in successful career transition you can check out the testimonial on our Achievers Channel whose link is given in the description below without a doubt this course can set your careers to New Height so visit the course page link given in the description and take the first step towards the career growth with the fullstack developer course
Info
Channel: Intellipaat
Views: 8,004
Rating: undefined out of 5
Keywords: How To Make Routes In NodeJS, Models In Node JS, Blog Application MERN, MERN Stack, Routes in NodeJS Express, Node JS Modules, Multer Node JS File Upload, Multer Image Upload Node JS, Comment. API Node JS, Cookie Parser In Node JS, MERN Stack Blog, MERN Stack Blog Project, MERN Stack Application, MERN Stack Project, MongoDB, React, Express, Node JS, Database in MongoDB, MongoDB Schema Module, JavaScript, MERN Stack App, MERN Stak Tutorial, MERN Project Tutorial, Intellipaat
Id: Ql__w3_rMW0
Channel Id: undefined
Length: 66min 58sec (4018 seconds)
Published: Tue Feb 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.