Build a Rest API using Node.js, Express, Sequelize, Postgres, Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's wait a couple of seconds no worries can you check the other we should be still nothing on my hands okay i see something so it should be perfect there we are hello hello hello everyone welcome uh this is francesco and we have yotam yeah okay okay we have the the right camera perfect okay so welcome everyone what are we gonna do today uh today we are gonna build uh some full rest api it's not a full stack application so it's just uh backend and adb connected each other we will use node.js sqlids which is on our ram i'll explain this one by one of course and i use postgres which is a sql database and i use of course docker otherwise i would not like live stream today but first of all let me introduce yotam which is our friend we've been interacting kinda a lot and he he is a developer advocate at table nine if i'm not wrong how are you yatam you are correct perfect perfect okay and uh so today we are not gonna just make an interview today we are gonna get your my hands dirty and i'll code with you this application from scratch from zero and to be honest i had a i've already i am an article about what i'm gonna build today but i'm not uh just copying passing a lot of code maybe i'll just take this on the site to cheat just a little bit but i'll code this from zero so you can interrupt me please make me some question if you want uh yotam will be will help me i hope by reading some questions you can interrupt me at any time and also especially i'm here also to explain what i'm doing so i'll try to explain line by line but if i'm going too fast or too slow please just let me know and let's think maybe on the top right you have seen the type 9 logo and i let the autumn introduce it maybe in a better way but basically it's a tool it's an extension for this code which lets you uh code in a faster way so it really helps helped me i started with the free version and after a while i i've upgraded that to the pro version and i think we have some good news because i think that during this live maybe in a couple of minutes we will put a free code free coupon um i'm not free but i mean some there'll be some reduction i don't know you'll explain this in your time okay and uh yeah and um yeah so jotan uh how has been your day yeah uh can you explain a little bit uh about the nine couple of minutes so many questions well i will start by saying hello to everyone and i'm very excited to be here and thank you for having for having me on your live stream francesco um i'm an i'm a developer advocate at the tab nine tab nine for those who don't know it yet is an ai powered tool for almost every id every code editor it is um it is an auto completion tool but for code meaning that while you write your code tab 9 has um a lot of information that it gathered from two million github pages two million so it knows code yeah that's not the one that's not one yeah no no no no many many github repositories from many languages so we just took um open ai's gpt 2 neural network that was trained to understand english so we said okay we can take this we can take this model and use the use the capabilities that it had to to learn to learn code not just english so by so when you so when you code so while you code and you have tab 9 running in the background tab 9 understands what you're doing and it completes your code while you write it i think we're going to see a bunch of a bunch of examples while writing this rest api app now let's see and as promised we have a promotion we have a promotion here just for who's watching watching it right now um i will i will share a link in the in the chat on the right side perfect and we will we'll probably uh we will probably add the link in the in the video description also so whoever wants to have a tab 9 pro can get a 50 discount for one month or one year up to you and i say let's start let's go yes that's great but first of all let me ask you just one question otherwise i don't start desktop 9 works with the docker docker file and docker compose files because i i use the other tools and they are just they work just with some specific language so what do you say i guess we will have to i guess we'll have to start coding and find out okay okay if this doesn't work with docker file i'll just end up there yeah i'll kick you from the live stream yeah but let's see let's see let's see perfect okay so first of all let's change the camera otherwise i start okay so can you see perfect just i have just one question if you can answer what's your unders if you use node if you use docker please write that in the chat so at least i know if i need to explain everything or you need to understand also how api works we're basically trying to create a server which will expose some endpoints and basically you will use postman which is a tool to test this api usually api they work with http requests we have some verbs i've not gotten into details of that but uh you will see you'll see this this should be kind of clear at the end and of course you can make me any question questions you want okay let's get started are you still there you are them yeah but since i don't see any questions coming in the chat about docker and um specifically about docker maybe we can elaborate a little bit about it for those who who are watching this live stream right now and have no idea what you're talking about yeah they know javascript they know tab nine of course but maybe they never heard about docker yeah i think i think this um example will be kind of different from a lot of examples that you can see on youtube but not saying this because i'm gonna say do this because uh we will embrace the containerization which is a technology to to deploy your application in applications in a way faster way since the beginning so the idea is that we will do a basic hello world with node.js and then we will write the docker file explain of course what it is since the beginning and we will make a subsequent better version of our uh image or our code and but i want to do this from the beginning i don't want don't want to add the docker just at the end and he's also to be honest also for me so i'm sure or maybe more sure that this could work so we with uh with less code yeah yeah so if you have any question you have done before i guess i start of course i could talk for howards but uh let's see it's it's something that you can use to deploy your application in a better way in uh this example at the end will be available available for everyone you can just run this example for from any any pc which has an internet connection i know that this could sound a little bit strange the only thing that you need is to have docker installed on your machine so that's it okay so let's start from the beginning i have a super advanced uh notepad file here and okay but this is more for me so i'll follow along i had no time to be honest to do something very very pretty sorry for that i'm sorry okay this is francesco's cheat sheet exactly now this is just to follow along uh yeah to see something that maybe only i understand probably okay so let's start from here i'm really excited uh yeah okay so let's create a new folder we can call this like i don't know node underscore tab nine okay because in your honor uh your autumn so because you have a lot of folders here called the node perfect perfect perf so so then let's open this up with the visual studio code it's in the other screen uh before starting just let me show which extension extension extension extensions are used sorry and yeah and i used a docker extension and i have this one so let me show you here the good thing is that you can also install this directory from the the market right it's so easy you just search for you just search for the extension you want you press install and there it is yes i don't want yeah i don't want to throw shaders but for with other tools you need to go on their their site they need to download stuff you can do everything and read the documentation of course of course but reading documentation is a bit boring let's say this so it's using who are who are the people who actually read the documentation yeah it depends of course maybe if you need to learn javascript you can read the commentation but to use a tool you should not this is my personal opinion so you can use from this one you have this and of course it you you also have a page right but you can do this directly inside this because this is something that i really like and i see also great numbers here yeah i'm not gonna go here today but we also youtube channel so yeah great i have a docker extension and maybe some other extensions just for the for the icons or some other basic stuff but uh and also something not related to javascript so let's get started okay so i have here a terminal and everything is clear i don't know why there is this okay maybe before we start we have a question here from ali okay he's saying that he is um that he's using all the tools that are in the title but he's using mongodb instead of and with node and not postgraphs okay so i have other i have also other tutorials when i use node and mongodb i'll show you exactly where you should change the the code okay during the live stream just remind me this while we are on the db part but we are not really we don't need to use postgres of course we are free to choose whatever we want perfect okay stay tuned ali perfect yeah of course um okay this and this one okay so let's start okay so uh basically we initialize um an npm project and we do do write typing like this npm init y which stands for yes yes we have initialized this npm project node project and then we should install all the dependencies i've written them there because i can't remember them and they are just three i think if we had like five or more dependencies can you read the the font is this too too small or is this okay i think it's okay but i'm not wearing glasses um if anyone wants us to to take the font a little bigger than just tell us in the chat okay let's see okay hello okay so let's install the dependencies the dependencies are just three and i stole them all now so we do otherwise i'm sure that i'll forgot about this so i install express express is a framework to use with node.js to build your web server applications then we have the pg which stands for postgres it's basically a driver to connect it to a postgresdb and then we have this c sequence i always misspell this i hope that they've done this well so there are three dependencies sqlites is something that will help us really a lot it will help to create some tables to make some inserts so we'll basically it will do the the heavy lifting so we'll create we'll do the insert updates delete this of the db okay and of course this could be done without an orm but i've done some examples with that but today i wanna use this okay okay so first of all let's create um a folder yeah let's get a folder otherwise this becomes a mess after a while so i use um app and then inside this app i'll create index.js file this should be not super new for someone maybe so it's always a good practice to create the folders and the files you need before filling them out just to have just to have just to have a screen of everything that you need before before you start actually writing the code yeah to be honest you are that keeps you on track yeah of course and to be honest i was about just to write the the the index.js they just filed but actually yeah luckily they have checked that okay i won't let you okay so let's start because uh we are here with your attempts okay so i type c or and i already see that type 9 is useful i'm not saying this because yotam is here because it basically it starts to it tries to help me because i'm at the beginning of a js file it could not sound that much time but if we write a lot of times const do you agree uh yeah sometimes sometimes it can fill up just one word that you're yeah that your fingers are writing without even thinking but sometimes it can fill up a whole line that you had to go and look forward and think about yeah i just want to point out that i'm i've all other stuff installed on this pc so this is not like a super clean machine with just these two uh extensions i have i think like 20 extensions so maybe this is also why we will see other stuff but this is an example because this is a real world example this is not something prepared so i want to really stress this out so i've typed four charters and it's already tab nine strikes again this is really great already i love this okay okay so i wrote the first line it's really it's great okay this is enough for now then let's um initialized our our uh application [Applause] i love this already uh because let's be honest today i'm doing this because i am writing sometimes i copy past but uh writing this it's really a pleasure okay let me write a couple of things but otherwise i forget about that uh i don't know if you know what a body parser is is something that for example to get some json inputs when we do we will do some post requests so we will do some requests with a body with the needs uh for a file format or a format in general not just a file format and to use this i've discovered this some weeks ago that you don't need really the body parts are packaged because it's something like deprecated so we will do this up you up dot use use [Music] express express.json nice this is a method call nice okay oh that's a nice trick that's the first time i see i see someone using the app the app used when express with with the json yeah but this is just to be honest execution to be honest i had this uh one person made me notice this during the um yeah during a live stream so i can't remember the name now but uh it was helpful because uh of course of course these words and just let me show you this again i've tried the your encoded it shows this and and this should be something like that wow this is great i will just explain i will just explain for one second what just happened here the reason that the reason that you see those completions showing up is because many people did this before you you're not the first person on earth to write to write the express code using the url encoded and with the extent with the extended truth tab nine already has this knowledge it understands what you're doing and it tells you i know what you're doing you don't need to write it yourself okay so now let me write something that probably we will not use in this um in this uh application but it's not bad to write this i will i would set some headers from the for the the application so this is like this is nice and okay so let me write and then okay set header here we go set header so probably we don't need this because um we will access from the same machine but uh access control this is i think this is where really top nine shines because uh i always forgot yeah yeah i just forgot this great rest and so i will set two headers the first is to um to avoid the course problem and the other one it should to allow some methods which should be this one so basically let's see should nice post post put i use put usually handle it and this is our crud perfect so we are not done yet okay stay with us okay and then let's be called the next and i'm sure that i need to call but okay this works should work okay and then i want just to do like a hello world i'm typing just because yeah so we can follow along this is a try catch statement and here we will uh listen to our server up listen i think a lot of people have done this before me i'm pretty sure precious and i usually use another thing so external port i use what's what's the what's the difference between between regular port and external port i mean i i only know that i only know the port method no this is a just an environment variable this is an environment i'm setting an environment variable but uh this is already the apart because if this is what uh yeah you can see this is where what um the apple will listen to let's see if it works okay but now for example i've not set any environment variable i'm writing this code because in the future we will use we will set environment variable from the docker compose file but for now let me do the old good trick for javascript which is basically so we will have some i don't know if we need to put this before no no after okay and if you catch some error hopefully not we will cancel log log console here or it should be there okay nice uh okay okay let's let's try to to run this application let's see if at least no no no we need some other stuff because otherwise probably we don't have um an endpoint to test so let's write some other files i think yeah so let's create the structure of this application so instead inside the app we will create the routes or rules what do you say what's the what well depends if you're from america or from the uk we said yeah right i think i think that i think the convention is routes maybe some people from the uk here will go find me and shoot me what what what what is the fastest way to test if if if the minimum process is running correctly is there like is there like some console yeah this is i'm working that way that we can we can do this but we this should already already work but uh we we can we cannot test an endpoint okay so okay oh let me let's try i don't know no let's try let's try this uh this test test and pack because we need this maybe later okay so uh routes then we have the controllers then we should have the models inside up i'm creating this now so otherwise after this i forget and then we will have a util folder which is basically where we will restore our configurations for the adb okay so in the routes we will create a new file which we will call like dev dot js it could be dev that routes dot js but um okay so to use this we will try we will type like always cost we need also the controller that we can write later controller nice we have not the file yet and it's it really helps me that's great um yeah it will try it will try it will try to guess the file that you're that you're looking for nice uh well controllers almost there and dev dev.js and then also uh so it's if i say routes i see a to say router equal required so basically i'm setting up some some a basic route and then an example okay express and then the router this is basically to hand because i don't want to i don't want to do this in the index.js okay so i will do something really basic here we will do something like that we could also write this here but i'll be super fast controller dot version let's see in the meanwhile i will just remind to whoever is viewing this and then watching watching this live stream right now you can post your questions if something isn't clear you want us to elaborate or anything just post your questions in the in the chat and we will answer everything thank you thank you you're done please check check the chat sometimes because i'm focused on i have i have four eyes on it perfect perfect perfect okay so in the controller we can use create another file we call this.js and then here i don't want to do something super complicated let's export a new file and it's called this uh um it should be like version so we have a request or response and then the next we will probably will not use this is great and then we will return the rest of status to handler great i love this okay this is all tab nine ladies and gentlemen and i also i love the the icon that shows them and yeah and this is the largest glass of coffee in the world okay this should be nice okay let's see if i've done this correct i don't know usually i just copy past but here i want to show how it could be like to test this from zero so let's see and i need no i don't need to export because i i like this uh i like this way of writing the stuff so let's see if i get some some error or not i should not be should not have but i already see that here this is nice for me i need to import the the routes so we will use basically the uh dash dab we should be like this okay and we will require require the file which should be something that we haven't imported yet which should be something like that but i think that we need to import this and now because we are requiring this here okay so let's see if i get some her even even in this case so let's try without docker let's see how it goes no okay so if i say move index.js nice let's see the error i cannot find module why i am i'm because i need to go in the app folder sorry of course if you create a folder you need to get into that folder quite basic okay okay so i don't see a log here because i have not put a lock but let's see if this works so just let me show that okay this is something hold okay so if i go to local lost don't check this local lost 3000 it was one or three thousand three thousand let's see i already forgot that now the port they're not the port 3000 3001 it should be dev version okay we don't have this let's see why okay so okay so this is okay so let's see if at least this is listening so if i do this cannot get let's because maybe i not saved the file let's see okay okay [Music] what's the problem here express i'm trying to type her or where's my phone oh my god oh maybe i need to install this again no let's see if i do this again now i've already done there okay no um let's see what's the problem here it should be up listen um external part i think this is some typos here the version controllers that dev require express controller dot version app controller dev version i think that i maybe i need to import something in the controller let's see no what's the problem here return rest of status suggestion i don't know if i need to do something else okay nice this is nice use maybe it's not slashed [Music] let's see let's see if the problem is this one something stupid for sure let me wrap up the icons log here okay so if i do this okay so the app should listen so let's see we should use the dash dev and we should get here we should get this controller dot version and maybe i know what's the problem i know this is something that i always forget this one i always forget this okay the model export yeah is to export this let's see yeah now it works it's something that i always forget it's it's stronger than me perfect okay so um i've created a basic hello world in uh for node.js.js now we should be here okay we are here now from this application let's let's write let's write some docker stuff so and now i'll check uh yotam if you if you are lying to me we'll say let's check if it works so i'll create something like which calls called dockerfile i think we can also just start starting from this one so basically what is a docker file a docker file is a text used to bundle our application in a docker image okay so why should they do the where should we use them i do this to avoid installing node.js to my development this to my production machine because here on my machine i have node this version but if i want this code running on another pc it needs to have a node version and you could have a different version of node and i can already say that if which you which usually happens usually i can already say this because this i i lost some hours on this if you use for example the newer version of node.js you need to upgrade something so for example this example doesn't work for example so for example now i'll use the node version for um 14 but if if you use sometimes different versions they could give problems with sqlites and postgres so in this case i do something like that so let's see okay so i do i write a from which is basically a common to start from a docker image i'll not go into details now but let's say that basically it's like that i start from uh a famous oh this is a nice the help on the airport on the node is fine oh i i i appreciate that okay then other okay so basically a docker file is done with key and value okay you can make any question your time also please check the chat sometimes okay so in another file i see i have keys and values so for example from and the value is known for 14. then i'll i'll show you from where we are getting this stuff then other keys we'll do we will do something very basic this time we will expose this part to be honest we don't really need this but this is just to remind so we don't really need this yeah it's still it's still good it's still good to know this yeah yeah so then something that usually i like to do i usually like to install inside the docker image a version the latest version on npm of the note version this is just because so i'm sure that i'll get the the latest version of the npm this could also be avoided make sense okay okay oh okay and then some interesting stuff because if you know if coded in javascript let me explain here maybe a couple of minutes okay do we have time i hope so um so if basically yeah basically uh we don't want to use mine or the modules folder because this is my dependencies on my machine so what we'll do we will copy the only the package.json and we could also um do this this basically uh takes the um package package.lock this is a little trick to don't copy package lock json if does it exist if it doesn't exist it uh basically it ignores that otherwise it will complain if you try to copy something that doesn't exist it will complain then we can do something um oh this is nice the help on locker file it it's nice mpm install perfect perfect and then we can also decide a working deer a work deer is basically a path for the image i'll show you this if i have time we can call this like lsrc we are basically creating the file system for the docker image based on our application okay if you have any question of course you can do this you can ask me this and then we are copying the whole uh folder inside the folder in of the image and i can see that here for example there is a problem because we are copying in this case we will copy this we don't want this folder no okay if we share this with you i would not i will have this dogger ignore probably right and then at the end yeah at the end we will can define at the end of the docker file um i come a command which is basically the basic command when we run the the docker container on a docker image okay i'm not going to super details now but uh if you have any questions you can see we we will have uh we will have another live stream yeah yeah that's dog if i start uh it's over okay so um okay so i've defined this basically it's what i should do can you recognize this from here that maybe if you need to want to run my application you should do something more or less like this like you download this then you run an npm install and you will do cmd node app index.js okay and how do we how do we ignore the node models this is a super great question you create something which is called docker ignore sounds my family probably i i i misspelled no this one yeah you have a yeah that's because there is there is an icon that's right this had this icon saves me okay and now and now we just and now we just fill up the names of the folders or files that we want to exactly exactly so exactly if you know git ignore you know docker ignored for example for example one interesting thing is that for example i don't want git in a production environment uh i don't i don't copy the git history this is the git history you know this the the hidden folder i don't need this just to show a couple of things another option could be i just copy the this folder or this folder and this stuff but uh i like to use this diff so i can show you this docker ignore okay now okay now we are here okay i mean we have a lot of stuff to do so um so now we do a very interesting command which is docker build which which is the short for docker image build we are building an image and when we build an image we can pass a tag which is basically the name of the image let's call it like that and we can call this like i don't know like know the tab 9 with the version let's use some just this version okay so the pattern is if you want tips about that follow me on twitter is a docker image build the tags the name of the image and then the path we can specify any path but usually we are doing this from the same folder which i'm we are not doing now so maybe let's see and then and then we don't need to specify no we need to specify the path but i am in the app folder so let me go up one level otherwise i fail okay so this should be more clear so now i am in the know the tab 9 folder can you see this so the build needs a docker file which could be named i need for a different way but let's start simple there is a lot of default stuff in docker and usually when you get started it's better to follow the best parts i can i could do f the name of my docker file but let's keep it simple this little dot is the path so basically now i'm running this i'm building this image sorry what's happening now now we are the docker is building for us this image based on the docker file and if you can see a lot of the the steps that are defined instead of docker file they become instructions so basically it's building this stuff you can you see this npm install i find this yeah i mean for a second we have seen that yeah do you see this stage like copy we don't see the cmd but that's correct because the cmd is when we run the container now to see because for example i got some questions sometimes where is the image i should expect maybe some image here i can refresh but it's not here the image is on my file system in a folder uh hidden by docker okay we're not going to details but to see where it is the image we can do this comma command of course we need to have installed docker let me show you here we have docker installed i also a video about that if you want to check but it's super easy okay can you see that here okay i've not done docker images before but you can trust me i'm not cheating because the idiot has been created 40 seconds second 45 seconds ago so we now we have this image and just to be sure let me show that now our server is offline okay we are not running our server right now instead of doing node.js node index.js let me do a different command one of my favorite commas docker run and let me expose the port 3001 3001 and then the name of the image node tab 9 0.0.1 let's see what happens if i do this can you see here if i do get i get the same application so what's the advantage here let me show you something interesting i'll delete my node modules folder okay i can delete this if it okay it's complaining because it's super big i don't need anymore i could even don't i could even uninstall node on my pc now i usually have this but yeah okay so now it's complaining because i'm trying to run another container with the same um i think with the same with the same port so now it's complaining but he is right to show the containers we do docker ps and we can do docker ps or docker ps a let me do this again docker ps with docker ps or docker container ls we can we can see all the running containers you can see that here there is the container id the image which is based on when it's been created the status and the port exposed and this is a fancy name that's given by randomly i could give my name to um to a container now to to show all the containers even the stopper ones we can do docker ram and we can type the first characters of the id for example c4 and two nine can you see this the c4 here and the two nine here okay it should complain about one because for security reasons where i don't delete it doesn't delete a running container okay so it says that you should stop the container and then remove that but since i am a little bit rude let's do just docker arrange f which stands for force 29 and it's done okay so okay so this was the an example so do you have any if you have any question i can stop a couple of seconds and then we will go on with the docker composer the only question that we have in the chat right now by coding vampire proven is asking if we are making a table nine clone no we're not today we're we're doing a rest api application i don't want to compete with with top nine at least today but uh yeah if you can pick them join them um but we are but we are using um just answering coding vampire we are using tab 9 to help us code this whole application faster and also if you'll if you'll scroll up a little bit in the in the chat you will see that you have a promotion code with a link for 50 discount for tab 9 pro i hope this answers okay let's move a little bit fast so uh now i want to do something a docker compo i want to create a dockercompose.yml file why usually you use you use the tool docker compose which is a set of cli commands and a file so there is a difference between the file and the cli so this is this is not this is the cli now there is this version too i could also do this without the the dash but this is the command line and this is the a file which is could also be used for example by kubernetes so this is the file where we define uh defenders kubernetes is a tool to orchestrate containers okay so okay i like i like to um to create these even if i have just one um service because after that we will create another service run into this docker compose and i i'll show you the power of docker compose this is a super crash course but usually you need like a couple of hours because before watch seeing the compose in this case i'll just go straight into that and then we can define some services i'll show you the the good stuff of this so we can define services as basically like these uh containers and images so like uh the node application is a service in this case so let's called like this node let's call this line not backhand oh this is nice oh nice it's yeah yeah okay here you can define i'll explain in this everyone uh one by one so we can find a container name which so we can define um a custom name and we will call this like node category recognize himself it can't okay usually okay then we can define an image a image here is more or less like the tag that we have used before so i've called this know the tab 9 0.0.1 so in this case i've called this node tab 9 0.0.2 okay then this this command is the build which i'll show you if i don't choke uh context okay so this is basically the dots that we have put before when we did the build command i'll show you yeah pretty soon i swear it helped me and it should be three thousand one three thousand one thank you okay and for now it should be enough but i want to do these maybe i don't need to do this but let's let me show these i can i wanna define some environment variables because that three three zero zero one are coded inside this i don't i really don't like this i don't like this one and this is just uh yeah but i really want to use these so which one i want to use this which one would you pick instead it's the same value but we could put an another value but uh i probably i'll change this maybe later okay so the no this was the x external part external part thank you equal 3001 and here we will put sum in five time we will put the environment variables of the db also and for now it should be enough so what i have done something which could sounds useless because we are just using a docker compose for just one service but look at this if now i do i type if i've not done any typos i'll show you the images in my local local file i do this docker compose this could be with a dash or without with this i'm using the new version docker compose build command just this let's see if it without without the dash is the is the newer version yeah this is written in go okay let's see can you see i've built another image just putting this this sounds a little bit like magic doesn't it but here basically it's saying okay please build the what's written in the docker compose file so i don't need for example to remember the tag the tag is what i've defined here in the image can you see the advantage of using this approach i don't need to remember thank you thank you for explaining and thank you for explaining this because this is a real what the hell moment exactly this is what i'm explaining this just for you yotam because i've watched that i've watched a lot of docker tutorials and they know where they fail okay so um yeah so basically here is very useful for example if you want to change version i can do this build and then build another version so let's see if i haven't done any mistake so how can i run now this service i could do like before docker run dash p the the ports but there is here i'm just using just one um variable dash p but think about having a more very more complicated example i can do just docker compose up and it's running this image based on the docker compass file let's see if it works it works okay yeah nice okay okay so this is nice uh uh with ctrl c i'm starting can you see that here is a little bit different it's showing some logs with the color of the name because if i have different here i could define different services and they will have logs with different colors so oh that's good we are gonna do this we're gonna do this now so i'm gonna skip the also also we have done this i'm gonna skip this repository because we will do this at the end i've done this this now i want to go straight forward into the adb is this that it's okay for you but at the end i want to show also the undercurrent but it's not more it's not really related to the code so since the autumn is here i want to do some more code related stuff is that okay for you okay yes okay but i'll show you if i have four or five more minutes okay so now we should have a db right so what should they do if usually uh usually i go here i see i go on postgres uh not possible sorry i will go on postgres uh these are examples so i should come here i should click i will never click this button i should download this this stuff i should have possible on my machine probably you have done this before in your life i've also done this maybe last time five years ago the problem we had a question where you had a question before about the differences between posing between postgres and mongodb so the difference is still here this part is for you yeah yeah okay uh i'm here this is a very great question because here i'm not saying that with docker you can use a postgres db you can use any db you can use i've done i've also some articles on hash node if you want to check that using i can use some node and here i'm doing something related just to postgres okay so how can i use postgresql without without installing it it maybe could sound really sounds really strange you can how do you do that that's that's a great question there is something called docker hub and if you know github you know docker hub because as github is a repository for uh for project docker hobbies are repositories for images and here these are the official images that are on this hub and there are seven millions and half available images so here you see the power of docker docker would be way less powerful if we would need to build every image from scratch here we have images done by the postgres team which of course are better than me at creating the docker file okay for for the dog i could download the postgres and do my docker file i have some this is a bit no one is better than your franchise no no no but because team is better than me at least at least on making the docker file on postgres they are better than me i'm sure okay okay let me show you okay do you recognize this this is the docker file which the postgres theme has wrote to create an image of their postgres version 12 application it's kinda long i don't know what's going on here i'll trust them but the idea is that these replaces to me to install posgus on my machine which is really a dream not just because i it's easier for me i could also do this with without docker but it's because i can use different versions of postgres at the same time on the same machine and this usually it's very hard to do this on the same machine and yeah and also if i delete the images like if i would have ins or uninstall the postgres sounds good that's useful that's very useful it is i'm super excited you know okay so before adding this this is a new service let me write this the dip oh wow defense depends on yeah depends on yeah nice uh and here i can say this uh service please wait for this service before um no db let's call this like that so we will wait docker will wait for this service to start before running this container there is an issue but we should not have this okay so let's write yeah i'm asking so the depends on is sort of like uh like an unload um yeah yeah like like like an unload function wait wait until wait until we have everything yeah to be 100 percent honest this is just for the container to start so docker is so fast that if you just do this it this server bootstraps even before the the container inside the the node the con the the postgres container uh it's set up so but this is not a problem of docker so we will do this uh one by one at the beginning so but okay so container name we could call this node not db the container name is then the name the default name that i wanna give the custom name to be honest then here i can do this postgres and here we will see this then let me write down a lot of other things like usually if you know postgres it runs on a specific port which is um five five four three two thank you okay okay and this is already has that been out of completed by top nine right now yeah but actually not this one but this one yeah it's replaced with the same one which is never never never a bad thing so environment stands for environment variables and here what we need to do because here we are defining the environment variables of the official postgres image let me go on here because where it was that one okay so they have given to us some environment variables that i can use i'm not defining new environment variables i'm using the environment variables defined by the postgres developers who made this image okay so this need to be exactly the same otherwise it doesn't work so the name is postgres user i need to copy this uh i usually since i have a big go i use my name then the postgres pass oh this is nice plus guest password because it takes some from the repositories so the best i hope everyone is seeing how francesco is barely typing anything he's mostly just tabbing down to tab 9 and this is not this is not code this is a yum file so it should be hard between to just understand what i'm writing because the yam is yeah maybe it's closer to humans there are different opinions about that but honestly i like that and then a postgres db this is kind of important because this is the name of the db when i run this image so let's call this like uh let's call this like uh i don't know tab 9db okay let's call it like that okay so that's very that's very creative francesco yeah yeah it is yeah now let me do something a little bit fast because otherwise we don't have time but the problem is that if you run stop containers you don't have persistence when you by default when you use containers so you need to do this in some other ways so this is a little bit more effort when you do when you use containers instead of just downloading stuff on the on some somewhere but to be honest this is a super useful thing because uh also if you deploy these on aws and other stuff so basically this is the persistence for for docker since we are using the db we are using a volume i i post about this every day i do i've done also some videos about that so self promotion and we will we will call this like uh mps let's call this like that which stands for not postgres sqlites okay data probably this is fetching my my my repository on github probably i don't know how it can understand this and this is the you're not sure how it works no but i'm happy i'm happy anyway first grass ql and data okay so this is the part of the volume which is basically for persistent i'll be fast here and here at the end of the docker compose file i'll define also the volumes that i want and i need just this little guy let's see i'm doing this just for you all perfect okay so if i'm not wrong now we should have two services running on the same machine when we'll do docker compose up so and you know and here if we want me to explain i could but first of all let me let me check if i have something running i should not have docker ps ah let me remove this this one i can just type the first uh the first charter okay so docker ps dash a docker images okay so okay so we have just the the two images that we have built one with docker fight just in docker build and one with the docker compass file and that's it we don't have any engineers now let's try let's try to do docker you can do this with the dash or with the space i need to get used to space so i'll try to do the space uh docker compose dash d stands for uh detached so basically you know let's do this without that so if i do docker compose app now it should look into this file and it should run these two services one is node backend again and one is the our postgres image so it will be a container running basically on this image can you see here i'm using the official postgres image let's see what happens if i do docker compose app okay docker compose up don't come up it means what is this is in this file i want this up and running okay now okay so now what's going on here because i see okay so maybe it's it it looks like it's struggling a little bit yeah it's because it's because we are live streaming oh okay okay so we're taking on your thing so your machine is taking most of the broadband to the stream okay now let's see if the server is still up and running okay let's serve the my our hello world server is up and running now do you see that here i'm stopped now if i do ctrl c it should stop the containers i don't want to do that so i'll create maybe i can do this from here okay so let's can you see here you want is a little bit bigger okay maybe it's better here because we are at the top with our camera oh okay okay now so let's try this okay it's a bit big but let's see what's going on here because here now i see that there are two containers a bit big okay two containers can you see this here let's check just a couple of things we have the name not a random name but the name we have defined in the docker compose so this is just to define the name what is this here but now now an exciting thing because we have this postgres and if we do docker images do you see that here now we have this image so basically docker has downloaded this image on the local machine since it was defined inside this file okay okay now if you want to get inside this db before doing the the rest api let's do a fancy command that i honestly like if i remember the syntax of course docker exec which is basically a command to execute other commands for containers usually is used for open a terminal but in this case we are not doing this docker exec it which stands for open an interactive shell and a terminal basically at ui um we can put the id of the of postgres 56 and then the command p sequel which if you have used the postgres in your life i don't know if you have you ever used this yellow tab okay um it's basically to get oh what is it to get to to run some sql commands and the db is stop nine db no let me check tab 9 underscore db this is this looks very good now can you see that here i am inside the container running the puzzle's image if i am i'm not that good with p sql commands but if i do something like that we don't have any relations here and we could like meaning this okay what does it what does it mean that they did find any relations okay yeah we should talk about hours about that but basically this database is a sql db so it uses tables and and it's an entity relationship uh db so it basically it uses some tables and relations between them today to tell this in five seconds okay thank you thank you thank you okay okay with also we don't have any tables here we don't have nothing okay so remember this it's okay now okay now the problem is that here i'm i'm not cheating but this is not done at all because i'm just my hello world server 100db but they don't talk to each other they're just two separate things on the same machine but i need what i want to do i would like to connect this service to my db right this is what we want to do this is what we promised right okay so now i let me stop this okay and now we will create the rest api so what form where can we start okay let's start from the configuration of the db so we need some stuff because we need to configure the db we need a model defined to understand how we want this table this objects and then we need five controllers with five routes to insert delete update and delete stuff so we need to go not anything fast but let's see how fast i can go okay so uh first of all we will create a file called database database dot dot js and here uh we will use sqlites civilized is on your rm and here also we should talk for a bit but uh let me explain really fast if you have used the mongodb i don't know who's gonna do that it's basically as mongoose for uh postgres okay so it's something that you can use to create tables create uh insert something like that okay here is the documentation okay if you have any questions that's pretty simple yeah yeah there are people against the orms of course but here we want to be as fast as possible so we want to require do you remember that we have installed this at the beginning we already forgot this here let me show this one and now you need to now you need to get the environment variables exactly perfect and basically now i'm writing code no more constant sqlize equal now we create an object this could maybe uh look a little bit complicated but you just need to get used to usually i copy past this for now so now we need to pass some environment variables to this object and the past is correct it looks like that okay the problem is that here i'm writing this environment variables but these are not the the postgres one these are my application one that i have not written yet so let's see let's do pg database a different one so you use database then let me do this pg user these are not the official uh postgres environment variables these are mine defined by me process.m pg password they you need to put this in order because uh i've experienced some problems with that okay in order you mean uh the user and the password this is not a json object this is a constructor so if you if you you can't understand it you want to use as usage this and then something sdb i understand okay this is a crucial part because uh usually when you're connected to adb you put something like the ap right like a localhost or something like that the container doesn't work that way you need to pass the name of the container so by passing the name of the container it recognizes that you need to you want to connect with the postgresql container and then we can specify a dialect because one powerful thing about simple lights is that it doesn't you don't need to use this just for the kyoto knight just for um just let me see if i just for postgres yeah just for sports and but for example for my sequel and before before i forgot this thank you let me write this because this is my this is my problem every time so here it is forgetting to export your file every time every time okay okay so this should work it's complaining a bit but i think we should be okay okay so uh now what should we do um let's let's think about that we should okay let's write before i forget about this the environment variables defined here inside the docker composer so here i have just this external port now i need to this is great and this is i don't need to use them the exact order because here i'm just defining the environment variable so here i'll use let's see okay almost faster than copybuster and and then pg oh no oh wait no we no this is not this is pg database now this is now here i want to define my personal environment variable video database then pg user which is by the way i'll yeah by the way francesco ali is uh has noted that if you've been using uh capital n maybe in the [Music] uh where uh you we had the uh in the database in the database js file you have uh that that's why it's a complaining you have uh that thank you so much thank you ali thank you yeah it wasn't strange but thank you well thank you you saved you saved my life let's go fast then pg password uh this is one two three four five if you seen spaceball you see what i'm you know what i mean and then the pg database we have and then this is very very important pg host which is the name of the service that we want to connect it to can you guess which one is it yotam you should tell me yeah do you want to try okay let's see let's see in the shot let's see when while i drink here we need to define the service that you want to connect to is it one of is it one of the variables that you already named it's here we need to define the service the service oh oh and now now we now we define it no it's already definitely in this file okay check check the chat i give you okay the service the service the service the service that we want to connect to we have two services we have two services can you see two services yeah so has anyone written so it will be which one oh well ali who is saying ali who is our who is our very our very active uh viewer says the name of the process um isn't it yeah but which one is it's not the same of the process it's the name of the service that we have defined here it's i don't make hard questions it's uh there are two services this is not backhand this is not the b which should i put this okay this one so it has to be oh so so just now okay so just node back and that's it not db because this is not backend which is connected to this other service you don't want to connect it to my to my own services i got a little confused okay thank you okay so basically here saying okay please connect to this service because this is the service of the node connected with this service okay oh okay big sense that makes sense make sense now yeah okay okay and to be honest yeah this is the name of this one usually i name them the same so it should work perfect now i need the hard part let's see okay the the now this part now for the dev routes we had just one now we need more and i'll try to be as fast as again so here we can do we need to define a controller like before which is a required control from controllers and users yeah i have this bad habit to write this before creating the file please forgive me because otherwise probably you should have recognized that and then the the router the route which is required if you have any question uh just stop me i'll be expressing here this is just express the trout or someone wrote this before me for sure okay definitely so here now we are defining the finding points so this is a crowd crowd and points so what we do here here we do router dot usually right like to write them like that but it should be down in different ways so if we go on the let me write this then we can controller don't get who i'm reading this before maybe it would have been better to write this after but uh okay just let me write this like this and then i'll gain the get i'll explain this um specifically i'm writing this by hand so you can follow me but usually to be honest i can't be posting this um [Music] then post this is something um given by express that i i can define the name of the http request by using this uh router maybe router not express so i don't need to define the the verb of the http request it's inside this method so yeah it's easier dot create one probably i'll misspell some of them let's see then if we do uh put all right i think you're good thank you i think you're okay thank you yeah this is this is incredible the update one it really it's really it read my mind okay i'm i'm just you you just wrote a whole a whole line of now this is no this is incredible this is the trick this is okay this is the peak of the live stream delete i did it controller did it check it check it all out [Music] if the controller method is some kind of a middleware that's a good question of course it is i could define here for example i've never created some authentication stuff but here i could define a middleware function and this is just a function i could also write this here but the code would really look very bad very a very great question ali yeah okay now the the hardest part which is the controllers are you still there saucers.js okay now i still need some to do something i forgot this uh before doing the controller let me write the model because since we are using sqlite civilized is very good but we need to define how do we want this object inside the db okay we are not using typescript today but uh we are defining civilized objects anyway so require sqlites and then we can call these db equal require dash let's see ut okay okay now this is getting now it's it will get really interesting because now we define the model for sqlites i know that this school sounds a little bit annoying this this task but here for example if we define users this is the name of the table so civilized will create the table for us this is useful we don't need to create a db with the table with create insert create table or something like that we don't we will not do this in this in this tutorial okay so here we can define some stuff i have something prepared we can also change some types if you want otherwise i'll go with what i already have so we can define a type for sqlites which is the circularized integer okay uh auto increment you can guess what it is basically you will get some the one two three without needing to define that like like if you go to a marathon you don't define your your number of course maybe then false you need an id probably to file it or fail anyway because this is the primary key okay we're not talking about primary keys but basically it's the one thing that you can use to looking for looking inside that table and then this is the primary key of this table then uh this was users right so a username this okay what is the what is the primary key boolean um boolean stands for boolean yeah the yeah the primary the primary key no i'm saying that the id will be the primary key of this model oh yeah okay it's a it's a it has a little bit strange syntax but once you get that it's it's kind of easy i don't know how to blind can recognize this because i have this as a string already and okay great and then hollow non-false yeah usually i say this also on other live streams it's you that you it's you you that you're not come every day every time with that excuse that excuse that you have a family and a job yeah i will i will have i will have to show up to all the live streams from there yeah you will find it i say this kind of often okay so just to brag about tab nine yeah of course okay so let me type a little bit if you want um uh we can even stop here no now let's let's type a password basically i'm yeah i'm like defining some basically you can add whatever whatever elements or characteristics to to this table as you wish i mean now now we're defining id username email and password but you can also add whatever else we want to add or we need to insert integer strings boolean now to be honest here i'm doing the same exact model because if i have some problems i know that these are the the types okay but of course uh this is to make civilized talk with postgres or to be more generic like to use a dialect uh uh this direct postgres if we change this dialect to my sequel i've created this and we change the image and we say use um my sequel for example instead of postgres i think it should also work no with mongodb doesn't work and we can use the same model ready where is the file i think you maybe created it inside the controllers wow and nobody told me it is perfect i just i i just realized that also now because the file now because yeah because the file is the same but uh okay so nobody okay let's check this okay um bye-bye okay so the model is defined here okay and before i forget this this could really hunt me the module exports equal user okay so okay so here we have defined this now uh let's go in the controller please remind me that i need to do something in the index.js file okay please i will try this number uh cause the user okay so here now we are we import import the the model of the user and here now we will you see the just one thing let's see i don't need oh no i don't need to import 3db here i don't need this no just the users okay users perfect okay and okay so now we need to create some some stuff i usually start yeah now now we start and now we start to define the controllers of the of the chrome exactly okay so let's i usually start with this one we can we can even if i feel confident i can write them all otherwise i could create one and then we can build the image to see if at least this is works so basically we are defining the controller for this okay inside we can use the strike etch statement so this is the function that if our following is basically this one okay yeah okay okay now uh no what i'm writing so const usually i do something like that because in this case we are getting multiple uh multiple um users if we have model one of course or zero i don't know wait users dot fine ho and this is the method oh wow the man knows this this is a method used by sqlites so basically civilized has given us all the users that we have so this is kinda powerful i don't need to write any sql queries here and then let's try it without just no just know that you have uh that you have a double slash and uh in in row one uh doubles where you require you thank you ali you are the best okay here's the mvp of this uh we need we we need we need the we need you stay with us okay so stay with us yeah please i'll try to be fast return dot no what i'm writing where i'm writing here uh return res dot status so this is basically express json express commands and jason will be jackson yeah yeah it's and in this case we will return the error appropriately not less dot status let's say [Music] 500.000 error so do we want to try with just with this yeah let's test okay i already know that we will get some errors because express is smart so if we don't comment this it will express this kind of um functions so i'm gonna comment them out because says where is the get one crit one okay i need to create them okay and the thing that i'm remember that i need to do is that inside the index.js file i need to do just a couple of stuff the fist oh you wanted me to remind you that you need to do something in the end yes please yes yes yes please yes yes now that i remember this i remember this because i asked you to remember does this happens to you everything and i'm here to remind you after you're after you remember okay util [Music] okay so i need to import here because here now we'll see if i don't do any typos a little bit of magic i will import the user uh require oh this is wrong models what is correct users okay and now i'll do something which could sound a little bit ugly but it's one of it's one way to do this but first of all let's me add the the routes for the users slash users require oh nice okay now uh i'm gonna do something a lit we could do this in many many different ways uh i'll do the ugliest and shortest version so uh just the way we like it no no this could be that in a way better way but okay so basically i'm using here all the power of javascript i'm i'm basically creating a function and i think a synchronous function and then i call this now so i don't need the two yeah just this is basically everything a sink with the iffy ife so yeah something like that uh but i need to do something before here is the here is the here is the magic check this magic sqlites dot sync and i'll pass a parameter which is force which will be set to false probably the default is false let me explain what happened here then we will try to build them another image and let's see okay so if this command would ever work we will have civilized creating the table users inside the db without even touching any and any endpoint because this is done before we bootstrap the application okay so this is to avoid like creating tables somewhere or i see a lot of tutorials do things manually okay you could do this manually of course you can get the table and then do the inserts but here we are creating this table okay okay you said it you said it will be an ugly move i don't find it ugly i think it's beautiful okay uh okay okay so okay let's see if we have everything working if you have any question this is a good a good spot for me everything's fine let's call this zero zero three so we have the zero zero two which differ which is a different it was a different image so let's see let's see if this fails or not or not docker compose build nice okay docker images it fits the image by the way this is not the the space of all the images it's just it's just one of them okay uh what i've done here okay okay uh so i have this new image now let's try which was the commander to run all the services docker composer [Music] oh yeah there is okay yeah i heard a lot of noise so let's try the docker composer up command let's see what happen this looks very great and now let's see let's try to eat no i want first of all to check if all the services are up running otherwise there is no sense let's clear docker ps wow they are both up and running this is great now let's see if they are connected or not we will use first of all again these endpoints and now let's check the users wow this worked so uh are you still there yotam uh so we have hit a decent point okay you've lost basically the best part of the of the of so can you see these little two brackets this means that this is working this is fetching the users inside the db and it finds that there are no user which is correct okay just let me do something super fast then we will write the other commands but i think this is already working so now basically this is already done we should create if we have time you can do this but otherwise let's see but uh just let me do this with cool sounds okay um so we have a different name for the container which of the postgres container which is 5 2 now and now if i do this one can you see here i see some relations and i've not created any table if i do select oh from users can you see this this is a table created by sequel eyes before even eating the end point it was not me eating this get endpoint i'm just getting here the things so this is the advantage on using an rm is it good is it or not i don't know okay so basically now we have two services running on the same uh network i can show this if you want if you are interested into that and now we should just add the other controllers but i see this already as a success so i'm already happy uh just let me show this if i exit like here so there is something which is called docker networks which is basically used to connect the same containers on the same yeah sets of subnets ip something like that so if i do docker network ls there are four networks to be honest these three networks androids you can see the chord cursor i think yes these three these three are the default ones this super strange one i've never defined these how this happened a little bit of magic inside a docker composer if i do a docker compose app and if i have a lot of services even if i have not defined any network it will create a network for us and it will give the name of the folder with this default which is this node tab nine no tab nine and just to show this this is called because if i do this without docker composer i need to create my whole network they are not connected by default they are connected if i do them on the bridge but usually let me show these that the network inspect this and expect is a really important command let's see if i just need the first two these cool sounds could look a little bit scary but it's not this network i'm inspecting and here can you see this is the most important part there are two containers these two containers they can you see the name node db node 9 on the same network so so if i see this and if there is any problem the problem is just for the connection from my back from my back end to the db but that's it it's not about docker or connection and other stuff okay that's super super super useful what was the command okay in in general there are three four objects in docker there are containers ls container ls the containers then there are the images then there are the network thank you for asking this because so i can show you something the networks and the volumes let's see if we have this there you go this is the volume defined inside the docker composer i've done this because so we at least have a name otherwise postgres uses just uh unnamed anonymous volume which is about a bad practice so just to give it a name so we can name it instead of just checking ids or volumes which is good sounds super super strange okay and of course we can define custom names like defining a name of the for the network and the volume okay so now we could expand this let's do this because we said this in the thumbnail but now what i'm doing now is just a basic node node stuff with some uh yeah let's do them let's do this okay yeah we do this i i'm i'm try i'm trying to escape but i know that i need to do this okay let's ride this ah nice this was very nice um okay try catch and then we do we can find a user constant user equal in the in the in the article i've just write i just wrote const u don't do that cost use user dot find by oh whatever find by pk which is stands by primary key and here they rewrite something which could sound strange thank you that i require params high d and this is what we will pass um from the url okay i'll show you this but before i forget to do this let me uncomment these rounds okay perfect how did you how did you remember that they were commenting out uh i don't know i don't know it was like i think i think it's just because i'm on a live stream and i'm more focused than usual okay so return and by the way thank you for stopping by your return rest status jason user perfect okay okay thank you tab nine i think the how will this will could be wow no i see i think it is i'm really uh saving time i'm not saying this because you are here okay now are you all watching this okay are you watching this all check this out perfect exports dot create one i don't know if i pronounce [Music] try catch now we have yeah three more methods to go and then we are done just okay oh life i love i love this really okay now of course now the types now i need to define an option now i think that now the typescript people i think are going to yell at us because we are basically creating just an object we are not checking any type of course we are just just a script file but if you really want this we can make a typescript version of this project i've done a lot of videos with typescript of course record request dot this game we need the body username and then we have the email i don't know how can we okay this is really showing yeah here the brain is showing is really it's flexing now you just wrote p you know you didn't even write passwords just yeah yeah yeah yeah this is really yeah yeah really uh great okay uh okay i think it we need to do something else with that enough to just define the model so we can do another try catch inside of the catch i don't know there are different opinions about that but uh um yeah so i think in this case oh well and in this case we will what we will do here basically we want to make an insert inside the db so i should like to do like insert into user something like that instead i just do user dot create based on the user model and this is the power of civilized for example and then i can return res dots now it makes a lot of sense actually yeah okay i can i can even just say okay but i want to return the users that i created it's not a must probably it should just say i don't know okay so let's write down the other one you mean like you mean like ad like adding a console log there saying like user was created successfully or something like that oh yeah let's do this log user created okay user created success yeah that's it i'm i'm out of fantasy today okay basically uh every time okay so um just two more um end points to go yes i'm watching what i need to do to do and let's start ali had a question that i find interesting again he's asking why are you he's asking why are you using jason method instead of ascending method uh json is just as short to send something in jason format format i could do send it should also uh it's like sending json format i can do send and then just an object oh no it's just a shortcut because i used to do this so i've seen a lot of people doing just because if i send and here i put just an object i don't know if this works probably yes but uh this is for for me to be sure okay okay make sense okay let's write the delete first so maybe it's a little bit easier and then the last the hardest um for from last okay [Music] okay so in this case also try catch in the cache this is really powerful a lot very powerful and then cost okay constant const user equal await okay now this is not what i need because it's something destroy correct perfect and here i put a wear which is like more or less sql sql commands okay id which is the required uh direct params id okay ah and i need to return that uh this has been good okay return rest status i don't know exactly i can't remember exactly what um civilized returns but maybe okay let's see okay now uh the last the last and the hardest one is this one exports update one which is a bit long i'll cheat a bit update one okay i think okay try catch come on francesco we are almost done and then uh okay let's see let's see this is interesting now you can now you can just copy and paste from the creator i could but let's see const user model and then okay in this case just copy just okay probably it's faster in this way and password okay username email and password perfect and then we are almost there come on francesco you are almost done remember matrix when it's trinity says come on trinity that's you can't you can't forget that const user come on uh await user dot update uh no user dot update of course we need to know what need user model and then they were [Music] id is equal to reg params id of course here we should make some checks about the bodies but of course again we are not just creating some basic credit api and then return rest status jazz on user without parenthesis wow that's right no this is not written correctly because this must be in phrases inside prints so yeah okay so we are done with the live stream thank you for everyone coming no i'm joking i'm joking now i need to check but this uh let's see so uh okay so first of all a good thing is that since okay let's pretend that now i am uh i've created some new stuff so i know that the 003 works let's say that now i want to test the new version because i know that the get all one already works so i change version here since when i do docker compose app it doesn't find this uh image it in it builds it builds that okay that's the power of the docker composer yeah that you can you can have a working you can have a working image like this zero zero three of course we are just getting started but think about a complex application when we need to add a feature okay we have this zero zero three version working now we need a new one okay okay let's see everything looks fine it should let's see too easy that's same clear ps they are botapa running we just need to make the last tests on postman if these are done i will be really super super happy so let's just recap what we're doing so if i do death dot version i believe in your francesco it will work perfect i need someone who believes in me okay so if i try to find the users it's empty now the interesting part uh just let's use something that i did before but uh just because i'm lazy i don't want to write here so let's try to add your time email i don't know you would like to have that one i don't know if you have that i i i am the only author in the world that's definitely my gmail account wow great okay so this is okay so don't look at this this is just a response before um okay let's try this i'm trying to hit the endpoint with the post verb the users so i'm trying what i'm trying to do is this i'm trying to hit this route okay so if i have not misspelled it this should lead this to this one and then controller create one it should do something like that okay let's see let's see i already see some oh this is this looks super promising because it returns me something a little bit strange because i see not just what i say what i said in the json object but an id one okay these three uh parameters okay and also these which are by defaults added by sqlites usually i find them useful but of course you can remove those if you don't need them if you have your but basically it saves these times when you create and when you update the same object okay [Music] so we can use so now so now we can use that also to test the the update yeah yeah just let me add the other trooper to people how he spelled the alley like like this i would like to add the other people are you there okay yeah ali spells his name ali your password is safer than the yatam one so this one and then if there is other one otherwise let's say you know francisco i want i would love to have francesco gmail but i don't have that don't send mail to this one i'll change this i don't want him to get boomed it's not me okay okay now let's do something a little bit more interesting if i do this get all i don't need this of course just me because i'm lazy okay here i see all the users can you see this now how can access to just one user of course this is not error prone but let's put something that it's real if i do slash tool i should get just ali okay can we only can we only approach the well the objects or the users buy their id or we can also this is a good question this i've done i showed you what i have done of course this depends on the application i have done this command and it is fine by primary key if i need something else i need to it's maybe a different endpoint or maybe have some logic here and i can look for example inside by where with some other parameters this id is the one that i pass inside the url okay now two more parts just the put and delete and we are done okay the two hours really flying okay and now to update an existing user and of course you should check every parameters if you have the values today i'll just do something like that so it's a put command what do you want to change let's change me let's call me i don't know i don't know youtube david what do you want to change my name okay no i wanted to change your name to david you look like 504 which one ok or david wow i don't know why okay it looks similar to a lot of people okay so we are let's see if it works okay so the output is a little bit strange because this is basically civilized telling us okay i've changed one rows on the db we could of course do another get after the put but just to show you that this really changed the effects as this can you see that the idea of francesco the username of francesco now is youtuber francesco also if i get them all when i got all the people we have this one now only two things left this one a test and we are promised that we are done so who would we want to delete let's delete me i don't want to to delete anybody watching this live stream accept me so if i definitely let's delete you okay okay expo i was expecting that you would have been sacrificed sacrificed for me but okay it seems not self sacrificing person i'm sorry i i appreciate your honesty by the way it's great doing listening with you so delete slash three let's see okay always a kind of strange output i could do this way better but let's check what we have now we forget them all and we see that i've just disappeared okay now just just last thing last thing can you see that we have the containers here up and running now let's do something like this let's get inside the postgres container without using postman i could use some some other stuff but let's see here if i do this i see the tables can you see this if i do select from users of course it still works oh then you get everything from here usually here you understand because here now i'm not get accessing that from the backend you should not do this in production of course just to understand but here i could i please don't don't make me write some sql commands here but i could make some inserts select whatever you want directly from the db i could get for example an admin so i have the same power of me installing postgres on my machine but if if i would if i will do i i can do this now let's let's clean it and cleaned up so i also show you a little bit uh some tricks so to delete all the containers this is one of my favorite tips on twitter we can do docker arrange f and this is some i can do something like that so basically i'm saying delete all the containers this is a little bit advanced command but okay okay so we have basically i've deleted all the containers of course these are just two i could have just said 5d five too then let's delete also the images can delete them like a rhyme uh the chef let's try okay the images why are we deleting everything because i'm done with this demo no leaving exactly exactly now but yeah because i want the you got me but um check this now i have no postgres anymore on my pc so instead think about that you should have downloaded the postgres from the official image okay you can you can delete things from here but i'm done i'm done with development okay it's done done with it going going to be a lumberjack yeah yeah exactly yeah yeah yeah i mean i mean for today but that could also be an option so no no i think i think you're done with development for the rest of your life man from from now on you're going to be i don't know a canvas article that would be great let me go back on the interview version perfect okay so what do you think about this uh just let me say that i've honestly used the tub nine a lot during this live stream it helped me okay i've talked a lot but if you checked me typing during the the end points on the controllers it really helped me kind of yeah i was i was i was watching you typing like mostly by tabbing down to tab to tab nine completions and but regardless of tab nine i think that this whole um well interrupted by your time tutorial was extremely useful and i really hope that everyone who was here was taking something and becoming better becoming better in the dev world and just before just before we leave in case we have viewers right now who joined in uh in the later stage of the video um scroll up scroll up to the to the chat or later on check the video when it's offline you will find um you will find a promotion link for tab nine you can all use it for yourself you can use it for free by the way but if you want the type 9 pro we have a promotion link for 50 discount feel free to take all the advantages of it yeah yeah definitely and i'm not using the just let me honestly your time i'm not using timeline just because you are here if you check me every other my live streams i always use that and not just not just today okay i'm not i'm not i know that about you i know yeah and uh thank you so much francesco i had the best time here i think the fastest two hours of my whole life today but yeah the time just flew by we just started five minutes ago yeah it looked like 20 minutes ago yeah yeah it took me maybe less time alone but at least we have explained we are asked to questions but this is what live streams are for so i'm super happy to be honest first of all because i managed to do this i got maybe more problem with the hello world than the whole rest api yeah that's incredible and also a special thanks to to ali to ali afshar our best viewer of the of the live stream strong with us throughout the way thank you thank you so much you really saved me a couple of times so thank you thank you really so much ali yeah perfect i think that we are done less than if we closed in 30 seconds or less than than two hours uh please check the links also in description i think we will also add the code in the description uh yatami just a question for you will they last forever or just for some period we are good we're going to kill we're going to keep the promotion live for for a while so okay so if you're even if you're what even if you're watching this and uh today is june 3rd 2021 2021 if you're watching this within a few days or a few weeks from from today the the link will probably still be a little bit perfect so we'll put those in the description but it's also i think pin it somewhere but yeah perfect so we are done if you don't have any question i can't read the chat but if you don't have any question thank you everyone for stopping by this has been really super funny for me i have done this uh video what i've done today also in an article honest node if you want to check it out but uh today i've done this from scratch i've never and i never did this article lives in this way so thank you yodan for giving me the chance to do this with you so it was more fun more fun the first time i really hope we're going to do this again with another with another one of your hashtags because they're great guys check out check out francesco's note page it for me myself it taught me so much you should also you should also take advantage of this brilliant mind thank you so much you are really too kind yeah yeah thank
Info
Channel: Francesco Ciulla
Views: 1,995
Rating: 4.96 out of 5
Keywords: rest api, node js, web development, postgresql, node js tutorial, sequelize, docker tutorial, docker tutorial for beginners, docker, express js, javascript, javascript tutorial, rest api tutorial, crud api javascript, node api tutorial, node api project, docker compose, docker compose vs dockerfile, yotam shinan, francesco ciulla, nodejs beginner, backend developer, api javascript, api javascript tutorial, node js rest api, docker compose tutorial, docker compose postgresql
Id: HhkwLJCZw2Y
Channel Id: undefined
Length: 119min 41sec (7181 seconds)
Published: Thu Jun 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.