Node.js Social Media REST API with MongoDb

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

this application looks good hope i learn alot

👍︎︎ 1 👤︎︎ u/Hour_Cauliflower_693 📅︎︎ Apr 07 2021 🗫︎ replies
Captions
hello my friends today we are gonna be building node.js social media application rest api and in the next tutorial we will build this react application and we are gonna use this awesome api and also we will be using mongodb we will create update and delete our own collections and the documents in the api we are going to create register and login authentication and then for user's router we will write update delayed and get methods we will be able to follow and unfollow any users and after that we will create posts update and delete them and like or dislike any post and finally we are gonna fetch all timeline posts according to following users for now it's gonna lack custom error handling or jwt authorization we will cover all these features in the next tutorials if you want to improve your express and mongodb rest api skills it's gonna be really useful for you so if you're ready let's get started okay firstly i'm gonna initialize my note application i will write here npm and init it's gonna ask me some questions about this application i will just enter all of this and it's ready firstly i'm gonna add some libraries here that we will use in our rest api so i will come here yarn or if you are using npm you can write npm install i'm gonna use yarn and add express mongoose and dot enb helmet morgan and nordmon let's create them and i will explain why we are using them and express as you know it's the node.js framework we are gonna build our application on this framework so basically our server will run on this express second is mongoose it helps us to create our models that we can create our documents inside mongodb like users posts or whatever and third one will be dot emv after creating mongodb it's gonna give us some secret url which includes our database server name and our username and password so if you use it directly someone can steal it and use for his purpose so we have to hide it somewhere in save so not only that url any keys any secret keys and any passwords you can keep inside this emv file and next one is helmet when we start making requests to server it's gonna help us to stay secure because when you make requests the request header carries some vulnerable properties inside it so helmet prevents some of them and adds some new properties for extra security a morgan is a request logging middleware whenever you make a request to server it's going to return us which request has been made what was the result and how long it took so we can see our results in our console here so next one is notmon when you create a node application whenever you make a change inside of any or files here you have to come to console and say restart all the time so nodemon allows us to start server once and anytime we change something inside our application it's gonna refresh the application so it's kinda listening our files here so here we are not gonna use any test i will say start use nodemon i will come here and say nodemon and our main file which is index.js we don't have any file here let's create okay i will close here and this one so we can create our express here const express and it's gonna require express okay and after that we can create our application and express that's all so how i'm gonna use this application i will say app.listen i can indicate here any specific port i will say 8800 it's gonna be our port and after that i will just console lock this and i will say back-end server is ready or is running let's try you can write here npm or if you are using yarn like me start and as you can see back-end server is running perfect if i make any changes inside this file or any other files let's save as you can see node 1 refresh this page again so i'm going to add other libraries here mongoose.me and matt and morgan to use dot emv i should come here and say config so it's ready to use i will create here my emv file dot eme and inside this we can write any secret keys here okay let's close them and here this is my mongodb cluster you can create quickly through this address it's totally free and right here i will say connect and choose connection method and here you can use shell or this application or you can manage this in your code as we will do i will choose this and this one will be our secret url i will come here and inside url and here you should write your username and password and here it's gonna be our database social i will write here my name and password and we will continue and after that i will go to documentation of this mongoose and for connection i will just copy this and paste here and it's gonna be our secret url so i will say process and eme and our secret k name and url and after that i will create just a function and it's gonna console.log our connection connect it to let's see back and so of course it's server there's an error here it wants to add this one also to our connection let's see right now apps so we created our application and we created our mongodb connection after that i can write my middlewares let's close this and i will also make this a little bit bigger okay and underneath i will say app.use firstly i'm gonna use express dot json it's a body parser when you make post request it's just gonna password it so after that i'm gonna use helmet and after that morgan you have some options here you can check the morgan documentation but i'm just gonna use common one so if you are not familiar with express and node.js and and you don't know what the middleware is how to use them you can check description below because it's gonna be quick tutorial i'm not gonna explain everything from scratch so let's try our application i will say get and for home page for example i will create some function here and say of course inside our request and response response and json or send welcome to home page okay let's try our port is 88 i will come here and say localhost and here as you can see welcome to home pages here if i change here let's say for example users let's separate them users welcome to user page if i write here users perfect and by the way morgan is working like that your date and request type and address and status and this is our duration of the response so everything is under control here and of course we are creating rest api so we are not going to use them and instead we are gonna create our roots here so let's create folder and it's gonna be roots and inside this let's create first users.js to create router i will say const and router and require express of course in code and after that i will write here router to use it in the index file i should export it i will say module and exports and it's gonna be router so i can use this here let's say here const user root it's going to be our path root and users so i can use this after this middlewares i will say app.use and it's going to be our address for rest api let's say api and users so whenever we go to this address it's going to run this router let's say user root so let's try here i will say router dot get and for the home page of user api request and response and it's gonna send us hey it's user roots okay let's try our api first and users i forgot something again here it should be users so refresh again hey it's user root have some so we are gonna do all our user things inside this router it's gonna be delayed user update user get one get whole users or something like that so i can use create and login users here also but i prefer using another router it's gonna be all dot js and i will just copy this and here and i will change here and in index file i will just call this one and here it's gonna be singular and after that i will call this here let's try okay awesome so let's create our models here i will create new folder here models and inside first one will be user.js i'm gonna call our mongoose here and require bongos firstly we are gonna build our user schema and it's gonna new mongoose dot schema and inside this we are gonna create our properties first one will be username and type will be string and you can indicate here any restriction for example require it's gonna be true because it has to be a username for a user and after that minimum 3 characters for this name and maximum let's say 20 and it should be unique because i don't want my same username for any other user and after that i will create email and it's gonna be type string again and required and max let's say 50 and it should be unique again let's create password type string and required and minimum minimum character will be six and maximum let's don't write maximum okay and after that it's gonna be a profile picture and type string and when we create a user it's gonna be default value and i can write here default and it's going to be empty string here i will do the same thing for the cover picture they are not required here but when we create new one it's going to be empty image here so i can add here followers and followings type will be array because we are gonna keep user ids inside this array for example five people are following you and they are their user id when they follow you we are gonna add any numbers inside this array like this so by default it's gonna be empty again i will say empty array so i will do the same thing for following people and what else i can say is admin type will be boolen and by default it's gonna be false when we create a new user it's not gonna be admin it's gonna be a false okay so to use this user schema i should export it and i'm gonna use it inside users and out also so i will come here a module and exports and mongoose.model and inside this i will write here model name user and after that it's gonna be our user schema so i wanna create here timestamps whenever you create a user or update this it's gonna automatically update our timestamps timestamps and it's gonna be true comma here okay so we finished our first model here so let's go to alt js and try this so i will come here and say register and inside in statcat i will say post and here register so i want to use this user model here const user and require modules and user okay we are gonna take information from client side but before this i can write here const user and it's gonna be new user this model and inside this i will write my properties username let's say john and email john gmail.com and password one two three four five six and after that i will save this user i can write here get to use browser but before checking there is one more important thing this process is an async function so i should come here and say async and this one should be await if you don't know async and await or a secret news functions i'm gonna create tutorial for this you can check in the description below so after this it should be await also because it's writing in the database here and after this i will just say res and send let's say okay for now it's just for test it's not real word example for now let's try right now i will say register okay and here i will check my collection as you can see our user is here and profile is empty cover followers and followings are empty awesome so we are gonna use this it should be post we are gonna send our users edit as a request so after that i'm gonna use postman it's an awesome application for making requests for your application so i'm gonna create here new collection let's rename it it's gonna be social and inside this i'm gonna add a request i will say here register user or create user and it's gonna be post and here i'm gonna write my localhost our address here and as you can see there is buddy here we are gonna send our user from this body i will choose here raw and it's gonna be json and here i'm gonna add my user username let's say jane and email chain at gmail.com and password it will be one two three four five six i can't send this right now because we didn't write anything inside so i will write here const new user so it's gonna be new user and here i'm gonna use this request and in request inside body we defined our properties here and for user name it's gonna be request and body and inside this username and for the email and password and after that when you use async and wait you should write your try and catch block because if any error occurs this catch block will catch it and after we can use any error handler or just print this in the console let's do this first i will say const user and await name user and save and for catch our error here just console.log this error and after that so i will say response and status it's going to be 200 which is successful and after let's say sand or json this user let's try let's try as you can see status 200 and here it turns our user let's check in the mongodb i will refresh this and right now jane is here also awesome but our password is jane also there is a mistake here because i forgot changing this name it's gonna be a password but there is still problem because we can see these passwords here we shouldn't expose any passwords anywhere so what i'm gonna do is i'm gonna add some other library here and add and decrypt it's gonna allow us to change our password into some random gibberish code so even if we see here this code we can't decode it and we can see the actual password so let's come here and call this pcrypt const be crypt and it's gonna be decrypt it's a synchronous function also so i'm gonna write this inside here so firstly i'm gonna generate a salt and after i will hash our actual password what i mean by that const salt is gonna be a weight and be crypt and i will say genesalt let's say 10 you can change here and after that const hashed password and it's gonna be await again pcrypt and hash and inside it's gonna be our password which is request body and password and after that i'm gonna use this salt so i generated new password here i can't use it here because it's about hash password here so i will just move this here inside try catch after that let's write here generate new password and here create new user and here save user and return response or just response or just respond okay let's try right now let's change them hey and here and i will send it's successful let's check here john jane and right now as you can see username hey and our password is called here awesome right now our password is safe okay but there is some error here the application warning it happens because of our mongoose here this version so if you decrease this version you can get rid of this error it's nothing that important it's not crucial so i'm gonna just ignore this okay let's kill this one we are not going to use this terminal okay so we can register with a user so after that i can write here login router it's going to be post again and right now it's going to be login i will close this and here it's going to be a request and response again and after that let's come to postman and here i'm going to create new one add request and it's gonna be login i will just copy this and paste here and right now it's gonna be login so what i'm gonna pass here i will say again row and json and for login process we are gonna ask user to enter his email and password hey gmail.com okay it's correct and here our password it was one two three four five six okay we are gonna use this one of course it's gonna be post again so i'm gonna try to find this user here to do that i will use const user and await and here async of course i will use this model and i will say find one because it's only one document inside in same name so i'm gonna pass my object here email and it's gonna be request and body and email i will say here if there is no user like that i'm gonna say res dot status i will say 404 which means not found status and i will say send usually not one of course it should be inside try and catch block and catch i will say error that's console.log and i forgot writing here slash let's try and see i will change this email name and i will send and as you can see 404 let's check user not font house what i'm gonna do is checking this time this password i will say here const wallet password and it's gonna be await and right now i'm gonna use another function of this precrypt i will say compare we are gonna compare this request body password and actual password inside this database so what i'm gonna compare i will say request body and password and i will compare this with user dot password if password is not valid i will send again response that is right now it's gonna be 400 because wrong password and here json let's say wrong password let's try it again right now it's gonna be correct and this is gonna be wrong password i will send and for under pad request and inside this wrong password helps so after all of that if the user enters the wallet email and password it's gonna send status 200 and it's gonna send our user to us json user let's try right now i will make it correct also and right now as you can see it turned back to our user so we completed our login process also of course we should validate these inputs first because for example if i delete this or this password if i click to send it's still gonna send this request and it's gonna turn user not found and also we don't have any custom error handler also we are just writing here arrows but i'm not gonna deep dive into everything we can validate them in the client section it's just a couple of lines in html but instead console.log i can send this as a response i can say it starts is 500 and json [Music] maybe this error and also here okay so in the user root i'm gonna add some request titles here and we will take care of them first will be update user and second will be the late user get a user get all users actually in real world social media application we don't need them we never get all users so i can say follow a user and unfollow and also i will go to user model and i will add some additional information here and after is admin i will say description and it's going to be type string and maximum let's say 50. and after that i will add some city informations it can be currency or just city and type string and again max 50 and i will save from it's gonna be hometown's t and after that it's gonna be relationship and it's gonna be type number and i will give some options here and user can just use one two or three i will say enum and one two three one can be single maybe merit or complicated or something like that actually the better idea is creating info model here and write them inside this one but i don't want to make this tutorial that much long and inside users table it's perfectly okay for now in the future we're gonna build really huge application it's gonna take around maybe 10 hours or more so we'll build everything in depth detail so stay tuned and for now let's go to the user i will just close this one and out also okay for update i will say router and it's gonna be put because it's updating process and i will say slash and id it's gonna allow us to choose any id numbers here any user ids for example when i write here for example one two three it's gonna be a user id and i can use here whatever i want and i will say again inside async and it's gonna be request and response firstly i'm gonna verify if the user id doesn't match with this id we are gonna return some error so i will say if i say request body and it's going to be user id when we send this request we are going to write here user id and we will try to match with this id if they match it means it's the same user otherwise the user can't update or delete any other user's account so i will say if equals request and params and id which means this id this is a parameter and also i will check whether it's admin or not i will say a user and is admin so i will write my processes here so if not i will say else and i'm gonna return some error here response status and it's going to be 401 or 3 and i will say json and i will send you can update on your account okay so what i'm gonna write here let's check here a user can update any informations here but if you remember we have password issue here so i will check this if request embody and password if user try to update password i'm gonna try and generate this password again const salt and await and it's going to be 10 of course we should just call this conspicrypt okay and after that i will update my request it's gonna be body and password and i will say await pick crypt and hash i'm gonna hash this password first and here our salt okay we send some password inside this body in postman and we are going to generate new password and hash and we will update this request buddy and password okay let's say catch and error i will just return this of course i can give some status it's gonna be 500 again okay okay we completed this password and after that i will update my actual user i will say try again and const user and await i will call my user and here i will say find by id and update and i will give my user id requests params and id or request body and user id doesn't matter okay we found our user here and after that what i'm gonna do is set request and body [Music] so it's gonna automatically set all inputs inside this body and after that i will say status it's gonna be successful and after that let's say json and account has been updated and of course i will catch here and i will send this error also okay let's try our user collection is empty so let's create new one i will come to register and send let's check here okay it's here so i'm gonna update this i will just take this user id and i will create new request here it's gonna be put and i will rename this also [Music] it's gonna be users and user id i will come to body and row and i will choose json here so let's try to update something inside i can update one of them here that's a description hey it's my updated description and after that i will indicate my user id and it's gonna be same let's check account has been updated let's check in mongodb here okay perfect if i update my password let's try okay it's successful here and inside this as you can see it's hashtagging perfect i will make this bigger also okay it's better so let's do for the latin process i will say actually i can copy this and we can edit some points i will say copy and paste here okay this time it's gonna be delayed and again id it's gonna check the user if it's not we will send you can delete on your account and after that you don't need any password process here and here i will say delayed1 and it's going to be our user id and here account has been deleted successfully let's check here i will create new one and it's going to be delayed user [Music] and inside body i will choose row and json so i will write here user id if i send here something wrong i will say send nothing happened let's check here cannot read property is admin oh i set here request user it's gonna be body for update also okay let's try right now i will send again and it's gonna turn you can delete only your account perfect so if i write here this user id there is an error again let's check delayed1 as you can see we just write your user id but we didn't say anything delayed by id or something so we should indicate here our user id so it's gonna be id and is there any function like that play it by id or not yeah find by id and delete so we can just turn back to previous version let's try again account has been deleted perfect let's check here okay we don't have any results here so let's make request for getting a user i will say router and it's gonna be get and again slash and id async request and response and it's going to be try and catch block i will send my error here and inside this i will say const user and my model here and find by id and it's going to be our parameter and id of course it's going to be a weight if we can find any user here we are going to just turn this back i will say response and status will be 200 successful and i will say json and it's gonna turn us this user let's register first okay this is our user let's take here our user id this one and i will create new request it's gonna be this address and i will change here if i say send okay we have user but there's a problem here because we have all properties of this user for example password or is admin for example update we don't need them so we can choose some of them so how i'm gonna do that i will come here and before this sending response i will say const and i will create an object these unnecessary properties i will say password maybe updated it okay that's enough i will say others i will just spread other properties here and here i will say user and document this document basically carries our whole object here this one so what i'm gonna do is sending this other i will not use password or updated ad let's try i will say send and right now as you can see there is no password there is no update to that after so let's follow some user here router is gonna be put because we are gonna update some lists inside this user i will say id again and slash follow async and request response so i want to verify something here i will say request embody and user id if it equals this parameter id request and params and id so it means they are same user so let's make here not so i will say as and if it's same user i will say response and status 403 and i will send this error i will say you can't follow yourself and here i will write try catch block response and status it's going to be 500 and json this error so i'm gonna find user which has this id i will say const a user await and i will find this user dot find by id and it's gonna be request and params and id and also i will find this current user and it's going to be body and user id so i'm gonna control something here i will say if the user and followers and i will say includes request body and user id if the user which we are trying to follow already includes this current user as a follower i will turn some other error here press and send but before status 403 i'm not sure it's correct status code or 401 is better let's check access to requested sources forbidden oh it's okay i think so i will say json you already follow so if it's not i will update this user and this current user also i will say await and user and update one so what i'm gonna do is saying here push because we are gonna push some ids inside followers and then followers and what i'm gonna push inside these followers it's gonna be request and body and user id so i'm gonna do the same thing for current user and this time it's not gonna follow us it's gonna have followings and after that i will just send this user has been followed so what we exactly did here firstly we checked whether these users are same if they are same we are just gonna send this error you can follow yourself and after that we found this user which has this id and also current user which is trying to make request and after that if the current user is not following this user we just said update these followers and followings arrays let's try to try that i should create another user here let's make zoom out here okay it's better let's say john that's great okay this is going to be our current user let's take this id here i will create new request it's gonna be put users user id and follow i will choose row and json here i will give my user id and inside oh we deleted all users here before so i'm gonna create second one let's say jane okay let's take this id also and here i will just paste here okay this is john and this is jane let's try user has been followed let's try here i will refresh oh sorry it's here it just didn't refresh but anyway okay john is here let's check followings because we follow jane okay followers are here but there is a silly mistake here as you can see let's go to model not followings followings okay i will just edit them okay and here it's gonna be followings and also i will delete inside these followers because we are gonna add again let's update okay they are correct right now and empty and i will send again let's refresh and for john i'm checking followings okay it's our id we made another three mistakes and here i'm gonna add not user id params and id so i will delete again so i'm gonna try last time i hope everything will be okay let's refresh okay it's chain and here followers it's okay it's done perfect so for unfollowing i will just copy this and paste after this and right now it's gonna be unfollow i'm gonna change something here you already unfollow okay it's not the best sentence but anyway i will say unfollowed okay maybe i can say don't follow and right now i'm not gonna push i'm just gonna pull from this followers and followings array and here it's not gonna be in that if this user includes this id this block will be run let's save it and try here this time it's gonna be unfollow and send user has been enveloped and here i will refresh and right now it's empty and for jane it's empty now so so we completed our user requests let's close this and create some other model here okay i will copy this and inside models i will create post dot js and i will just paste it and it's gonna be not user it's going to be paused and here post schema and inside this i will delete them okay first one will be user id type will be string and it's gonna be required and after that i will add description type string and it's going to be max 500 characters and we can add some image string and after that i will create some array for likes type array and default will be empty array and here i will just close this curly parenthesis and comma okay it's ready i think user id description or image and it's gonna be default likes let's add this inside index but before we should create roots it's going to be post js i will call this router and after that i will just export this okay i can write right now i will come here and say post route it's gonna be posts and here it's gonna be paused okay let's try router and i will say get for the home page request response and i will say just console.log post page i can try on the browser and enter post page okay it works i can close this and i will delete this here and i will write my titles here create a post update and here it's gonna be delayed and like a post get a post and get all posts but it's not gonna call all posts it's just gonna get all posts of the user's followings let's say here timeline and here basically we will just call all followings of the user and then all posts of these users okay let's create i will say router it's gonna be post request response course is gonna be async function i will say const new post i will call this post model i should call it here of course const post and it's gonna be require models and post okay i will say new post and inside this post i will just say request and body so let's write here try catch press dot status it's gonna be 500 and json let's say error and inside this i'm gonna create new one so cons saved post it's gonna be await and i'm gonna save this new one and after that i'm gonna turn this as a response and status will be 200 and json i will just send this post okay let's try by the way we didn't give any name for them i will say get user and save and this one will be follow and i will just duplicate this it's gonna be unfollow user and here the address will be unfollow okay let's save and after that i will create new post request here create new post or just post and it's gonna be paused okay so inside this body i will say json and here i will write my user id we will find this later and here description hey it's my first post and after that we can add some image or we can just leave this empty it's going to be only description so let's check here it will be jane i will copy this and let's send so as you can see our post is here let's check in the mongodb i will just refresh and we will choose post here apps i will just open this in new top and here for users let's choose this john from john and after that i will add some image image dot png and send okay perfect it's from jane and it's from john and for the update i will say router and put and as always request response and after that and it should be post id of course so i will verify this user again to do that i will find this post of course async here and i will say cons post and post find by id it's gonna be this id request and params and id and after that we are gonna check the owner of this post i will say if post dot user id equals request and body and our user id [Music] if it's the same so we can update this if it's not i will just turn some error and json i will say you can update only your post and of course i should put this into try catch and json error should be a weight okay so it's gonna check this post so even if there is no post like this it's gonna turn 500 it should be 404 so we can write here with that is and 404 and post not found but anyway we have error here i will not handle all these errors we are gonna handle all these errors later so inside this i will say await and post and update one and i will set inside this body and after that i will send this [Music] the post has been updated okay i will create new one i will just copy this update post and here it's gonna be put i'm gonna check this first one it's our post id and here inside body i will choose row and json and here i will write user id and it's gonna be john's id and here i will change this description let's try has been updated 200 and here perfect if i write here wrong user id it's gonna say you can update only your post have so so i will copy this and for the delayed i will paste it's going to be delayed and everything is same and here i will say to late one and here delete it and delete okay i will come here choose delayed and for the wrong user id it's gonna send some error if i write here correct one it's gonna delay i will check here perfect we delete it right now we are gonna like some post here i will say router and it's going to be put again and post id and after that i will say like and i'm gonna find this post again await and post find by id it's going to be request and params and id i will say try and catch error and json this error okay after finding this post i'm gonna check whether this post like array includes this user or not i will say if the post and it's gonna be dislikes array and includes request and body and user id and after that i will say await and post update one and i'm gonna push this user id remember how we are doing this and i will say likes and requests and params sorry buddy and it's gonna be user id and after that i will send this post has been liked i will do the same thing for dislike in this ham function so if this post likes include this user id it's gonna like this post if it's not i will say s and await pause update one and right now i will just pull item from this array i will say pull and after that likes and request and body user id and after that i can say disliked maybe okay so we are gonna check this likes array if it includes this user id it's gonna like if it's not it's gonna dislike i will say like this like here let's try it's our post i will choose this and here i will create like and dislike post and here i will say post this post id and it's gonna be put and here i will write my user id it can be drawn and it's gonna be like here let's send okay some error occurs here i will check i should write here first request and then response because it says request status is not a function so let's try right now i will send okay let's check and in likes array okay so we'd like our own post here so good we completed this also let's try to fetch some post so i will say router and it's gonna be get an id here request response i will say try and catch i will catch my error here and inside this respawns json and i'm gonna send this error and inside this tray i will say const post and it's gonna be paused and find by id i will pass this parameter request and params it's gonna be id after finding this post i'm gonna send as a response and start this will be successful and after that i will send this i'm coming to postman and add new request it's gonna be get i will write here get a post and here it's gonna be post and our post id here this one okay i'll just send there is error here because we forgot this await here and again i'm gonna send and this is our post perfect so let's try to do this timeline post i will say again router and it's going to be get and here i will write timeline async request response so i'm gonna create an array here i will say post array it's gonna be empty first and after i will just fetch all these posts i will say try i will do this quickly response status it's gonna be 500 and json error so how i'm gonna fetch all these data i'm gonna use something different here instead of a weight i'm gonna use promise because we will have multiple promises so firstly i'm gonna firstly i'm gonna find current user it's gonna be user of course first await and i will say find by id and inside request body and user id and after that i'm gonna add all posts of this current user to this post array i will say const user post and await pause dot find so i will say user id it's gonna be equal current user dot id because in the post model we have user id here we will just try to find all posts of this user and after that i will try to find all post of these followings i will say const friend posts it's gonna be a weight and i'm gonna use here promise dot all because we are gonna use map here if you are using any loop you should use promise all otherwise it's not going to fetch all of this if you use a weight here in sitemap it's not going to fetch i will say current user and followings and i will use here map let's say friend id and for each friend id i will say post dot find and again user id equals friend id actually i was going to use post array and first add this one and after this one but we don't need that i can delete this i can just basically concat these two arrays i will say res and json user posts and concat it's gonna be friend posts it's gonna take all posts or friends and concur with this post let's try firstly i'm gonna add some posts as jane where was this post here and my user chain i will copy this id and here i will say from j and i will say chain two and let's add for john also drone two okay let's check first here okay from john from jane jane 2 and john 2. so firstly i'm gonna follow john i will come here and our user id i can copy this and for john so basically i'm gonna follow john as a j i will say send and after that as jane i'm gonna try to fetch all timeline posts i will add request timeline posts posts and timeline and in the body i will indicate my user id user id will be jane's id which is this one i'm saying send it's going to be dot here and also i should return posts because it's gonna return each post inside this array let's try again now it's about naming that because it's conflicting with this get post because it's get also so it takes this timeline text as an id so i should just change this let's say all and start again let's try again of course i should write all right now it works perfectly from jane jane 2 and john john 2. if i make request as john let's write here as you can see it just returns john's post because it doesn't follow anyone awesome so we finish post twitter also of course something missing in this api because we are not using any error handling or we can use jwt verification later but right now for the beginning it's totally enough in the next lesson we are gonna use error handlers and we are gonna build our react application so after that we will not use postman we will make this request on our own application so it's pretty much all for today i hope you enjoyed it so you can find useful resources and source code of this api in the description below if you want to see more tutorials like this you can subscribe the channel and like the video so i will see you in the next video
Info
Channel: Lama Dev
Views: 105,798
Rating: undefined out of 5
Keywords: node, node js, express, rest api, node rest api, express rest api, crud, login, register, lama dev, mongodb, node with mongo, social media app, social media application, social media rest api, mongoose
Id: ldGl6L4Vktk
Channel Id: undefined
Length: 90min 30sec (5430 seconds)
Published: Thu Mar 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.