Free YouTube Transcribe

Video transcript

Full Course Web Development [22 Hours] | Learn Full Stack Web Development From Scratch

Mehul Mohan · 222,359 words · 1011 min read

Want to search this transcript, jump the video from any line, or download it as TXT, SRT, or VTT?

Open in the transcript tool

Full transcript

Teaser

0:00hey everyone welcome to the front end boot camp 2022 singular youtube video where we will discuss

0:07about everything that should be relevant as a front-end developer in 2022 and beyond that

0:13includes starting from absolutely scratch with no prior knowledge to actual front-end developer and

0:20this boot camp will be discussing about html css javascript react tailwind react query and github

0:30ci and cd now these topics are extremely important as a front-end developer because they form

0:36the complete backbone of your application from developing to building to deploying everything

0:44is covered in this video if you like this make sure you check out the full stack learning path

0:49on code dam to learn more about how to become a great full stack developer by building practicing

0:56and doing stuff right inside your browser let's go if you're new here make sure you leave a like

1:01subscribe to the channel and hit the bell icon this is free of course and helps the channel grow

HTML / CSS Fundamentals

1:11hello everyone and welcome to the very first video and the very first course of full stack

1:17web development html and css fundamentals course now this course this video you might see in and

1:24when i'm navigation the website that the content already exists sometimes but this is a recreation

1:30a reshoot of the content to make it more embedded with the hands-on exercises which you will be

1:36doing along the way so if you are watching this updated content congrats you're seeing probably

1:41the best course you can ever find on html and css on the internet and it's completely free so

1:48just to give you a brief idea of what this learning path what this course will be about

1:52we will be starting with html and css from bare bones from xero you need not have any

1:59programming experience any programming knowledge beforehand and make sure you're coming from

2:04the internet fundamentals or whatever courses whatever small courses are before this inside

2:10of our full stack web development learning path or front-end web development learning

2:14path or as a matter of fact any learning path which you have picked on code down

2:19so this is a codem.com exclusive course hopefully you will learn a lot of new things and will have a

2:24lot of fun practicing in the in browser exercises along the way and building projects as you go

2:31i'm super excited to start this course with you and hopefully you are too

2:40hello everyone and welcome back to another video in which i want to quickly go through how you

2:45should use codedam.com the website in order to actually learn effectively so we're going to be

2:51exploring that how we can start with coding and stuff very soon but before that i would

2:57just quickly like to point you towards one thing first of all create an account if you already

3:02haven't and once you do that from a computer what you can do is go ahead and go to your dashboard

3:09and right here you're going to see something known as playgrounds click on the playgrounds

3:13part and start an html on css playground when you start a playground like this you will get a url

3:21which will actually set up a development environment within your browser window

3:28now this is something which we will not just be using exclusively obviously you will be using your

3:34local editor as well but this is something which will be super helpful for you when

3:38you are learning this course why because i would recommend keeping a playground tab open in one tab

3:45and the second tab should consist of these videos or these learning paths or whatever

3:49why because although we will have embedded exercises along the way where you can experiment

3:54this is just a free flow where you can do whatever you want right and i'll be using

3:59this as a place where we can also learn about html and experiment with them without actually

4:06just firing up all the things although we will see that how that works as well

4:11so when you create a playground like this you will get a url which automatically updates and

4:16if you refresh this page your code stays that means you can just practice here whatever you

4:21want and come back at any later time and this url will still work and this is a private url

4:27so it's only with you therefore you are free feel free to just just use it however you want

4:34so that is all for this video from the next video onwards let's get into the programming parts

4:38a little bit setting up your text editor what does that mean and yeah super excited to start

4:50hey everyone welcome back and in this video i'm gonna show you how to set up

4:54vs code on your system and why this is required in the first place because vs code visual studio code

5:01is the name of an editor which you can use offline to do the same thing which you will do here

5:07but on your local system right so first things first we are learning about web

5:12development right that means creating web pages that means visiting urls like these and writing

5:18the source code which you probably see you know something like this for example so you'll

5:23be writing this html don't be afraid of the minified syntax but you will be writing this

5:28sort of code and you need some text editor to do that which provides you with all these colors and

5:34auto completions and stuff like this because as programmers we want to automate our job as

5:38much as we can that's why we develop all this nice colors and syntax and

5:43things which tells us if there are any errors and so on so what you need to do first of all

5:48is go to google and write vs code and once you write vs code you're going to see that you get to

5:54visual studio code website which you can download and pick up any vs code version according to your

6:01system right in my case i will go with mac os but if you are running windows you will select

6:05this if you are running linux you probably have vs code already or some sort of text editor but

6:11once you do that once you have vs code or any any sort of text editor you can launch it and the way

6:17you launch it is first one is either you just go ahead for example on mac you can write code

6:23and it will appear like this on windows you can go to start and search for code or from the terminal

6:29as well so once you have installed for example on linux and mac at least that's what i know

6:34go to your command line whatever it is for your terminal whether you call it terminal your shell

6:40and write code and hit a space and a dot now what does this mean that means that open the

6:46current directory inside of vs code and you should know a little bit about this

6:51from if you don't know you can check out the linux clr fundamental scores which is again

6:56a course which will be there but don't really worry about the syntax right now once you do that

7:01something like this should open and obviously not in your case this folder would be blank

7:05so once you open this you'll see that this looks very similar to what we have right here in our in

7:13our you know in our online editor so you have the vs code which gives you an editor all these tabs

7:20and stuff and you get similar things right here inside your code damage data as well the benefit

7:26of this is you have these temporary playgrounds which you don't necessarily need to care about

7:30and you can create all these files and folders and just go ahead and use them and when you do

7:36you actually just get the updated output so you can write your your name is xyz and this will

7:43automatically reflect we handle the heavy lifting for you plus these urls automatically update so

7:48you don't necessarily need to worry about you know your work getting lost for example so it's your

7:54wish you can choose to continue this course on vs code which is also fine or you can choose to stick

8:00to a code damn editor which will allow you to just focus on the important parts that is setting

8:06up your html document correctly but if you wish to do your code if you wish to your course like

8:12this what you have to do is let me just go ahead and actually don't worry about this command which

8:17i wrote right here but let me just go ahead and actually tell you how you can set up a

8:22development server here as well so what you have to do you have to create an index.html file here

8:28you have to write whatever we will be writing for example let's just write hello world for example

8:34and what you have to do is go to this extensions tab here and search for live server right

8:44hit that click on the first result this should be the icon install this live server in your vs code

8:51and once you do that what you'll see is that okay it's ready right the next thing you need to do

9:01is right click on this file and click on open with live server

9:06right and that's it once you do that you will see that you have a browser window opened and now if

9:12you do hello worlds like this you will see well it does not it does not automatically reload because

9:19you can see a small notice library load is not possible without body or hit tag so we'll learn

9:25about body and head don't worry about that yet but just make sure you write all your code inside body

9:30for example so once you do that and now if i hit anything you'll see it automatically refreshes but

9:37i mean you know just to start i would say rather stick to this because this is much more simple

9:42in terms of the changes which are reflected you don't necessarily need to set up anything

9:46right here but that's how you can and you should set up vs code on your systems it will be super

9:52important as a developer when you're working on your own projects and make sure you have that

10:02hey everyone welcome back and in this video let's just go ahead and actually write our first

10:07ever html document now first things first well we already have written one

10:13but let me just go ahead and walk you real quick what exactly is happening here because this

10:18whatever happening whatever is happening here this is very close to how real world things

10:23actually work as well there is no abstraction here there is no magic work going on so let me tell you

10:28so the first thing is you see right here we have a terminal environment with us and it gives you

10:34something something where you can actually write stuff so what is the difference between this and

10:39this file well you see this computer right here this is this is an actual computer which is

10:44connected to a computer running in the cloud now you know from your internet fundamentals course

10:51that you need a server to deliver a web page to a client right whenever you write google.com for

10:58example there is a server owned by google.com which sends you the html so whenever you go

11:04to google.com this html this nice page which you are seeing is actually this html code which your

11:11which your browser is getting and how does this html code arrives at your browser that is because

11:16some computer some server somewhere in the world somehow figured out that hey this guy or this girl

11:23needs uh needs to see google.com and i need to send him or her this page right so that's how

11:29it works but what is that computer where is that computer i mean as a user you don't care but when

11:35you're creating a website when you're creating something you need to care because that computer

11:40is the one which will deliver the content so what is happening here is that we have a computer here

11:47which is a remote computer and that is connected to this file system so what that what do i mean

11:53by that for example let's say i create a new file this is so cool dot txt hit enter and go ahead and

12:02write ls here which is list files you see i get this is so cool.txt file here if i write hello

12:09world in this file for example what is happening here is that we have actually modified this file

12:15on the server so we can see that from this is so cool.txt right so you see we get hello world

12:22so that's fine this file system is synchronized to this remote computer and this is our window

12:28of actually running any command on that computer but how do we serve this file then how does that

12:34appear here the reason we do that is because we run a server now you don't necessarily need to

12:40worry about this command but whenever you refresh this page whenever you do anything this command

12:45automatically runs and what this means is that we are serving this file at this page for you

12:52so whatever you write here if you open this in a new tab and if i go to index.html and write hello

12:58whatever you write here that will automatically be fetched right here just like your vs code live

13:04server extension right so you don't necessarily need to worry about any of these details

13:09don't necessarily need to go any in any of these details i just wanted to give you a picture

13:14of just just telling you what exactly is going on so that you don't necessarily feel lost when

13:20you're into this interface but you will be using this interface in your exercises as well which you

13:26will see along the way and this will be super fun because this is a real environment when you are

13:32working on a local system that's exactly what you will be doing as well the live server which you

13:37use runs exactly this this thing somehow more or less but abstracts away this terminal thing so you

13:44can just you know for here as well you can just minimize that if that bothers you just keep on

13:49working here so technically a hello world document in html is just a hello world and your browser

13:55will be able to actually show you hello world here so you have written hello world technically

14:01speaking right and we don't necessarily need anything else i'm also going to delete this file

14:07so that's it once you write an index.html file once you create that and if you're on codem.com

14:13that's how you're going to write it if you are on vs code for example if i go back to vs code

14:20and if i write hello world hello world like this hits hit save and if i click

14:26on open with live server you can see i get the same output right pretty much the same thing

14:31which you get here now i have shown you on both the places but i'm going to be continuing working

14:37with the code down playground you can copy all of the things which you do right here run it run

14:42it with a live server and it will be exactly the same thing so you can continue wherever you want

14:49so yeah that's pretty much it for this video hopefully you were able to write your first

14:54hello world into web development this is the seed of something big this is the seed of your web

14:59development tree which will form i'm pretty sure all the best for your journey and this journey

15:06will take time it's not easy it's not something you can learn overnight but it will surely

15:12and definitely happen if you keep on working on these practice exercises these labs which

15:17you see on code dam these videos which you complete and you will definitely get there

15:27hey everyone welcome back and in this video let's just go ahead and discuss about comments in html

15:33and quickly go over through why you would ever need them as well so you see although we don't

15:39have a perfect html structure html document here because if you go to sites like google for example

15:45and view page source for them you will see they actually include some cryptic

15:50you know doctype html and then i don't know exactly what that is but you see that there

15:56there is actually code here but we haven't written any sort of code right it's just hello world as

16:01an english word so that's fine we'll get into that but before that you could see whatever

16:08i'm writing here that's actually appearing on the page and as developers what we do a lot of times

16:14is we just leave comments at different places commence is just a fancy word of saying that hey

16:20i want to write some english sentence or something but that necessarily is not a code right and i

16:26don't want it to be parsed as a code so what we can do is we can go ahead and use this syntax

16:33which is if you look close enough is a angular bracket an exclamation mark and two dashes

16:40and you need these two dashes and everything in order because syntax highlighting here

16:45would also help you you see that syntax highlighting is not necessarily working here

16:49and sometimes you know you will see that it is you know it's still working kind of because html is a

16:55really bad programming language if you say like that because it is very forgiving but the way

17:01comments start is like this where you have an angular bracket exclamation mark and two dashes

17:07and whatever you write inside of this whatever i mean you can write anything and everything

17:13it will just be not rendered by browser at all right and the way you close the comment

17:20is two dashes again and a square bra and an angular bracket so you see if i write something

17:26outside this that appears just fine but nothing inside this comment block so that is pretty cool

17:33also if you go ahead and take a look inside this pages source code you will see google chrome

17:39actually turns this into green and the screen block is usually means that this is a comment

17:45so that's it that's how you write a comment so what you can do now is just under hello

17:51world you can write something like hey i did my first html program error you know and you can

18:02include any sort of emoji any anything you want basically like i said nothing escapes the comment

18:08block it's like a black hole for html whatever you write here it does not get out on the page

18:20hey everyone and welcome back to another video in which we'll be learning about

18:24tags in html and tags is super important the fundamental building block of an html document

18:32and my document i just mean this html file so i'm gonna remove this and we're gonna head over

18:37to google again and if you take a look at google's source code which i did by right clicking here and

18:43clicking on this view page source what we see is that this document let's just ignore the doctype

18:50html for now this document consists of these purple things these purple stuff right html

18:56is purple script is purple if we go a little down and i believe let's just enable line wrap as well

19:03so if you go a little more down you will see i mean this is google is

19:08basically garbage let's not take example of google let's go to example.com instead oops

19:15and not the inspect but right click and view source ra this is this is good so you can see

19:21example.com consists of multiple purple tags and what these things are these things are actually

19:28called html tags now what does that mean well you see that the only information your browser

19:36is getting from that remote server that remote computer is a text document right it's a text file

19:44but it has to construct a ui a user interface a beautiful user interface out of it

19:50which might have a favicon here like this fancy icon which might have text here in the browser

19:55which might have animations which might have layouts which might have colors and all that

20:01stuff so we need to deliver a lot of information like what is animation what are the colors what is

20:09the content what's the font size what's the font family that means what's the font type which thing

20:16is a link which link should point where and all this stuff we have so much information to tell the

20:22browser that it's simply not possible if you're if you start writing it in english or something right

20:28i mean it's possible but you don't get the idea that you you know the browser will be confused

20:34what to do so what we developed is actually called html which is hypertext markup language and this

20:40language consists of a lot of tags these tags tell the browser how to behave on a certain feature

20:48for example this title tag right here which you see example domain is responsible for showing this

20:54example domain in the title if i for example go ahead and use the same thing in my playground here

21:02example domain one two three four five like this and open this in a new tab you can see we get an

21:08example domain one two three four five like this in the browser right so this title tag is one of

21:14the many examples one of the many tags which we will use but that's how the thing works and

21:20you can see that we although we are writing only title it still works in our case right so why the

21:26hell has this person whatever the developer was doing here has written all of this stuff what's

21:33the point and we'll get to that we'll get to that in the next video but to understand what our tags

21:40tags are simple well fundamental building blocks of html documents which tell the web page somehow

21:49how the content should appear or how the content should work or even how the page should behave

21:54in this case just setting up the title so we have a lot of tags for example a p tag

21:59which stands for paragraph can display just a paragraph a div tag for division and so on

22:05we'll discuss that won't want to rush into that right now but don't worry we'll discuss that

22:12so yeah that's pretty much it for how the tags work tags 101 we'll get into more information

22:18about an html document tags attributes and so on really soon from the next video

22:29hey everyone and welcome back to another video on tags in html and css we're going to stick

22:35with this for a long time and we're going to be discovering a lot of tags along the way but

22:40i want what i want to go ahead inside of tags is is styling with simple html tags now although we

22:47discussed like what could be the behavior the behavior could be colors the behavior could

22:52be ui the behavior could be style sheets which will eventually get into but the simplest one

22:58is headings right h1 h2 h3 h4 h5 h6 this goes up to h6 and you can say i am h1 tag like this

23:09so what's happening here let's take a look inside of html the first thing you have to realize there

23:14are two kinds of tags the first kind of tag is where you open something you open a tag like

23:21this and then you close a tag so if you look close enough you will see that i'm closing it with the

23:27forward slash like this right and then i'm writing the same tag name basically so that means whenever

23:34you open a tag you have to close a tag not necessarily with some tags which you will get into

23:40but it is necessary in this case right so let's say you know we have already seen title tag how

23:48it works so a title lag is also a opening and a closing tag so it's not a self closing tag

23:54p tag is a paragraph tag you can see it's also opening and closing tag so all these stacks of

23:59heading you will see i am h2 tag you also have to close them right that is the concept in html

24:06you open a tag you write whatever you want and then you close something if you nest tags for

24:12example let's just go ahead and see what nesting means so i opened and closed a div tag this is

24:17a this is a block tag which just means that hey you're trying to create some division on the page

24:24this does not necessarily do anything on its own that means if you just write content inside it

24:28it'll just appear plain just like p tag but it's just for you know web developers love to use div

24:34tags everywhere so what do i mean by that let's say if i open an h1 tag now i have to close this

24:42h1 tag in order that means you can see what's the hierarchy div opens h1 opens h1 closes and then

24:50div closes so it's not like div opens h1 opens div closes and then h1 closes you will see that it

24:57still works in the html but let me tell you html is a bad programming language don't consider html

25:06to be a good programming language because html is super forgiving right html will allow this code

25:13html allows any sort of code i mean you can never really crash an html document as such because the

25:19browser will try to make sense of anything and everything you throw at it that's why our just

25:24our hello world also works whatever we write also works without any tags but technically you need

25:30tags your browser needs stacks to understand so the one important thing is always try to make sure

25:38that your tags are closing in order that means div h1 h1 div it should always happen in this way

25:46if it does not then your html will be considered as broken your browser still might be able to

25:52make sense of it somehow but it could lead to problems so that is one important thing

25:57which you should definitely keep in mind the next thing is super simple i mean if you just

26:02keep on doing this you will soon realize that let's say if i duplicate this for h4

26:10and h5 you would see that after h6 i mean you will see a couple of things first of all

26:19you see this is the h6 although you know the text is wrong but you can see it by the size

26:24so it's 6 h5 h4 h3h2 h1 but there is no h7 so you see h7 also does not get the syntax highlighting

26:32so that's a little bit of hint from our code damn website as well as the editor

26:36that hey this stack probably does not exist right so you can see whatever you write an unknown tag

26:42in html it still is not gonna complain to you but you can see that you lose that syntax highlighting

26:49and it also appears just like regular text right so you don't necessarily need to use this

26:55so yeah i mean this is a very basic tutorial about tags again you need to spend a little bit

26:59more time with tags we'll be working a lot with a lot more tags eventually but this is a start

27:11hey everyone and welcome back to another video and in this one we'll be reviewing a super important

27:17thing a super important concept which is around attributes in html now let's just go ahead and

27:25first of all see what i'm talking about so i want to create i want to create a link which takes me

27:34to codedam.com fair enough i have written that in english but it does not work there is no link here

27:41so how do you create a link well you guessed it right you have to create another html tag

27:47right but a link is a very generic thing right so you cannot really just have a tag for example for

27:55go to google right that wouldn't make a lot of sense because now let's say if i want to go to

28:01google.com a what would i do there is no way for me to just create those many infinite tags so

28:10what html allows you to do is that for these generic purposes where you can supply more

28:17information to your tag this is by the way this stands for anchor tag a tag and it's used to link

28:22pages different pages that's like you know the og tag of the internet because internet

28:28literally the web literally means a web of interlinked pages so a tag allows you

28:35to link one page one page to another and so on so what this a tag allows you to do and a

28:41lot of other tags as well is it allows you to set a certain attribute an attribute is

28:46just some additional information to that tag which may or may not be required for that

28:53tag to work properly so what do i mean by that in this case in the a case the anchor tag

29:00the important attribute is to tell where do you want to go otherwise it cannot work right

29:06so what we use for that is an attribute called href and the way we give an attribute is a space

29:12after the tag name and that attribute name and an equal to sign with the value inside quotes now

29:21you would see some people just writing quotes without value wins without code and it works but

29:26this is not recommended this is not recommended because if your value has spaces then this will

29:31break so always always try to put your values inside double quotes single quotes also work but

29:37i prefer double quotes so yeah that's it so now we can go ahead and do give it a link https codem.com

29:46and you can see it turns it into a different color because this is like the default browser style

29:51now if i open this in new tab because it won't allow me to just go into

29:55i mean we'll talk about iframes later but it will not work if i click it right here

30:00if i go here and if i click on this you can see my browser window got redirected to codedam.com

30:07right so if i click on this again you can see it works just fine and you can see by default when

30:12i'm clicking on this you also see that turns into red and all of this behavior is browser's default

30:18things which are customizable you have that power to customize them how we'll look into that but

30:24just know that you can customize all this behavior so this tutorial was meant to do two things first

30:30thing is introduce you to anchor tag and second thing is to introduce you to attributes and

30:35href is just one of many many attributes which are there doesn't mean you need to learn them

30:41all but that does mean that hey you need to be aware about what attributes fundamentally mean

30:48they mean that you can supply additional information to the tags on the page right

31:01hey everyone welcome back and let's just go ahead and quickly discuss about paragraph tag and also

31:07an important concept in this video so first of all if you can observe what's exactly happening

31:14here is that you will see that everything in in is in its new line right so h1 imh1 tag is

31:22newline h2 is newline s3's newline and so on so what is happening here exactly so what i want to

31:29discuss in this is paragraph tag and a couple of other tags but i also want to discuss the

31:34concept which is so important that you should be just just make sure that you understand this

31:41because this will be a very important thing which you will also discuss in the css tutorials there

31:46are two kinds of tags in html roughly speaking and majorly speaking actually the first kind of

31:54tag is a tag which is called a block tag now what this block tag means these are the tags which take

32:02up a complete block of row on your html document so you can think of these tags as you know just

32:10just completely taking up the space so this h1 tag does not take the tag where the content ends it

32:17actually takes the full tag right and i can help you with that if you just excuse me for using css

32:23here right just excuse me for using css this is just for demonstration purposes don't worry about

32:29the syntax we'll discuss this when we start css but if i go ahead and give an h1 of background

32:38oops background red you will see oops what the hell am i even doing h1 of background red you

32:48will see that this tag right here you can see it takes up the full full space it does not end here

32:54so h1 is a block tag similarly h2 is a block tag similarly h3 is a block tag

33:00h4 is a block tag h5 is a block tag and so on how do we how do you know that h1286 is a block tag

33:09well you don't this is just this is just something which is there right you have to

33:14you will eventually know which tags are blocked which tags are inline the second tag

33:19but yeah right now whenever you come across a certain tag just try to put it a background if it

33:23is trying to span the whole row then it's probably a block tag now second kind of tag is called an

33:30inline tag let's just change the selector from h6 to a and you can see now the anchor tag which you

33:38have at the bottom is slightly different you see it does not take the full width so what's

33:43happening well the thing which is happening here is that a or the anchor tag is actually an inline

33:50tag so what's the difference the difference is that if you have a sentence let's say if i have

33:59a div tag for example right and if i am if i am writing a sentence and if suddenly a block

34:11tag comes in then it gets its new line wait block tag says hey dude i'm not gonna continue

34:17in your own line i'm gonna get my own new one and that's it and that happens again and again

34:24but if i am writing a sentence like this and then an inline tag appears you can see it just

34:32continues in that right so this means i can just link to something in a paragraph and if you think

34:41about it it makes sense i mean the creators of html people who actually designed these block

34:47and inline tags they thought about this that most of the people when they will be writing content

34:52on the web they would probably be putting links inside paragraphs right so the paragraphs need

34:57to just continue as if nothing happened they don't necessarily want everything on a single new line

35:03but for heading i mean it makes sense you would not necessarily just be writing something in a

35:07paragraph and then suddenly the text become bold and four times larger and you know just

35:13continued working like that so what we came across is the notion of these two things the first thing

35:20is an inline tag an inline tag is nothing but something which just takes as much width as it

35:26wants and does not spawn a new line basically and the block tag which is something which

35:32takes the complete width of the screen of the container i should rather say not the screen

35:38and yeah just does not let anyone else occupy any any sort of space

35:44so paragraph tag again here is an example of a block tag so if i do this is a paragraph

35:52and this is some text so you see by default if you are writing this text this is just inline right

35:58because you don't have necessarily any text so of course you wouldn't expect every single character

36:03to get its own line right so that means everything is in line here so this is in line but if i switch

36:09to a new tag called span you would see that this is actually inline right paragraph tag is block

36:18because it gets its own new line and does not allow entering this line above but if you switch

36:24it to span again you get you know it's it's fine spam says hey it's fine just share a line with me

36:30so yeah this was an introduction to paragraph tags span tag block tags and inline tags and don't

36:38worry about them like i said you will eventually learn about a lot of these tags and what their

36:43behavior is if you would have guessed div tags if you would have guessed by now diff tags are

36:48actually block tags right so div tags just create a division that means if you're writing this thing

36:55it will not be just continuing with the div itself right div says that hey this whole block is mine

37:02go ahead and continue from the bottom right and it makes sense it does not make sense for your

37:08inline tag to contain a block tag right because the point of an inline tag is to actually be just

37:14limited in width and if your inline tag has a nested block tag that does not make

37:19a lot of sense but don't worry about that yet just understand that paragraph tag is

37:24nothing but a block tag which just creates a full container with area for your content inside

37:32right that's it this is all a paragraph tag is similarly div is also all that else right they've

37:40also just you know just creates a space the only difference subtle difference you can say that

37:46browser actually styles the paragraph tag a little bit different you can see browser by default gives

37:51us a little bit of margin at the bottom which is this white space which you see if i switch

37:56to div for example here instead of paragraph what you will see is that that white space is

38:00gone right so although it still is a paragraph tag uh although still it's a block tag but that white

38:06space is gone basically so you don't have to worry about that but yeah i won't necessarily say worry

38:11about these details yet but just understand that's how the things more or less work in the html space

38:24hey everyone welcome back and in this video let's just quickly review and in a couple of further

38:29videos as well just quickly review some common html tags right so i'm going to get rid of the

38:34style tag which we'll get to when we start css but the next tag which i have in mind is a button tag

38:41so a button tag basically like the name says it creates a button i am a button on the screen

38:49now you can go ahead and click on this you know and pretty much that's it that's that's all this

38:55button do but what i want to touch into this video is that why do we have i mean like i said we can

39:03pretty much customize almost every single aspect of these stacks through css when we start css

39:10i can make the h6 tag as big as h1 and h1 tag as small as x6 so i can reverse this

39:17behavior right away when we start with css right when we are working with css

39:23i could create a div as a button i could create a button as a div and you might have

39:28just guessed that button is also a inline element at this moment right because the text continues

39:35now the reason then why do we have these names all over why don't we just have divs

39:42and you know title for example some certain tags which have special meaning

39:46and then all of the tags should be div why don't we have that that is because html as a programming

39:53language as a markup language was built to have a semantic some sort of semantics why because okay

40:02it's fine i mean visually i can tell that this is the largest heading this is the smallest heading

40:08but your code should also be able to tell that without actually being parsed into the web page

40:16why is that important that is important because of accessibility reasons for example if you have

40:21an h1 on the page that usually means that hey this thing is important this heading is important why

40:27because your browser knows your accessibility readers on people who are disabled know that hey

40:34this is an important heading that's why it is h1 similarly if you have a button your accessibility

40:40reader knows that this is a button which could be clicked most likely your browser would be able to

40:46tell that to your reader right whatever it is so the reason for you know first of all if we

40:51just used divs all along it will become super boring real quick so that's one of the reasons

40:55and the second reasons is to actually give your code meaning that's why we have all these names

41:01to these stacks right but yeah just to discuss a button that's how you create a button that's

41:06pretty much it we can customize this behavior and we can add a lot of interactivity with it

41:11once we learn javascript then we can attach event handlers that when i click on this let's

41:16say this h1 tag should turn red or this h2 tag should disappear or this h3 tag should change to

41:24you know a bigger text font size whatever so we can do all that fun stuff once we

41:29learn about javascript but let's not get our you know expectations real high right away

41:34there's a there's a bunch of work that still needs to be done um so yeah that's pretty much it for

41:39this video i hope you understood about button tag but more importantly why button tag is right

41:51hey everyone welcome back and in this video let's just go ahead and take a look at

41:56image tag in html now image tag is of course really important because images are an integral

42:03part of our communication and how we perceive the world so html allows us to embed images directly

42:10with the ease of a single html tag so what i'm going to do is i'm going to create a new tag

42:16right here after creating some space for me and i'm going to say img and one thing you should

42:22note here is that i hope you remember our talk about the block not exactly the block sorry the

42:30self-closing tags and the tags where you have to close it again right so so far whatever tags we

42:37have seen they have to be closed for image tag that's not the case that means if an image tag

42:45is there then it need not to be closed right you would not write an img like this this is not

42:52valid html and you can see your editor is also reflecting that because it does not have a syntax

42:58highlighting so image tag is a tag which is an inline number one inline tag and number two it's

43:06a self-closing tag that means you do not need to close the stack and it seems like a fine decision

43:14to me why because once you have an image i mean you could technically think that hey

43:20i will specify the url or something here but that's not how it works you just specify a url

43:25as an attribute and that's it you're done then the image appears and then you customize the width and

43:30height of the image also through the attributes so that means it does not need any content that

43:35should go in between right so that means it does not need a closing tag so therefore therefore you

43:40don't need to include a closing tag and as a rule you should not include a closing tag so i just

43:48have an image tag but i cannot see anything so what the hell is happening well nothing

43:52is happening the reason for that is because you haven't specified all the relevant bits and pieces

43:58the first bit which is the most important thing is that you have to specify src the source of

44:03the image and this should be a url right just like every single page on the internet has a url your

44:11images also have a url so if i go to google for example and if i let's see if i right click oops

44:18i think google has some game or something so let's just go to images section and right here you would

44:28be able to see i have this image for example if i right click on this and open image in new tab

44:33you will see this is a url which i have right and if i copy this and if i go to my web page again

44:40and paste this right here you will see i have an image with me so this image is embedded directly

44:46from this url you can see into my web page now whenever somebody visits my website like this they

44:52could see a nice big image right so that's cool but let's say i want to customize the width and

44:58height for this now you could technically go ahead and specify a width and a height attribute here

45:06so 200 and height is 400 300 but don't do this trust me don't do this there are better ways

45:13to do this with css and this is also deprecated that means it will work for legacy reasons because

45:20you know the older web used to use the syntax but the way we do it now is we do it with css

45:26right so what does that mean that means we will be using the css programming language to customize

45:33the dimensions of this image for now it's fine i mean for testing purposes it's fine but whenever

45:39you're writing applications make sure you customize the images with css and not with

45:43these width and height attributes with html let me just quickly tell you one more thing the thing is

45:49you might find some tags which work right but are deprecated so what are these tags these tags are

45:57usually some tags which have been upgraded to some modern alternatives either in html itself

46:04or with some css rules for example a deprecated tag i can think of is a center i mean it's so

46:12deprecated that the highlighting has also stopped working um this is some text in center right

46:21so you can see although our text got in center because browsers apparently still support it

46:26but this tag is deprecated right this stack should not be working you should not be using this

46:31instead again you should be using css for this which we'll see eventually but these

46:36are some of the examples of deprecated tags and deprecated information and you should be very

46:41careful whenever you are learning from outside resources i mean at goddamn i can guarantee you

46:47that as long as you are on code damn you will we will not be teaching you any deprecated or

46:52older practices but just just keep that in mind because with web development with html

46:57html has been around for 20 years right and a lot of modern syntax has just been developed

47:02in the last four five years so you don't necessarily want to learn bad practices so

47:07that's one of the examples plus again like i said there are better ways to do this on image

47:11tag again which we'll take a look at when we start css but that does the job for now

47:22hey everyone welcome back and in this video what i want to do is actually go

47:27ahead and explore a new tag in html5 which although has been there since 10 years but

47:34still it's a new standard in html and that is how you can embed videos so if you go a little

47:41back in time just to share a quick story with you the support of videos was actually very very bad

47:48in terms of how the browsers could play i mean images were fine text was fine but videos had to

47:53you just have to install adobe flash player download codecs do all sorts of fun stuff to

47:59actually get something working and this is i'm talking about 2005 2006 time since then a lot

48:07has improved since then what has happened is that of course there have been new standards of video

48:14that allows us to transfer videos more efficiently but the support of the browsers have also majorly

48:20improved and that means browsers now allow you to embed videos natively that means just like

48:27an image an image can you can just have a raw jpeg image for example this imagenzin.jpg so i'm

48:33assuming this is jpeg you have this raw image with you and you can embed this on your page similarly

48:40you can do the same thing with videos right and if i go ahead and copy this example video with me

48:47what i can do is make some space for myself first of all and write a video tag like this and unlike

48:54image tag although you might think that video tags should technically be also self closing

49:00because well it sounds like you know fun because you cannot really have anything inside of video

49:06as well but video tags are actually not self closing right so you have to close a video tag

49:12so what this video tag does is that it takes up a source as another tag and this source would only

49:18work and sources like you see you can see source is not a uh you know a tag which needs a closing

49:26tag so a source what it does it it embeds or it tells this parent video tag that hey what is the

49:37place where you should be embedding or where we should be looking for the embedded video

49:42and we tell that hey the source is this video right here and you can see it it kind of gets

49:48embedded right but you can see i'm not able to do anything it almost seems like this is an image

49:53and that is because we do not have controls over this video right i cannot see a play pause button

49:58anything like that so how do you add controls you just write an attribute and that's it you

50:04don't necessarily need to give it a value as long as this attribute in itself is present

50:09that is also fine i mean this syntax is also fine you can just leave attributes like this if you

50:13did not know this before so now you can see once i add this we have controls now right here and now i

50:19can play this video and this video plays which is pretty cool now one important thing which you have

50:25to notice here is that i'm using a raw src video link you know this video is ending in dot mp4

50:34dot mp4 actual mp4 this is an actual video which you can just download and play into your vlc media

50:40player a lot of people might confuse this with a youtube video for example so if you go ahead on

50:46youtube the youtube video starts playing and you might just copy that youtube link and paste it

50:51here that will not work because what you're trying to do is you're trying to paste a video you're

50:57trying to give this source a video but you're actually giving it a web page right it's just like

51:03saying that hey i'm just going ahead and pasting it like this this will not work because this is

51:08not a video it cannot play it right this is a web page so what you need to do instead of this is

51:14actually make sure that you have a valid legit video from somewhere and you can just use this

51:21w3schools example if you want but this will not be useful in case of youtube youtube for example

51:29how you would actually be able to embed a youtube video is when you click on the share you will get

51:34this url but this is not what you want you want to click on this embed somewhere and you see

51:38this you get this weird html string right you can copy this and you can go ahead inside your editor

51:46and you can paste this iframe thing the whole thing and if you go down you can now see it's

51:51it's pretty cool right that you're able to embed a video directly right here and that's me by the way

51:58so um you're able to do that but what is this iframe thing and why this is not a video well

52:05first things first we'll discuss about iframe later the thing iframe does is it actually

52:09allows you to embed full web pages inside and that is required because youtube is clever

52:15youtube does not give you the raw video and why do they not give you raw video because then they

52:20will lose this player this awesome controls and the branding that the fact that this video is

52:26actually on youtube because you know youtube wants to say that hey

52:30whenever you are embedding this video on somewhere we want to advertise ourselves as well that you

52:34are embedding this from youtube so that is why instead of giving you a raw video link

52:39youtube actually gives you an iframe that is it gives you a web page to embed

52:45so that's that but there are multiple use cases of iframe which we'll discuss but other than

52:50that what you need to realize is that video tag is only meant for videos which are raw right they are

52:56not web pages these are actual videos which are present right so you have to be careful on that

53:08hey everyone welcome back and in this video let's just learn about tables and why do you

53:13need them well tables is something which i believe everyone would be able to relate to

53:18it's just the organization of data in a proper way and you would be surprised to know that

53:23a lot of html layouts the complete layouts of the website were actually done with table tags

53:29so i'm gonna just start a real quick with table because it's just gonna make so much sense to you

53:33in terms of how the html tag names are so of course table has an open and a closing tag

53:40which defines a table it does nothing on its own it needs more data so the first thing you have

53:45is a t head which is a table heading right again has an opening and a closing tag

53:50and what you can do is you can start a table row like this so what does this mean this means just a

53:58single row of information and a table row needs a table data right so i can have a column one

54:05i can have a column two i can have a column three right that's it now

54:12the next thing is well i have the table head with me and you can also i think make this th

54:20to give it a feeling of table heading right so it just bolts your text nothing fancy

54:28then what you can do is use a t body which is the table body text

54:32and again the body will consist of multiple rows so i can say this is you know call one value

54:42and this should not be th it should be td which is stable data and call to value table data and so on

54:50call 3 value for example right and you can see even though i'm not organizing it explicitly

54:56in any sort of layouts or anything it just falls into layout properly automatically right and you

55:01can see i can just create multiple such things and although there is no borders on anything

55:06which we can also add but you can see it still we still get a nice table look right with this

55:13actually let me just go ahead and quickly give it a s a border so that we are able to

55:19see what the actual table is and again i'm gonna cheat here by using css so i'm gonna say trth

55:27td basically giving everything a border of one pixel solid black

55:33right so you don't necessarily need to worry about anything right now don't worry about this thing

55:39we'll discuss that but now it just looks a little bit nicer right in terms of what the boundaries

55:43are now the fun part in table is that you can actually spawn certain cells to have multiple rows

55:51or columns right so what you can do is you can say this this element right here this call one value

55:59should have a call span of two that means it takes two columns instead of one and then we

56:06can just throw away the third value right so you see now it looks kind of like you know

56:12just having two values i mean depending on your data it might make sense sometimes it might not

56:18similarly you can give this table data a row span of two right so now what you can say is you can

56:25remove the third value from the next row because you don't need that so you can see now you have a

56:31table data with a call span of 2 which looks like this with a row span of 2 which looks like this

56:36so you can have all sorts of fun stuff and you can imagine if you scale it up to the whole page size

56:42you can create some pretty awesome layouts right with a sidebar with a

56:46um you know a sidebar and a content area header and everything but the problem here

56:53with this this sort of designing a web page is that it is ridiculously hard to make it responsive

56:58what do i mean by responsive a responsive is a web page which just adjusts its layout

57:03automatically with the screen size right so it works properly on desktops and it works properly

57:08on the mobile phones that is something which is extremely hard to achieve with table based

57:13layouts right so therefore we will only use you should only use stable for actual tape tabular

57:20data representation never for layouts right that those days are gone those days are long gone

57:27but yeah you should be aware about tables and how to create simple data visualization because

57:32sometimes you know if you're connecting a back end and you're getting some data

57:36which you want to display in a table that's that's something you should know out of the

57:40box right you don't necessarily need to just reinvent tables in css all the time

57:50hey everyone welcome back and in this video let's just quickly go ahead and take a look at what

57:55forms are in html and forms basically allow you to take input from user to your backend servers

58:05or to your web application and what does that mean that means if let's say you have seen sites like

58:12facebook or google which allow you to log in sign in create accounts and do all sorts of stuff but

58:18when you sign into these websites what happens is that you have to enter your username and password

58:23right so these are input fields where you have to enter this enter the stuff now you accept those

58:30input fields data with certain html tags again which are special tags they are not like p or diff

58:37um but form is a parent container of those stacks which just holds all these tags together which are

58:45required to take the input from the user without any more talking let's just actually create a form

58:51tag right so what this form tag does on its own is nothing you have to specify some input tag

58:59inside this so let's say i specify just just this input and again like i said for image and video

59:06tags input tag is also self closing that means you do not need to have an input tag like this right

59:15because all it does is that that is just creates a space on the page for the user to type some stuff

59:21now you can actually type some stuff right here now this input tag however is super interesting

59:28because you can give it multiple types what kind of input do you expect from the user

59:34so what you can say is input type and now you can see there are so many types right here which

59:39you can i actually encourage you to play around with but i'll just stick with some common ones

59:44so i'm going to start with the text one which is something which the browsers

59:50use by default if you don't specify or what the browsers fall back to if you just enter any

59:56gibberish value right so that does not exist you can see input type text is something

1:00:01which pretty much accepts well text right so it accepts every and any sort of text

1:00:06that's it nothing multi-line nothing as such but just you know single line text

1:00:13well let's just take a look at something like input type password for example so the password

1:00:19field you can see immediately my password manager also kicked in i used lastpass but you can see my

1:00:25password manager kicked in and what i can see is my text which was i was able to enter earlier is

1:00:32now all dotted right so you cannot really see what i'm writing that is important again if

1:00:39you are trying to create a login form you want to have a password field but that's how you do it the

1:00:43only difference between password and text fields apart from the accessibility and all this cool

1:00:48stuff which happens that your password manager is able to stick to it is that it hides the password

1:00:54it hides the text which is entering all right moving on to the next tag let us see um

1:01:01we have number right so the number field only allows you to enter numbers and it also gives

1:01:06you a small slider if you have to use that if you try to enter text it will not work right it will

1:01:11just not take your input now this in no me no way means that the user cannot technically input text

1:01:18on the back end so you should not ever rely on the front end input of the user always but it's just

1:01:24a nice validation where you can just restrict a person to only enter number on the front end

1:01:29then there are things like input type file for example which give you this button where you can

1:01:36prompt the user to upload something right then we have some special things like input type email for

1:01:42example right and what i can say right here is that well it still looks like pretty much what a

1:01:50regular text field would look like right so what's the difference why does this type email exist

1:01:55well you see what we also have is an input type of summit right and what i can say is

1:02:04that this email field is required so now if i try to write something and click on summit

1:02:10you can see that the browser actually gives you an error message by default it says please

1:02:15include and add the rate in the email address this email address is missing and add the rate right so

1:02:20browser till certain extent is able to figure out that an email address needs an ad symbol

1:02:26and you know still not not right because browser says that hey you're still missing some

1:02:31information and if you write something complete and then submit it then it kind of works and the

1:02:36reason it refreshes is because when you click an input type summit something interesting happens

1:02:43which is now we are discussing which is with forms so what a form tag does is it majorly takes

1:02:50two inputs the first one is a method where you specify a get and a post so let's say if i write

1:02:57get here and an action an action is a url where the input of this form should be redirected so

1:03:07just just stick with me here so let's say i have an action of summit right and let me just go ahead

1:03:14and open this in a new tab so pay close attention to the url the url right here is whatever this is

1:03:20and nothing after that right so now if i go ahead and it hit like mayhole at the rate codedown.com

1:03:28go damn.com because that's that's what it'll accept as an email and click on summit you can

1:03:34see well we get summit and basically a question mark and nothing so where did that form data

1:03:40go well technically speaking when you have a method of get it should actually write all that

1:03:47information in the url itself but the reason that did not happen here is because we are missing a

1:03:54couple of attributes the first attribute which you are missing is a name so a name is like my user

1:04:03user's email for example if this is something i give and this is required and let's just go

1:04:08ahead and try this again what will happen is if i write maehol at the rate codedown.com and hit

1:04:14summit you will see inside this url if i copy this url and paste it here you can see this is where i

1:04:21got redirected summit question mark then my user's email is equal to maywell at the redcoatdom.com

1:04:30so this is pretty much something which we probably are getting ahead of ourselves right now we'll

1:04:35discuss this more when we start with javascript but what's happening here is that we are sending

1:04:42the details of this form inside of the url so whenever you use a get it redirects the form

1:04:49with the wherever the route you have specified and all of the data is combined inside of the

1:04:54url right now you can have multiple such things now you are now we are talking right now you can

1:04:59say something like register and have an input type text name username for example and then

1:05:10required for example right so now you have a couple of fields which you have to enter

1:05:15and if i go ahead and refresh oops if i go back and refresh this you can say mahul mohan

1:05:24and if i hit summit you will see i have a username of mihul mohan and my users of this thing right so

1:05:30this information is something which appears right so this is one way right where we are actually

1:05:39the con of this is we are actually exposing this data inside of the url which sometimes

1:05:45is fine sometimes it's not fine so that's one way another way is we actually change this to

1:05:50post but now that's something different that's that's something we would actually take a look at

1:05:55when we are learning about servers and javascript maybe or something how to extract that information

1:06:00out but forget i think it's pretty simple and it's pretty visual as well how it works so that

1:06:06is how you actually communicate your data from front-end to back-end as well so maybe this

1:06:12url is running a back-end script which just takes out these parameters and extract out these values

1:06:18with the key names as well right so that's how you communicate your data from front-end to back-end

1:06:23in a very simple way but yeah in general that's how a form works mostly and that's how you create

1:06:31these things as well now you can pretty much if you want to you can just throw them inside a div

1:06:38and say like your name and throw this inside a div as well and say

1:06:46like your email and you might have guessed like from the earlier uh version of this that the

1:06:53input fields are actually in line in line elements that means they just stack against

1:06:58each other that's why i just threw them into a div tag so that they appear differently

1:07:03and that's it you have a simple small form with you but yeah we're going to be discussing

1:07:09more about forms when we start javascript because that's where the fun really happens where you just

1:07:16stop the form from submitting and use javascript to submit the form in the background why do we

1:07:22do that because we don't want this weird page reload right or maybe you just want some custom

1:07:28validation logic as well so you see this page reload or whatever happens that would not happen

1:07:34if you are using just a regular um javascript thing but yeah that's that's something different

1:07:41but overall i believe this video helped you understand how to work with forms

1:07:50hey everyone welcome back and in this video i want to only focus on a valid html structure which you

1:07:57need to follow whenever you are creating an html page so far we have been doing some ridiculous

1:08:03work with html just throwing tags anywhere and everywhere we like but that is not how you have

1:08:09to create your html documents what do i mean by that first of all let's just go and look at

1:08:16any decent website like goddamn for example and if you go to the view source you will see that

1:08:22there is a certain structure which is followed and even for code dam i think it's pretty compressed

1:08:27so let's just go to example.com and go to this page source and you can see that it does not just

1:08:33start with example domain as h1 and p tags and all that stuff there's a proper structure to that

1:08:38and why is that well this is because browsers need certain parts of the website

1:08:45in certain place certain tags sure if you start with just this diff tag i mean if that is all

1:08:50we had on the page it would not be a problem it will still display the content but this is not

1:08:56the complete html markup right like i said html is very forgiving in the sense it will not tell

1:09:03you that you are doing it wrong but you are doing it wrong so what's the catch what you have to do

1:09:10well the minimum you have to create in order to be actually a valid html document as follows

1:09:16so you have to write a doctype html the stock type html you can see it's not technically a tag

1:09:21because just like comments it also starts with a tag and then an exclamation mark but this

1:09:28just tells that hey your website is using html5 html5 syntax is the recent the most latest

1:09:36supported browser supported syntax this is not exactly you know a make or break thing for your

1:09:42website but you should have this right then once you have that then you need to have an html tag

1:09:49this html tag by itself does nothing right it's just a root container for everything then

1:09:56inside of head tag this is where our styles and javascript would ideally go the javascript can

1:10:02also go in the body tag and so could styles i mean that there's no exactly fixed rule for

1:10:08anything here but technically all your meta tags for search engines your scripts your style sheets

1:10:20should technically go inside of the head of the document and by convention your title tag also

1:10:26goes inside head document so my title so head is like something which does not which is not content

1:10:34which does not appear in the ui but modifies your ui somehow in one way or another or modifies your

1:10:41meta tags or searching and stuff like this now the body tag is the actual tag which actually

1:10:46consists of the real content on your website right so whatever you're writing h1 hello world

1:10:52stuff like this this is what appears on the page for the user right so all of your stuff all of the

1:10:58good stuff actually goes inside the body tag and yep that's pretty much it i mean you need to throw

1:11:04a couple of metacare set utf-8 things this is mandatory because otherwise your page would

1:11:11actually break and let me show you a fun way of actually breaking a page like that i'll tell you

1:11:16why this meta cards at udf8 is important and we actually have a lab on this i believe in in the

1:11:22other code in the other course but let's say i copied this emoji and if i pasted it right here

1:11:28you can see it does not parse properly why why is that because the browser does not know that what

1:11:38these characters are because technically speaking every single thing is a character right in memory

1:11:46this is a string this is some sort of string but your browser does not know what the hell is this

1:11:50this is not a custom font this is just an emoji right and your browser although can represent

1:11:55this but it still needs a character set of what this page is right and the most popular

1:12:02character set is utf-8 right the only thing you need to know about this at this point is that udf8

1:12:09supports emojis right so what you say is that hey the character set of this page is going to

1:12:15be utf-8 and the moment you do this ta-da it turns into you know regular emojis and we have

1:12:22this in as a lab as well in the further courses i know but you can see that the udf8 udf-8 and

1:12:29capitalization doesn't really matter however it could not be just you know udf and stuff it has to

1:12:34be utf-8 it's a character set name but yeah anyway that's it once you have this simple structure

1:12:42now this is a valid document right now this is a valid html complete valid html document so yeah

1:12:50you should always write complete code whenever you are shipping it to your users just don't you

1:12:55know just don't write like this because it it will just create all sorts of problems right so do this

1:13:06hey everyone welcome back and in this video real quick i'm just gonna go ahead and complete a small

1:13:11challenge for you which you should also see most likely until and unless we haven't just replaced

1:13:17it or replaced it with something different inside your exercises as well so you would be attempting

1:13:22this right but if you want to identify you can just mark this video as complete or done and

1:13:27just move to that challenge otherwise i'll just quickly go ahead and tell you how to complete this

1:13:33challenge so first things first what i'm going to do is i'm going to start by creating our html

1:13:39document structure like we discussed i'm going to create a head tag just for the clarity i'm going

1:13:45to create a body tag just for the clarity and then i'm going to finally start working on this so the

1:13:51first challenge says that my tribute page should have an element with the corresponding id as

1:13:56main now although i know that we haven't discussed idn classes that much because that

1:14:02makes a lot of sense when we start with css but just understand that id and classes are

1:14:07just two attributes which you can use with pretty much all the html tags right and also let's just

1:14:14go ahead and throw a doctype html while we are added so let's just say i have a div id main right

1:14:21here and a closing div right all right so that is done now let's just move ahead and see i should

1:14:28see an element with the corresponding id title which contains a string okay so i need to have

1:14:36an h1 you know pretty much you can have anything but i'm just making my best choice here h1id title

1:14:42which is let's say i'm creating an attribute page on my own right which is which is dedicated on me

1:14:48but you can write elon mask let's let's do it for garyvee why not right and let's move ahead

1:14:55i should see either a figure or a div element with the corresponding id img div let's go with a div

1:15:02tag there we go within the img div i should see an img element with the corresponding id image img id

1:15:12image right within the img diff tag i should see either a fake caption or a div element with

1:15:20the corresponding id img caption that contains textual content describing the image shown in img

1:15:27okay so i can say img caption and i can say a photo of gary wayne or chuck

1:15:36and inside of this image let's search for gary vaynerchuk let's just take his photo

1:15:43and this one this one's good

1:15:47and just copy this and stick it right not as an id but as an src right here right and although i

1:15:57do know that this is not something i recommended but for now until unless we start with css we can

1:16:03just stick with the width and height attribute but we should have better ways of doing that

1:16:09okay i should see an element with corresponding id attribute info which

1:16:15contains textual content describing the subject of the tribute page all right so we have a div

1:16:22and then we have an id of tribute info right at this point we can also use some of the more uh

1:16:31html tags instead of just keeping on using div you can also use section for example section is

1:16:36another html tag these tags these are something which we discuss in further courses but yeah you

1:16:42can explore a little bit on that but okay let's find this is the let's stick with the html thing

1:16:49so we have the tribute info with us which contains the textual represent describing the subject of

1:16:54the tribute page so this is a tribute page to gary wayner chuck who is an awesome guy right

1:17:07okay i should see an anchor tag anchor element with a corresponding id

1:17:11tribute link which links to an outside site that contains additional information about this page

1:17:19yeah i mean you can choose to follow that or you can just probably link it back to goddamn.com

1:17:27right and i'm just gonna give it an id as well of tribute link like said go to gary's

1:17:35favorite website why not right and it also says you must give your element an attribute

1:17:42of target and set it to blank so the only thing this target blank is actually doing

1:17:46if you even google it you will see that whenever you open this in a new page when you click on this

1:17:53it opens it in a new tab instead of just you know replacing the original tab so whenever you want

1:17:59to open a link in a new tab you just give it a target of blank that's it the img element should

1:18:05responsibly resize relative to the width of its parent element without exceeding exceeding its

1:18:09original size now this is something i which will involve a little bit of css so excuse me if this

1:18:15exercise actually includes a little bit of css you can just skip these two tests if you want or

1:18:21what you can do is just go to the css file right here and make sure you link the css file as well

1:18:29but don't worry if you don't understand about this yet we will discuss this what we can do is

1:18:39right here i can say the image the image id should have a maximum width of 100 percent don't worry

1:18:47about this if you don't understand it it's fine we can discuss that later an image element should

1:18:51be centered within its parent element so if i go to image div and say text align center you

1:19:01can see our image is now centered awesome so now if i click on run test let's see how many we pass

1:19:11okay looks like we just failed this one the image element should responsibly resize

1:19:17relative to the width of its parent element without excusing exceeding its original size

1:19:22okay and one last thing is that we can just get rid of the width and height attribute right here

1:19:26and the final change which we will also make is a height of auto and what this height of auto

1:19:32means is that just adjust your height according to the width of the image right so like you can

1:19:37see if i resize this now the height is fine if i give it a height of a fixed height for example

1:19:44then at some point your image would look fine but otherwise it will just stretch right we don't want

1:19:49that we want it to replace we want the height to automatically work hence we can just specify

1:19:55a height of auto so the moment we do that and run the test this should hopefully pass it now

1:20:02and and also through a display block in here let's see and now you can see that we completely

1:20:07pass the challenge which is fine i mean we can definitely work on this challenge it should not

1:20:12have required a display block or anything but yeah it's fine so yeah that's pretty much it

1:20:17a very small tribute page to garyvee a very very small tribute page rather but

1:20:24i recommend you adding more information more images more text more links for your tribute page

1:20:31and eventually styling it with css as well as and when we learn in the next section

1:20:41hello everyone and welcome back to another video in which i just want to say you that you

1:20:46have successfully completed the first section of this course which is on html basics and you have

1:20:52completed the basics of html well does that mean you are just good to go and start earning from

1:20:57millions of dollars by freelancing and getting placed in google well not yet but you are getting

1:21:05there you have completed some of the fundamental concepts of html tags attributes how to work

1:21:12with most common html tags and understand how web pages work now like i always say programming and

1:21:18web development is not a single pass thing it's a multi-pass learning where you would be learning

1:21:24about these things more and more again and again when you are working with them again and again

1:21:29that means you cannot learn about html 100 once and then move on to css and then learn css 100

1:21:35and move on to javascript that does not happen in programming world especially in web development

1:21:40you will be now mixing your knowledge of html with css then playing with both of these technologies

1:21:47together then you will be introducing javascript to the mix playing with them all of these three

1:21:53together and then moving on to different different technologies and whenever you mix a new technology

1:21:59you would actually realize you understand a lot more things about the previous one

1:22:03because the previous one only made sense to discuss whenever that new technology is introduced

1:22:08right so for example one of the things is a class attribute so all the ht most of the html tags

1:22:15support a class attribute but this class attribute makes no sense until and unless we introduce

1:22:20at least css in the mix right so yeah it's time to start with css because we have done html basics

1:22:29that does not mean we are stopping with html that only means we are introducing a new player

1:22:34which should unlock more of the html things while we are learning about that as well so yeah that's

1:22:40pretty much it for this video hopefully you had an exciting and practical learning of html basics

1:22:46and if you did make sure you rate this course um through the rating button somewhere you could see

1:22:57hey everyone welcome back and in this video i would go ahead and show you how you can start

1:23:04working with css and before we actually get into that let's just actually understand what css is

1:23:09and why that is needed so if you take a look on any other regular website on any website

1:23:15basically in today's time you will see you have all sorts of layouts you have all sorts

1:23:19of colors you have all sorts of effects going on and even sometimes a little bit of animation and

1:23:26that is all because of css or at least some part of css css stands for cascading style sheet that's

1:23:34probably the first and the last time you need to know the full form of css because

1:23:39the only thing you need to know is how to work with it as an effective developer

1:23:44now whatever you create with html you see you can provide some sort of structure to your document

1:23:52that this should be a heading this should be a paragraph this should be a section

1:23:56and so on and so forth but the problem here is that you can only provide that structure

1:24:03which you know the tags give we don't have a tag which says um a container where the header is

1:24:12200 pixels in the height right or 200 some unit in the height because that will be just too much

1:24:20tags right if you have a header 200 tag for example which creates a 200 pixel length of header

1:24:27then let's say i want to have a background tag then maybe we have a bg black

1:24:32something like this and then a color white red or color blue or yellow so you see it will be

1:24:38it will quickly go into tag hill now to avoid this what we came up with was that we said okay let's

1:24:46just go ahead and separate the html that will be the actual structure the actual document of

1:24:51the page and create another programming language called css which the only responsibility of css is

1:24:59to style the layout to style the elements to make sure we are able to customize a lot of parts of

1:25:05the website and so far it has played out very well css is a very awesome language if you are able to

1:25:11understand it properly and that is what we're gonna do in this section in this course make

1:25:16sure you're attempting all the exercises because we'll be doing a lot of layout stuff a lot of

1:25:21amazing stuff with css and it's super important that you are practicing as well as you're doing

1:25:26and that is the the most important part of learning on code damn that you're able to practice

1:25:31as you go ahead so make sure you're completing the exercises the small projects in between as well

1:25:37and we will have a lot of big projects as well later down the line

1:25:45hey everyone welcome back and in this video let us just go ahead and take a look at what are all

1:25:51the ways you can include css in your document now first things first let's take a look at the

1:25:58easiest way now the easiest way is you actually go to the element which you want to style for

1:26:03example in our case is this element let's say and add an attribute called style right now the style

1:26:11attribute exists pretty much on all these stacks body h1p is valid on all these tags on html as

1:26:17well um because these this attribute right here allows you to write css right inside of the html

1:26:27document as a value so it's basically you know it looks like just another attribute but by browser

1:26:33it will be parsed as a css string so if i did something like background yellow don't worry about

1:26:39this we'll discuss what this means but you can see that it turns the background to yellow so that is

1:26:46how you can do it in one way but you if you think about it you will soon realize that let's say if

1:26:52i have another tag hello world again and if i want to use background yellow again then i have to copy

1:26:58paste this and let's say i have a thousand such tags and i wanted to change the color from yellow

1:27:04to blue i would manually have to go ahead and do for every single one of them so this does not seem

1:27:09very friendly right this is why we have the second approach the second approach is where we do not

1:27:17give these tags a style name but actually we point it with the help of the selector which we have so

1:27:28what do i mean by that first things first we'll create another tag called style and don't worry

1:27:33about them again because we will be discussing all of them in detail so the style tag whatever

1:27:39you write between the style tag would be passed as css right and in css the first

1:27:45thing is that you have to select a selector and what do i mean by selecting a selector

1:27:50just like we wrote style right here and it made sense for the browser to understand that hey

1:27:56this style attribute is for this element right because that's that's the property which is

1:28:01written inside the stack similarly the moment you do a selector in css your browser knows that

1:28:08hey this selector the styles which you will be writing in the selector are targeted for

1:28:13these these elements which are matching them right in this case it's just h1 it will not

1:28:18match for p because this is not the selector so let's say i give the same background as yellow

1:28:24and you can see now instead of me going to both of these style tags and you know h1 tags and giving

1:28:31them a style attribute i can just pretty much change it from here right and that's that's easy

1:28:37but this method also has a problem where let's say my website has multiple pages multiple html pages

1:28:44i still have to copy paste all these styles to different different html documents

1:28:49right so the third way which is the best way out of all these three is to actually maintain

1:28:57css in a complete completely different file itself right so what you can do is you can create a file

1:29:04any file which ends with a dot css extension and copy paste these styles directly here and you

1:29:11need not have to just wrap that into style tag because this is not an html document this is a

1:29:16css document so it's understood that browser will automatically understand what this is

1:29:22now well that's fine but how do you link this file to this right because now you might have multiple

1:29:29html pages but you also need to make sure your browser understands that this html page is linked

1:29:35with all of these html pages are linked with the style sheet well you do it from the html document

1:29:40obviously because your browser only receives the html document at this point right it does not

1:29:45know about the existence of this file so what you do is you use something known as link link

1:29:52rel style sheet which just means that we have got a link the relationship of this link to this page

1:29:59is that it's a style sheet and we give it an href of style.css in our case because you know it's in

1:30:07the same directory we can just give it like this so uh not exactly in the same directory but you

1:30:13know because if you open this in the url you'll see that your stylesheet is actually present at

1:30:18the root right it's basically the same file so that's why you can see it gets applied as well

1:30:26and if you change it to yellow for example you'll see it just works fine so that is how you're gonna

1:30:33start working with css this is also kind of like a hello world for you for css we will also discuss

1:30:40in depth what these selectors are what these properties are so don't worry about them yet

1:30:50hey everyone welcome back and in this video we're going to be taking a look at

1:30:54css tag based selector now what does that mean so first of all let's just realize that css needs a

1:31:03selector in any case in order to style an element a selector is a fancy word of saying which element

1:31:10do you want to pick on the page the last time we saw you can just inject a style tag inside the

1:31:16tag itself which works fine but the other way is you actually write a css file or you know inside

1:31:22the style tag and use a selector we have multiple types of selectors in css one of the selectors is

1:31:30the tag selector now a tag selector is pretty much a selector which is the name of the tag itself

1:31:37right so let's say we use another let's say in any html5 like tag for example i know a side

1:31:43is a tag in html which is pretty much like div but it's just it just is semantically equal into

1:31:50a sidebar kind of thing right so let's say i just wrote hello world inside a side right and

1:31:58if i have for example the same thing but for a div right so what i can do now is go back to my

1:32:07style sheet and just directly target aside and i can say as color as green and background as black

1:32:16right so you can see this turns green and black but nothing else

1:32:20right so this means what i can do is i can take any tag on the page and target its selector

1:32:27right away so for example if i take body for example and i give it a background of let's say

1:32:34pink you're gonna see that it just turns pink right so that's that's it that's how you work

1:32:41with things in css on the first level that is you just take up the tag and just

1:32:47start styling it so in fact even now whether when we have not really learned about a lot of css

1:32:53properties just color and background you can see you can create some fun funky looking pages right

1:33:00so yeah i mean we'll be learning more about css properties and what we can do but this is

1:33:05one way of actually starting to style css and you can see css follows a specific syntax the

1:33:12first syntax is you write a selector you have an opening curly brace you have a closing curly brace

1:33:18and you have a property column value semicolon you can see i'm not using quotes here

1:33:25i'm not writing these values in quotes you don't have to write them it will not work otherwise some

1:33:31values need to be written in quotes we'll learn about them eventually as we are going ahead right

1:33:36but most of the values you can just use without goats as well so that is one thing and yeah i mean

1:33:44in the next video we'll discuss really briefly we will discuss something super important with css

1:33:49which will help you in order to debug your code as well but we'll take a look at that in the next one

1:34:01hey everyone welcome back and in this video let's just go ahead and take a look at quickly

1:34:06take a look at one of the things which i think is important that you know although we will discuss

1:34:10it in much more depth in our using dev tools course on the full stack learning path the

1:34:16front end learning path whatever it is but we will be briefly taking a look at dev tools in

1:34:22this one video what do i mean by dev tools well if you're using a browser like chrome or even firefox

1:34:28when you right click on anywhere on the page you will see this inspect option right here at the end

1:34:34right and when you click on this you'll see a window opens on the right maybe for you it is at

1:34:40the bottom like this for me it is at the right you can switch it by clicking these three dots

1:34:45and selecting a layout which you prefer anyway this window right here you could see it pretty

1:34:52much looks like the html you wrote here but it's not quite that and we'll take a look at that in

1:34:59some other video in some other course but for now you can just consider that this is the same html

1:35:05what you wrote inside of your html document but what i wanted to discuss in this video

1:35:10real quick is sometimes it might happen that your styles might not work or something might

1:35:16not work on your page in css right so let's create a situation where i have a background

1:35:24of black but it's not working right so you can see it should technically give me a background

1:35:29of black but it's not so how do i debug this well the way to debug this is first of all

1:35:34you have to open let's just refresh this you have to open the inspector like i did and you have to

1:35:40click on this select an element in the page to inspect it now when you're hovering over the

1:35:46page you'll see it just you know sticks to all the elements and just go to the element

1:35:51you want to debug in this case this is our green text and i have this aside inside the site right

1:35:59just right here inside of the styles part you will see the css assigned to this

1:36:05and right here you can see chrome gives us a warning and it says that invalid property value

1:36:10so now we immediately know that hey our background black is not getting applied because it has an

1:36:16invalid property value now you can go back and change the code and it'll work fine or you can

1:36:21just click right here and change the code right and chrome will just give you a small preview

1:36:26of course this does not stay if you refresh it it will go again to the broken value but it can just

1:36:31you know just use you can use this area for quick debugging or quick checks even you know writing

1:36:37something like background yellow just to see how it looks like so you can do some real time changes

1:36:43on the web and this is how most of the if you have ever seen that on internet most of the fake

1:36:48screen shots kind of stuff is also generated where you would right click on a page change the bank

1:36:54account from zero dollar to 99 take a screenshot and you know just show off kind of so that's how

1:37:00it works people just open this inspector change the value and use it but of course that is not

1:37:07something which is in real world because if you refresh the page it will reflect back but yeah now

1:37:13i can see that hey we had a wrong value because we were using codes so i'll go ahead and remove that

1:37:19and once we do that it will just work fine because just like html i mean for css the browser kind of

1:37:26helps you because for html even the browser does not tell you what's wrong but for css you can get

1:37:31a little bit of help little bit of hints from the panel so if you use any wrong value your browser

1:37:37will say that it's an invalid property value so yeah that's pretty much it for the css part in

1:37:43the next video we'll try to explore more ways of working with css more properties and so on

1:37:53hey everyone welcome back and in this video let's just go ahead and take a look at css properties so

1:38:01what we have been doing so far with background and colors is actually styling certain elements with

1:38:07the help of css properties right so these things background color and whatever we will discuss in

1:38:14the future as well these are called as properties and these are values in css so like i said

1:38:22css always follows a property column value format always you will never find something weird here

1:38:30and yeah this is this is the underlying thing of basically all the styles which you see on

1:38:36the website a selector a property and a value and that can be used a lot of times a couple of things

1:38:43you have to note here is that all these values end with a semicolon there is no exception here

1:38:49in css your code will work fine if your last value omits the semicolon then it's fine but

1:38:55if any other value omits the semicolon you will get errors right you can see it saves me semicolon

1:39:01expected and also our styles are broken here so it's as a rule of thumb just make sure you're

1:39:06ending all your values with a semicolon that is one another thing is that we have a bunch of

1:39:12properties in css some of the common ones which you can think of are you know related to

1:39:18dimension for example we sure have background and color but we have for example width where i can

1:39:25wi ddh where i can give let's say 200 pixels otherwise so you can see it's a little shorter

1:39:31than before if i increase it to 300 you'll see it just increases a little bit 350 and so on

1:39:37right so you can see that you can play around with width you can play around with height

1:39:45width and height for example it's it's a long aside tag now

1:39:50you can also play around with certain properties like margins and paddings which we'll also get

1:39:55into and we'll discuss how they work in terms of their short hands um but yeah for now i think

1:40:01it's a start with background colors width and height right so now you can have

1:40:07four tags for example let's just go ahead and create a p a side div and h1 right and now let's

1:40:14just give them different different words so h1 is width and height 200 pixel and background as

1:40:21green for example then for a side we can have the same thing but for let's say 150 pixel and then

1:40:32for div we can have the same thing as blue red and this would be 250 pixel right so you can see

1:40:41we have a mix of styles here and it's already a lot colorful than just you know plain html page

1:40:50so yeah i mean we have now we also have a property which comes to my mind like border border radius

1:40:56and border radius is just in either in pixels or in percentages the amount of curvature you want

1:41:02on the borders i'm going to give it a 50 and you can see it turns it into a circle now obviously

1:41:08the content is overflowing which we don't want so maybe we can fix it later down the line or

1:41:13you know just keep it as it is but you can see now you are able to play with css a little bit

1:41:19and there are tons of properties right there are tons and tons of properties so i would probably

1:41:25not be doing just one property per video because that will just be a really boring course in itself

1:41:32so what we will be doing is we will be actually discussing these properties as and when we are

1:41:36building stuff with them right whether you are building them in the exercises where you will

1:41:41see the properties names and the description in the uh in the exercise description or whether

1:41:46it's a video where of course i will be telling you what the property does so that's how we'll

1:41:52start working with css properties by actually making use of them there are a lot of them

1:42:02hey everyone welcome back and in this video let's just go ahead and take a look at classes in css

1:42:09and classes in css will make a lot more sense the moment we realize what is happening right now

1:42:15so for example right now you can see that what we have is that we are trying to create multiple tags

1:42:21for selecting those tags inside css and styling them now this might seem okay right now but if

1:42:28you think about it if your website has hundreds of elements then it probably makes no sense to

1:42:34actually come up with hundreds of such tags and then style them differently because that will be

1:42:39just insane amount of work so what we came across is that we said okay you could pretty much use

1:42:47a bunch of tags on the like div or p or span or whatever we discussed and you can still select

1:42:54them in a unique way or in a collective way by using classes now what does that mean let's say

1:43:02this is a div again matching it with the with the one below but let's say i also want this to

1:43:09just have the blue circle which which it had earlier so what i can do is i can give it a class

1:43:16of blue right and right now what i'll also do is i'm going to give this a class of red so so

1:43:24far you see nothing happens because that's it that's what all that's all class does right it

1:43:30just gives an attribute which you can pick up in css but we are doing no such thing in css so far

1:43:37so what we can do right now is instead of aside i can say i want to target this blue class

1:43:45but remember the moment we write blue css is trying to actually look for a blue tag in the html

1:43:52it's not looking for a blue class right so the way css looks for a class is you have to start that

1:43:58with a dot with a period right so this full stop distort this period whatever you want to call it

1:44:05this denotes that hey this selector right here it's not an html element it's not an html tag

1:44:12but it's actually a class name so go ahead and take a look at the dom and see all the elements

1:44:18which have this class of blue whatever you want to call it right you can call it very well call

1:44:24it green and it'll still work if you just make the right changes so if you call it green you can see

1:44:30it still works so it's basically you can pretty much name it anything as long as it starts within

1:44:36um with a string i think that condition is also relaxed a little bit i'm not sure but yeah make

1:44:42sure you just keep your class names sane not really just go all wild characters or anything

1:44:50so that's how you use classes and you can see we already have this as red because we are targeting

1:44:56div but even if we target even if we go ahead and target for example dot red like this it will

1:45:02still work right another advantage for this is that i can also use the same class for example

1:45:09with this another tag right and now i did not need to go ahead and write more styles for the

1:45:16same thing so you can see it's kind of it kind of makes it reusable it kind of makes your css

1:45:21code reusable because now you can just slam a class to any of the element you want and

1:45:27it will be just turned that way similarly i can just go ahead and give this h1 a class of blue

1:45:32and right here you would see that suddenly this green color went away for each one and why is that

1:45:40why that happened that is because of some cascading style sheet rules and we'll discuss that

1:45:47but for now you can just imagine you can just say that whatever comes the last whatever comes last

1:45:52is applied right if there's a competition between h1 and dot blue then blue is coming at last then

1:45:59gets implied but this is not the full statement we can kind of override this as well but we'll take

1:46:05a look at that later on the line you don't have to worry about this now at this point i would say not

1:46:10to put conflicting styles so probably a good idea is to just remove any conflicting style at all

1:46:22hey everyone welcome back and in this video let's just go ahead and take a look at

1:46:26ids in html and css and what that what does that mean so in the last video we saw about classes and

1:46:34if you understood classes that's awesome because ids is pretty much the same concept right it's

1:46:40exactly more or less the same concept but the thing with ids the only one constrained with ids

1:46:46is that you have to give an id to only one element on the page so one unique id

1:46:54one unique value of that id belongs to only one element so what do i mean by that well

1:47:01i can give this a class but i can also give this an id and i can say this is only paragraph right

1:47:08so this id right here technically i mean of course nobody's stopping me and go ahead

1:47:15and for going ahead and create this paragraph two but this is wrong in the eyes of browser

1:47:24right the browser will not like this and that's all the browser can do to be honest um because

1:47:31they don't complain about html right but this will actually come and bite you when you're

1:47:37working with javascript because javascript just like css has selectors javascript has methods

1:47:43to pick up the elements from the dom right we'll come to what dom is what did i just say

1:47:49but what you have to realize is that just just keep it in mind at the moment although you can

1:47:55cheat the system and i can tell you like if we go and only p and do a font size of let's say 30

1:48:00pixel you will see it works across both of these paragraphs that works fine but trust me don't

1:48:07do it if you are using ids just keep the id to a single unique value on the html document you can

1:48:15give it another one only p2 that's fine and then style it and you know i might have skipped this

1:48:21but the way you style an id is by using a hash symbol here right so we had a full stop a dot a

1:48:29period in the class name and we have a hash symbol for the id so that is basically it that's all

1:48:37that's all the difference between a class and i and an id the way you refer that number one and

1:48:43number two is that the fact that you can only keep it one unique value per page in most of the cases

1:48:52i usually prefer people to just go ahead and use class because it's just less cognitive overload

1:48:57you don't have to think a lot about that and it's fine i mean ids have a very slight

1:49:05more performance on the web page um but that's that's basically negligible right you

1:49:11would not never never ever feel that so just technically speaking ids are faster because

1:49:17browsers can maintain a hashmap of the ids on your page and directly go to the element in that

1:49:23tree but don't worry about that trust me here you can pretty much just forget all about that

1:49:29and focus only on classes but i'm telling you that ids exist just because you should

1:49:34know if you see an attribute that should be a unique id on the page and you can style that

1:49:40using css just like you would do a class but using a hash symbol instead of a dot

1:49:51hey everyone welcome back and in this video let's talk about an interesting concept in

1:49:56css and in html which we also have talked about a little bit before which is the inline and the

1:50:02block elements so just to quickly revise if you have forgotten what inline and block elements

1:50:07were block elements are the elements which pretty much take the whole width of the screen i mean in

1:50:13this case we have obviously just customized all of them with a given width and height

1:50:18but if you take a look right now for example for blue if i give it a background of blue

1:50:23you'll see that it takes the full screen width or i should rather say the width of the container

1:50:28it is in so for example if i go ahead and and close this in a div and give it let's say a

1:50:36class of parent and right here if i go ahead and do a parent and width of 200 pixel you can see

1:50:44well the blue is also taking the 200 pixel width right if i switch to 400 the blue element is

1:50:51also taking 400 but this one right here is taking the full width of the body because

1:50:56the parent of this blue element is the body which is 100 of obviously now this is a block element an

1:51:06inline element is an element which for example is a span right this span right here you can see well

1:51:15we have a rate class as well so let's just get rid of this first of all so right here you can see

1:51:22this span right here is an inline element because it does not extend the whole way to the screen

1:51:28with css what you can do is you can change these behaviors so we know that span is an inline

1:51:35element right but we can make span a block element how do we do that we make use of a property called

1:51:42as display and we set this property to display block and you can see the moment we do that

1:51:48this span spans the whole row no pun intended but yeah that's how you can change the behavior

1:51:56similarly you can make a block element in line as well so if i go ahead and decide

1:52:03to let me just go ahead and remove this parent and switch this blue from a block to an inline element

1:52:10you can do that so the moment you do that you can see they have stopped taking up full 100 width but

1:52:16this span right here takes up the 100 width even though technically span is an inline element right

1:52:24it's not a block element so you can see that with css that's just one of the many things you can

1:52:31control right you can for example in this case h1 you can go ahead and target h1 and give it a font

1:52:38size of 16 pixel and you know font weight which is if the font is bold or not

1:52:45and you can say normal right so you see that you have converted an h1 into just a paragraph

1:52:50and you can pretty much just reverse apply this to your red paths and say that they are 32 pixel

1:52:57for example and font weight bold right so you have basically converted these

1:53:02red class elements into headings so you see with css you can bend the rules you can

1:53:11just break html in multiple ways html says that h1 should be the heading it should be the

1:53:16largest element but well there are no rules to that right with css you can change that

1:53:23so yeah that's pretty much it that is all on how you can switch between block and inline

1:53:30this display property is very useful and it is also useful for creating layouts with css which

1:53:36we will see how we can do that but yeah that's how you switch between block and inline elements

1:53:41and we will take a look at a couple of more values which we can give that but later down the line

1:53:52hey everyone welcome back and in this video let's just go ahead and take a look at layouts in css

1:53:58and we're going to be starting off with flexbox now i'm going to give you a quick understanding of

1:54:05how layouts used to work i think we have barely just you know in one video touched upon this

1:54:12when we discussed tables right so in the very old days when the web was still new and young and

1:54:18you know the support wasn't there what we used to do as web developers was we used to create

1:54:23all these layouts with the help of table tag because just like i showed you in the

1:54:28tables video as well we can find it above in some other section that table gives you the

1:54:33opportunity to use things like row span and call span so these things allow you to kind of bend

1:54:39the rules and display nice uis but that is not useful at all because tables are not responsive

1:54:46they just don't make sense on a mobile phone or you know different width devices and that was

1:54:52a real problem in 2021 and beyond because we are actually using a lot of mobile phones and

1:54:59weird screen devices not just fixed display devices so we needed a better layout solution so

1:55:06what we came up with in css3 which was the latest version in which flexbox was released

1:55:14was a different sort of layout now how that works let's see so i'm gonna go ahead and create a div

1:55:22where i'm just gonna name this as a class of new new layout uh yeah i mean we can keep that that's

1:55:30fine and let's just give this div let's just give create four empty divs here right just to

1:55:38set the picture set the stage and right here i'm just gonna remove all of that i can just give

1:55:44the body a background of pink i don't know kind of like you know it's a smooth color for the tutorial

1:55:51so anyway so we have the new new layout and right here what i'm gonna do is first of all

1:55:59yeah i'm gonna also tell you about a different kind of way to select elements the way you can

1:56:04do that in css is you can write a dot new layout like this and then give it a space and then div

1:56:12now what does this mean if you hover over this you will actually see it gives you a simple tip

1:56:19as well that it element class new layout and any element after you know any child div inside that

1:56:26so what does that mean this says that any div any sort of div which is inside the new new layout

1:56:33can be used right we're going to be discussing more about all the selectors later down the line

1:56:39but for now this is a start this is how you can pretty much select div inside a new new layout

1:56:47class of div right so right here i'm just going to give it let's say a background of red

1:56:54a width of 200 and a height of 200 right and you necessarily do not need to give this um you know

1:57:04a width and height both if it contains some sort of content but in our case because these

1:57:08are just empty divs we don't have any width or height because of the inherent width or height

1:57:13because of the content and you can see that it looks like we have just one div which is super

1:57:20tall and that is because all of these discs got stacked with each other right so what we can do

1:57:27is actually also give them a border so i'm going to say it has a border of one pixel

1:57:32solid black again a new property i guess for you which we did not discuss in this

1:57:36which is border it takes up a border thickness then a solid which is the

1:57:43kind of the border which you want we also have dotted and i think we also have dashed

1:57:48so these are like two three values but solid is like you know the most common one and then the

1:57:53color of the border obviously we can give it a two pixel and it'll just double the thickness

1:57:57so you can see all right the next thing is we can also give this a little bit of margin

1:58:04so margin is this property right here is actually a shorthand of four properties right

1:58:12um margin left margin top margin right and margin bottom so i'm going to show you real quick what

1:58:19this means not in here but actually opening this in the new tab and opening the inspector again

1:58:24which we have already discussed so if i go to the stiff right here which has been styled you can see

1:58:31although this this width and height is fine we have these arrows on the right of these

1:58:37three properties these arrows means that we are using a shorthand version of the property even

1:58:44for background right so you might be surprised what is the actual property name so in case

1:58:49of margin for example if i click on this arrow you can see that what exactly was the shorthand

1:58:55which i used so i said margin top is 10 margin right is 10 bottom and left is 10. so if you use

1:59:01all of these four properties or if you just use this one property this is equivalent right browser

1:59:07considers these four values these four properties and this one as same for border you can see it's a

1:59:15lot of properties right i mean this is something you can leave out but you can see these are the

1:59:21actual expanded properties right and you might be wondering like why do these properties even exist

1:59:28well they exist because css gives you extremely fine control over how the layout should look like

1:59:33so you can say that you want a different width of the border you might want a different color

1:59:40of one side of the border and no border at another side color and so on and so forth so

1:59:45theoretically you can customize each and every aspect of these things right so that's why but

1:59:51in most cases you don't necessarily need to worry about them for margin sure this will be something

1:59:56which we'll use a lot but for borders i think this is this is a very common thing which you do

2:00:01for background again you can see nothing's fancy you can't just forget about all these properties

2:00:06but background actually is background color not just background why because background also

2:00:12allows you to give an image as the background but background color well just gives you the

2:00:17opportunity to set the background color so anyway coming back to the video of layouts what i wanted

2:00:25to introduce you in this video was the flexbox layout which we still did not see yet so the

2:00:32build up is done and now what we can do is we can just go ahead and give it a display of flex

2:00:38remember we had a display of block earlier right um because this is also a block element so by

2:00:46default div takes a display of block right but what we did was we did not change this to inline

2:00:54but we changed it to flex and flex is a like i said is a new layout system flexbox is a new

2:01:01layout system which allows you to stack elements in a row or in a column depending on how you want

2:01:09so by default you can see it changed it direction to a row so flexbox by default just stacks

2:01:16all of the things in a row you can change it with a flex direction

2:01:21of row which is you know the default value or column where you would see it just gets stacked

2:01:27just like before before it was right so yeah that is pretty much it if you take care look

2:01:34at row for example you'll see it just sticks it like this and column would do the vice versa

2:01:45hey everyone welcome back and in this video let's just go ahead and take a look at what exactly is

2:01:53flex basis because flex basis is going to be a property which you will be using a bunch of times

2:01:58when you are working with flexbox so in order to understand that first of all let's understand

2:02:04a concept about flexbox that is the axis so you see when you have a flex direction of row

2:02:10whenever i add a new div here you will see it gets added inside that row right

2:02:17so it's all the new divs are getting added in this direction towards my right so this means

2:02:22this direction towards the right is actually the main axis of this flexbox container all right

2:02:30so once we have that understand the that the axis perpendicular to this that will be downwards right

2:02:36here is the cross axis so we have to access the main axis in which the elements are getting added

2:02:43like this like these stiffs and the cross axis which is perpendicular to this so what we have

2:02:50here is a width and a height right for the sake of clarity i have given different widths and let

2:02:57me just go ahead and actually just keep it with just two diffs to actually make it even more clear

2:03:04and we have a width and a height now we have some property known as flex basis and let me

2:03:10just go ahead and give this a width of 300 pixel right so you can see the divs got slightly larger

2:03:17right and this width got ignored so with this width is ignored and the reason for that is

2:03:23because flex bases actually is width in this case let me let me tell you what i mean by that so we

2:03:32discussed about the axis right so in our case this is the direction from left to right

2:03:37in which our main axis lies now what flex basis does is that it defines the length of the item

2:03:46in the direction of main axis so it is width in this case which is if i change this to 350

2:03:53or 340 whatever you will see it becomes longer and longer and if i shrink this to let's say 50

2:03:58pixel you will see it becomes shorter right so basically width is completely ignored

2:04:03similarly if i have let's say the flex direction of column what will happen is that this flex basis

2:04:11right here actually becomes the height of the element so if i change this to 200 for example

2:04:19you see the height increased and now if i have the width as 50 pixel then it stays the same right

2:04:25so now in this case height is irrelevant because the moment we change the direction to column the

2:04:32main axis becomes this from top to bottom because this is the direction where new elements are going

2:04:38therefore flex basis property is gonna point to the length of that individual item which is what

2:04:44we are selecting right now um in that particular direction right so in this case we are saying that

2:04:49hey this should be 200 pixel so if you're using this in this case it does not make sense to use

2:04:55height right because height is just meaningless for this so this is what flex basis property is

2:05:01super important stuff and super fundamental thing you should know about flex basis is that it only

2:05:08works in the direction of the main axis and how do you find main access a quick simple rule is that

2:05:14whenever you add a new element to the container in which direction it is getting added if it is

2:05:19in the row then the main axis is like this if it is in the column then the main axis is like this

2:05:29hey everyone welcome back and in this video let's just go ahead and take a look at flex

2:05:36shrink property and i'm gonna tell you what does that mean so first of all let me just go ahead

2:05:41and change this to row and i'm gonna say i'm gonna just show you let me just go ahead and also not a

2:05:47width but a height because our width is defined by flex spaces let me just go ahead and shrink this

2:05:53so you can see you can see by the end of almost you know the browser window collapsing to zero

2:05:59our boxes also get almost shrunk down now this is fine because flexbox is considered to actually not

2:06:08just overflow until and unless really needed right so it tries to adjust the width of every single

2:06:16item in in the container you can control this behavior by using a property known as flex shrink

2:06:24now first for that first of all let me just go ahead and move this as first and this as second

2:06:33right and what i'm gonna do is say for the first box i want to say that it's flex shrink

2:06:40is zero now let me tell you what what i mean by that let's just see this at this point both

2:06:46of them are 200 200 pixel right but what i have said is that the first which is this div right

2:06:53here should have a flex shrink property of zero so this means this flexion property

2:06:59is basically a proportion of compared to other elements how much a particular element

2:07:07should shrink to fit that's that's all this is so number zero is saying that hey

2:07:14don't really adjust at all that means never really change your width to shrink to fit so that means

2:07:21only the other element has to basically you know shrink all that all the way to zero or whatever

2:07:27their minimum weight is now if i give this a 0.5 for example you're gonna see that the first

2:07:34element just shrinks half as much as the second element not half as much sorry i should rather say

2:07:42um for example if the if the second element because the default property of lecturing

2:07:49is one let me make it a little bit simple so i can give this a flex rank of one and this a flex

2:07:55shrink of two so you can see that this basically is shrinking twice as fast as this element right

2:08:05here right so they start with the same width but right here this element is also shrinking but you

2:08:12cannot you know this element shrinks much faster than that because it's shrinking as twice as fast

2:08:18so these are absolute numbers they do not have any units because these are proportions compared

2:08:24to other elements so this is what flex shrink is right that means if you want certain element

2:08:32to not shrink at all all you have to do is just set their flex shrink to zero and these elements

2:08:38right here will stop shrinking that means they will just start overflowing the parent container

2:08:44if they have to right so that's how you can maintain a fixed width with a flex box

2:08:55hey everyone welcome back and in this video let's just go ahead and take a look at how you can use

2:09:03flex wrap so in the last video we saw that if i do a flex shrink of 0 this basically says

2:09:09that hey you're not supposed to change your width from whatever flick spaces has set therefore just

2:09:15overflow if necessary so what you can do in order to kind of fix this is on the container you can

2:09:21say a flex wrap of wrap and what this property means that just go ahead and overflow this

2:09:29you know element to the next row if it does not fit in the previous one and it's kind of fine with

2:09:35certain card based layouts for example where the width matters and you want to just just push it

2:09:41to the next row if possible or before you know for items where you don't know the size of the element

2:09:47beforehand or rather the count of the elements beforehand so that would be useful in that case

2:09:54but yeah it's as simple as you know just setting up flex wrap on the parent and not worrying about

2:10:00what would happen if we have more elements because now if you just try to add more elements it will

2:10:06try to fit as many elements as it can with within the single row as long as possible

2:10:13but the moment it is not possible it will just just you know push them into next next rows

2:10:20and there's that you have a free kind of like you know free responsive layout available to you

2:10:26not exactly responsive but you will get the idea that this is something

2:10:31which is much better instead of just having a user just keep on scrolling on the right of the mobile

2:10:37screen so that's at least that's one step in the future so yeah that's pretty much it you need to

2:10:43do flex wrap wrap that's it once you do that it'll just work fine it'll work the same way with flex

2:10:49direction column as well but browsers are weird and they are basically made for top to bottom

2:10:56reading not from left to right so this is why flex wrap wrap makes much more sense in a row-based

2:11:00system but it'll still work in the column based layout as well so don't worry about that

2:11:06but yeah that's pretty much it for this video hopefully you liked it if you did make sure

2:11:10you're leaving the review to the course if you haven't left a review yet and leave the comment

2:11:15just invite some of the people to watch this html course css course with you i mean it's completely

2:11:21free right and most likely you're enjoying the practice sessions as well so if you are make sure

2:11:26you share a word with your friends and family that will really help the platform grow as well

2:11:36hey everyone welcome back and in this video we'll be taking a look at how to center a div now this

2:11:43might seem like you know a easy thing but it wasn't easy at all back in the days when there

2:11:50was no flexbox when there was no advancement to css layouts and all this stuff so it's super easy

2:11:56now which we'll take a look at but it's still a running joke in developer communities that

2:12:01how do you center a div with html people just just like to throw the statement all the time

2:12:06so i think you should know the answer to that but anyway what do you have to do in order to center

2:12:11a div in a in a another div let's first of all have some divs here so let's say this is parent

2:12:19right and this is dave id child right and now we want to center the child inside the parent so

2:12:27first of all let's just go ahead and give parents some background of red width of 100 or 100 vw and

2:12:37height of 100 or you know 50 vh and let me just quickly go over these units as well if i haven't

2:12:44gone over yet so you could see that we are pretty much using units like pixel now i'm

2:12:50using something known as vw what exactly is this so in css there are multiple ways of specifying

2:12:57what the dimension should be right just like we have centimeters and then we also have meters

2:13:03and although they are technically convertible there are a certain there are usually certain

2:13:07ways you can also specify widths and heights dimensions in computers one of the ways

2:13:12is pixels which is the most common and the most used as well so pixel is just basically

2:13:19basically speaking a single dot on your screen which is responsible for emitting a light

2:13:24so 100 pixels just means 100 pixels across and 50 pixels wide and more or less sometimes you just

2:13:32have to play with these numbers to kind of get the feel of it then we also have percentages in

2:13:38css 100 just means complete width of the container it is in and 100 um is basically similar to what

2:13:48100 we w would mean with the only difference between vw is actually the viewport's width now

2:13:56what this means is the screen size of the of the container right so right now in this case you can

2:14:02see there's a little bit of overflowing if you see on the right the div actually overflows 100

2:14:07vw but does not overflow if i specify 100 percent now the reason for that is because 100 vw is true

2:14:16screen width right and right here we have some default browser margins available to us

2:14:21so the first thing we'll do is actually just go ahead and set margin zero and let me just quickly

2:14:26go with at this selector as well although we will go over this these selectors in depth in our next

2:14:32course which is advanced html5 and css3 but this selector pretty much here means everything

2:14:39so what we are saying is by default every single thing should have a margin of 0. well that sounds

2:14:46wrong right if you think about it we don't want every single thing to have a margin of 0.

2:14:50but the good thing is that css selectors actually comes with something known as selector specificity

2:14:57and again this is something which we will discuss in the advanced course but what

2:15:01you have to realize is that the star that is everything has the lowest specificity why does

2:15:08this matter because this means anytime someone wants to overwrite this style they can easily

2:15:13do with any any selector they don't have to worry about it right so that's that's a handy thing you

2:15:20should know so anyway we have vw and let's say 50 vh vh is just 50 of the screen if i give it

2:15:28100 for example you will see it converts fully to rate screen uh 50 makes it just half of it

2:15:35right now the next thing is we want some child dimensions as well so i'm going to

2:15:41give this a background of yellow width of 200 pixel and height of 200 pixel as well

2:15:49right and there's our child div and now what we want to do is we want to center

2:15:55this child div inside this parent diff and as a matter of fact let's just go ahead and see all the

2:16:01positions possible with flexbox um alone for this right so it's gonna be a fun exercise and you will

2:16:08also realize what all you can do with flexbox in terms of positioning and in terms of layout

2:16:14so let's say i want to center this first of all because that's that seems like the simplest

2:16:20so the first thing i'm going to do is i'm going to make my parent a flexbox by saying display

2:16:27flex now the moment i say that this means that my parent now is a flexbox and

2:16:32all the children inside it are automatically flex children however i haven't specified how

2:16:39or what should the layout be right so by default it just takes the flex direction as column

2:16:44therefore if i have a second child there and if i go ahead and convert this to a class and make

2:16:50this a class and create a second child you will see that by default no not not in the column but

2:16:57in the row by default they just stack in the row right that's the default flexbox behavior

2:17:02but anyway we don't need to worry about that what i want to do this time is i want to say

2:17:07justify content center and align items center now let's just go ahead and take a look at what

2:17:14these two properties are because our most of the work would involve these two properties

2:17:19so the first thing we are doing if i remove justify content send align item center you

2:17:24will see that our main access was from left to right right which is what we discussed in the

2:17:30first flexbox video from left to right so justify content whatever value you provide it you could

2:17:37see that it actually centers that on the main axis now this is important this is important

2:17:46why we will take a look at that but justify content centers on the main axis and align items

2:17:53center would pretty much center it across the secondary axis now let's say if i have a margin of

2:18:025 pixel here just to make some space and now if i go ahead and create another child

2:18:09right and let me just go ahead and actually make this full screen why not right so we have these

2:18:15two divs let's just remove align items for now we see that justify content does it in the main

2:18:22access way and we don't have a line items so what i'm going to do next is i'm going to say

2:18:29flex direction as column right so what this means is that switch our direction from stacking items

2:18:37in a row to the column side right and immediately you can see because our main axis was now this

2:18:43you can see it centered it in this main access row right earlier our main axis was this therefore

2:18:49it got centered in the main axis so justify content always works in the main axis direction

2:18:56and to be very honest it's it's just a property which you don't necessarily need to remember where

2:19:01it centers you can just figure it out on the go as well you can just apply it see how it is centering

2:19:06because it will center the children in your flexbox until and unless you are doing some funky

2:19:11stuff here it will work just like it is supposed to but again like you can see a line item center

2:19:17right here will actually center it across the secondary um axis as well all the items rather

2:19:24all right so this is that let's just go ahead and take a look at let's just go back to the

2:19:30the one child itself and in this case it does not matter what flex direction you have

2:19:34but what i'm going to do is i'm going to start messing around with these

2:19:38values so i'm going to say justify content flex start and let's just remove this as well

2:19:45so you can see flex start is basically like saying nothing because it just keeps it right there

2:19:50right so it's basically the default value then you have justify content flex end which

2:19:55just pushes the content towards the the very end right and that is all what justify content can do

2:20:02on the main axis it can allow you to align all the child items then we have align items right

2:20:09and align items just like you would have guessed from justify content also has these values

2:20:14flex start which is basically doing nothing flex end which is basically pushing it on the

2:20:21end of the secondary axis and center just centers it right so you see you have three possible

2:20:28values here and you also have three possible values here therefore it means that you can

2:20:36pretty much have nine combinations here right and if you think about this flex start flex end and

2:20:44center if you have nine combinations then you can have one two three four five six seven eight and

2:20:53nine so this is like this square right here then this square right here then this square so you can

2:20:59pretty much possibly place the object all the way in a in a kind of a symmetry right so let's start

2:21:05very quickly from flick start and flick start and we'll go in this direction we'll form this loop

2:21:11right then let's say if i want to push it all the way to the center first i'm going to give

2:21:16this a center then we want it flex end then we want this to be center because it brings it down

2:21:27then i want this to be flex end then i want this to be center because it brings it in the center

2:21:33then this should be flex start then finally this would be center and then finally this

2:21:41value would be also center so that's how you get a div in the center of a parent pretty nicely and

2:21:48i hope you understood a lot of properties along the way as well justify content and align items

2:21:53and of course they will play a little bit differently if you have a couple of divs here but

2:21:58obviously the idea remains same if you just start again with flick start flick start you will see

2:22:06that if i do this flick center it's basically just not flick center just center it basically

2:22:11just moves both of them together flex end and so on you know you get the idea

2:22:22hey everyone welcome back and in this video let's just go ahead and actually take a look at

2:22:27some of the common layouts and i want you to be confident in how you build layouts with flexbox

2:22:33so what i'm gonna do is i'm gonna go ahead and create some sort of layout structures for you some

2:22:39basic hands-on layouts which you should be aware about and as you practice as you build more sites

2:22:45with the similar layout you will realize that this is super important stuff which you should learn

2:22:50now what do i mean by that i mean like if you go to google and carefully look at this webpage you

2:22:55will realize that this area is in the center of the screen then you have a footer then you

2:23:00have a kind of a small header and so on right there's a big gap between this footer and the

2:23:06um these navigation buttons and so on so just to develop just for developing that understanding

2:23:12of how to create these layouts you need to fundamentally understand how you work with flexbox

2:23:18so what i'm going to do is let's just shift this to pink for example and what i'm going

2:23:23to do is go ahead or maybe just a little darker shade on the reddish side yeah

2:23:33so i'm gonna go ahead and create first of all a simple google.com like layout

2:23:40right and i'm gonna leave the elements filling elements part to you like creating this button

2:23:45creating these input fields because we have seen them all creating these anchor links and so on

2:23:50so let's just start with parent i'm going to go ahead and remove the margin from everything

2:23:55and we have the parent like this and child and in fact we don't need this as well

2:24:03okay so the first things first i see that there's a navigation bar now make sure you're

2:24:08understanding this tutorial in a way how i am thinking not what i'm telling right super useful

2:24:15super important just make sure you are able to see how i'm thinking so i got a navigation bar

2:24:20i start from the top to bottom of the site i see first things first which i have to place is this

2:24:25navigation bar so i'm going to go ahead and create some sort of um some sort of navigation right

2:24:32i'm going to use a nav html tag which we'll probably see in the advanced course as well

2:24:38nav and i'm just going to add a couple of links here home about for example right nothing fancy

2:24:50now the next thing i need to do is there are there are two ways developers approach a project

2:24:56the first kind of people what they do is they just code up the whole html structure thinking

2:25:01about how the css would make them look like and the second one just takes one step at a time

2:25:06code a structure then go to css code structure and go to css what you do is completely your

2:25:11choice my case i usually prefer to just write the whole html structure and then arrange it

2:25:16but it's fine you can pick whatever you like for the sake of this tutorial i'll

2:25:20just go ahead and stick to my own style but you can pretty much do whatever you like right

2:25:27then you have an area which is the center so i'm gonna have actually let's just get rid of the

2:25:30parent as well it's not exactly needed we can just style the body tag itself then we have a section

2:25:38which is probably in the center of the screen i will say this this is divided logo for example

2:25:44right then we have a footer at the bottom and we've also have a photo tag in html

2:25:51and you'll just know about these tags don't worry about them if you don't understand

2:25:54that hey this tag also exists or hey that tag also exists for the most part you can

2:25:58stick to div but we will also discuss about these stacks briefly in the next course in

2:26:03the advanced html css course and how you can know them as well so don't worry about that yet

2:26:09so for the footer i would say we have a layer 1 so i'm going to say dave id layer 1 for example

2:26:14or div class name it's to be honest it does not really matter you know i can even give this a

2:26:20class of layer because they pretty much have the same background color so class layer again

2:26:27so we have our basic html structure at this point we are not doing anything with the css and

2:26:32you can see pretty much nothing looks like google right but let's let's fix that so the first thing

2:26:38i'm going to do is arrange this navigation part right so i'm going to say this nav has a display

2:26:44flex and flex direction by default turns it into a row but what we want to select is the snag ul why

2:26:52because li or whatever you write here would be the children of ul not nav right the direct children

2:26:59and what i can say is for these nav uli is list style none which will disable their bullet points

2:27:06right and just a quick hit heads up if you know about what you need to do for example this thing

2:27:13you're stuck hey how do i remove this bullet because this is overwriting

2:27:17how to find this is to go to google and write that question how do i remove bullets from

2:27:25ul or from li whatever use google when you're building projects to answer these common simple

2:27:31questions don't just get stuck or rely so much on a video whether it's code down whether it's

2:27:36any other place which you're watching because we can just teach you so much you will run into small

2:27:40issues which you would have to debug yourself so make sure you're using google properly for

2:27:46every single question so anyway let's restore that so that we have a nice clean looking thing

2:27:53and uh yep that is pretty much it what we can do next is i can say flex direction flex not flex and

2:28:01we already have a flex direction of row so that does not matter just if i contained flex end right

2:28:06so this puts us right here now you could pretty much go ahead and play around with a little bit of

2:28:13padding padding is like i said um we will discuss about the content the box model in css again in

2:28:20the html and css advanced html and css course so stick with me i'm i'm pretty sure a lot of things

2:28:27would get clear once you are done with this course the exercises and the next course so i'm going to

2:28:32go ahead and put a padding of 10 pixels which gives us a little bit of padding on the sides

2:28:36um and you can also put a margin off to pixel and if you want to see like how margins and

2:28:41paddings are working you can always give this a background of yellow for example

2:28:45so now you will see that this white space or let's give it a darker color this white space in between

2:28:51this is this is the margin and this gap between the text and the boundary is the padding right so

2:28:58if you increase these values the gap increases but if you increase these values the space

2:29:04between them between the elements increases so it's your call what you want to use on

2:29:09a white background i mean margin and padding visually both look same here but they are not

2:29:15just to make sure you know that all right so once we have the navigation part figured out the next

2:29:21thing we need to do is the center thing and lucky us we have just discussed how to center something

2:29:28on the body or on the you know the page so we will not be following that because i want to show

2:29:36you a different strategy i mean kind of we will be following that but let's just go ahead and for now

2:29:42i'm going to go ahead and say logo has a width of 80 vw and a height of 200 pixel right i'm

2:29:49just giving it a background of red for example just for our placeholder so this thing should

2:29:54technically be going right here but we'll take a look at how we'll do that the next thing i will

2:30:00do is i'll style the footer which we have right and the layer part we know that this is a little

2:30:08bit of grayish color you can extract those colors out as well but i'll be just a little lazy here

2:30:14we don't necessarily want to style footer we want to style the layer part here so what i'm going to

2:30:20do is i'm going to go ahead and say this has a background of gray which you can of course just

2:30:25lighten a little using the select this speaker itself and yeah i'm just going to give this

2:30:33a width of 100 or 100 vw whatever you want um i would recommend not confuse getting confused a lot

2:30:40with percentages and vw just try to pick something and maybe like percentages and stick to it

2:30:47but for the most part you'll realize that you don't necessarily need to give bits or heights

2:30:52to these elements the only reason i'm doing this is because these things don't have some content

2:30:57contained right for example if we really had an image right here it will automatically have its

2:31:02own dimensions right so that's why we don't necessarily would be giving a lot of width

2:31:07and height in the real world projects but yeah it's a good idea to just know about them as well

2:31:13so we have a width of 100 and a height off again let's not give this a height because like i said

2:31:19we are lacking content so i'm just gonna add a footer one and a footer to notice so you can see

2:31:24the moment i do that because we have some content right here it automatically appeared on the screen

2:31:30now you can sure go ahead and give it a padding of 10 pixel 0 and what this means

2:31:37this means padding top right bottom left so padding top is 10 pixel padding right is zero

2:31:46padding bottom is 10 pixel padding left is zero right top right bottom left it if you have two

2:31:53values if you just have a single value here then it's top right bottom left all same if you have

2:31:58two values here then it's top right bottom left oscillating right for example if i give

2:32:0420 pixels here see that we have more space on the left and you can see really right but we do have

2:32:10than compared to top and bottom so anyway we can give this a 5 pixel and we can also give it a

2:32:16border bottom of 2 pixel solid gray for example right there we go now it still looks horrible

2:32:26compared to the original side but we'll do one neat trick which will kind of fix them all so what

2:32:32we will do is we will go ahead and select body first of all and let's just go ahead and give it a

2:32:39height of 100 vh or kind of like minimum height at least we want at least one the body to be 100 vh

2:32:47the next thing which is going to be interesting is i'm going to set this to flex

2:32:51right and you see the moment i do that it kind of breaks it it breaks the layout but we don't want

2:32:57this flex to be row we want this flex direction to be column which is what it was earlier but now

2:33:04what we can do is we can stretch this section to take up as much width as it wants now we can

2:33:13go ahead and say that hey hey hey hey don't go ahead and take out any sort of width from nav

2:33:21and footer and how we do how do we do that we say flex shrink zero i don't want my header or footer

2:33:27to be shrinking but what i want is that section go ahead and take as much width as you want

2:33:36see now what happened here the way the reason what happened uh the reason why this layout is

2:33:43looking like this if i go ahead and open this in a new tab you will see and we have not have not

2:33:48discussed the chrome dev tools yet don't worry about this there is another course in the full

2:33:52stack learning path on this dev tools but just stick with me here for the sake of visualization

2:33:59so we have a body right it has got a nav it has got a footer and it has got a section the thing

2:34:05which we said here is that nav and folder should not shrink and if you do not understand this

2:34:10just go back a couple of videos you will find me discussing these concepts in great great depth

2:34:16when the flexbox was starting so we said nav and photo should not shrink that's fine so what should

2:34:22happen to section i say section should take up as much place as it could right and we know that

2:34:29body at least has the height of the full screen therefore section is taking up a lot of space

2:34:35here right that is cool but how do we center this now i mean that should be simple here

2:34:40right because this is again a reduced problem where you have a div and you want to center this

2:34:47and we have discussed this so what we want to do is we want to just say display flex here

2:34:52justify content center align item center and boom you're done and that's it that's how you create a

2:34:59nice little google like layout for yourself you can see now it pretty much matches a lot i mean

2:35:06not exactly in terms of the fonts or the layouts or whatever but in uh in terms of

2:35:10the positioning right so that is what you want to do right you want to go to different websites

2:35:17like even like code dam for example i would recommend that like go ahead on code damn

2:35:23try to create this layout again you should be able to visualize how these nav items would

2:35:27be placed how the search bar would appear how this gap would be created in between and so on

2:35:33right so try to go to different different websites which you see like in the guess of

2:35:37this footer just take example of the photo and try to construct them for now you can also go ahead

2:35:44i'm not sure how long it will stay like that probably but if you go to codedam.com projects

2:35:52you could see certain projects which you can also build which have certain helper files

2:35:57available to you in order to build those things and certain guidelines available to you so these

2:36:03projects would be also very very useful very very beneficial when you're learning layouts and

2:36:07stuff like this but a bunch of them also involve javascript so i'll recommend just holding your

2:36:12horses until and unless you do javascript but you can take a look at them how you can create them

2:36:22hey everyone welcome back and in this video let's just discuss about a very very very very

2:36:27very important concept in css again some of i think some of the fundamental things

2:36:32just like layouts is one of the fundamental things this is also something which i consider

2:36:37one of the fundamental things you should know in css and that is the concept of positioning

2:36:43now let's just go ahead and create i'm going to explain the positioning part from the last video

2:36:48which we did and create a span right here right just a simple span tag okay now what i'm gonna

2:36:58do is i'm gonna go ahead and first of all go to section span and create a background of yellow

2:37:05or you know blue for example because it could give this a little bit of

2:37:14better looking thing width of 100 pixel and height 100 pixels nothing fancy right so we

2:37:20have a small square here and obviously because this is a part of a flex box so it's it's kind of

2:37:28you know following the flex direction now what i want to explain in this video however is not

2:37:34related to flexbox it's related to a property in css called position now by default what happens

2:37:41is all the elements come with the property of position static a position static doesn't mean

2:37:48anything that's that's just a placeholder kind of value for example so what what is position

2:37:55first of all well i believe you will be able to appreciate and understand it in much more

2:38:00way if i just kind of used it right away so we have a value called position absolute

2:38:08now position absolute like it sounds it actually picks your element

2:38:15and picks it apart from the layout tree which you have from the layout structure which you

2:38:21have now if you think about html in fact i don't even need flexbox and all this stuff in this one

2:38:27if you think about html a little let's just keep body um you will realize that even though if you

2:38:34don't have any styles or anything that css just starts css just starts to not exactly css but

2:38:43html just starts to stack elements together right on one after another one after another and so on

2:38:49but with css you can change this behavior of elements you can pick an element

2:38:54bring it out of this behavior and position it anywhere on the screen by giving it coordinates

2:38:59position absolute kind of allows you to do that so if i go ahead and give this a top of zero

2:39:05and a left of zero you will see that this blue square just got stuck to the top of the screen

2:39:12right and if i try to actually let me just go ahead and open this in a new window because that

2:39:18will be much faster how i can explain and don't worry about this weird looking dev tools panel

2:39:23we will discuss how to work with that in another course but you can see right here at least um we

2:39:29have an area where i can see the styles and i can set this to one pixel right and now if i careful

2:39:36take a look at here and the behavior what's happening here if i increase this value with my

2:39:40keyboard you will see that this element is sliding down right so it's pretty apparent that the stop

2:39:46value is exactly controlling the coordinate of the top left this top left pixel of this element

2:39:55right similarly the left value is also controlling the left attribute of the top left l top left

2:40:02pixel so if i give it a new value you can see it pretty much just you know it's it's just

2:40:09increasing and it's just placing the element at a new place now you might think why this is why this

2:40:15is necessary i mean would there be any real use case of this at all and yes there is a use case

2:40:21even if what i'm about to tell you wasn't did not exist till css absolute property is super helpful

2:40:29but anyway there's a special use case of this and the use case arises when the whatever element has

2:40:38an absolute value has a relative parent what do i mean by that i mean for example let's say i have

2:40:45a 10 pixel top and 10 pixel left and i go ahead on section and give this a position of relative

2:40:53you see what happened here if this did not exist if this block did not exist

2:40:58what this blue box was doing is it was just taking up the 10 from left and 10 from top

2:41:04from the screen from the window right but the moment i give this section a position relative

2:41:10which is the parent of the span of absolute it actually considers this this red box as its

2:41:17ultimate you know zero zero coordinate system this is important because what position absolute

2:41:24does actually in fact is that it tries to go ahead inside your html and tries to go ahead

2:41:30to all these parents and tries to find which one has a position relative stuck to them

2:41:38and the moment it finds a single parent which has a position relative it just uses that as the

2:41:44coordinate system of you know you know just placing it from top and left if it does not

2:41:50find anything then of course it's just the screen right and you can do some interesting stuff with

2:41:55this now you have position absolute you know for example if you know the dimensions of a container

2:42:01you can pretty much just play around with this mess around with this as well right you can just

2:42:05place it anywhere um in that particular card for example you can give this a negative value as well

2:42:11so if i'll give for example write as negative 10 pixel um well we have the width as 80 vw that's

2:42:19why but if you take a look here you can see that this they've just slides outside this div and

2:42:24you know i'm not sure if you have seen but there are certain sites like we just post like certain

2:42:30numbers like new course and that's kind of like nice looking label for that right so that's how

2:42:36you style these elements that's how you pick them out of the tree and do all sorts of funky stuff

2:42:43so yeah that is how you use position absolute with position relative super important stuff which you

2:42:49should know that is how position relative works in harmony with position absolute and so that

2:42:56is all for this video make sure you are leaving rating to the course if you haven't share it with

2:43:01your friends and colleagues and practice along the way practice practice practice is super important

2:43:11hey everyone welcome back and in this video let's just go ahead and take a look at another value

2:43:16called position fixed which is kind of like position absolute but slightly different so what

2:43:24do i mean by that for that first of all let's just give our body a minimum height of 200 vh

2:43:30that means we will now be able to scroll this body right now let's just go ahead and change this from

2:43:36position absolute to position fixed and you will see a couple of changes here if you are careful

2:43:42the first change is that the box has moved slightly up for some reason and the second

2:43:48change is now when i'm scrolling this the box is actually stuck to the screen right and that's what

2:43:55position fixed does position absolute takes it out of the coordinate system the l takes out the

2:44:02element out of the regular html coordinate system right and puts it to the nearest relative parent

2:44:08position fixed goes one more step ahead and just pretty much takes out the element out of

2:44:13the screen and gives it to you and says that hey just go ahead and position however you want it

2:44:19and you can see because i haven't i have given top as negative values top and right

2:44:24it is actually going out of the screen because for position fixed the coordinate system is in

2:44:29fact the screen and not the parent element which has a position relative or absolute or whatever

2:44:35you can pretty much put whatever you like here but position fixed does not has a coordinate

2:44:40system which is bound to an element but it is only bound to the screen so you can

2:44:46only style it with the help of setting up coordinates on the screen and the fun fact about

2:44:52this is that it kind of sticks to the screen right it just sticks when you're scrolling and so on

2:44:58that's how pretty much a lot of these sites even for example for code dam i guess we use

2:45:03uh we use slightly different technique here which we'll again discuss but you can see this this kind

2:45:07of effect where the header stays the same is kind of like position fixed not exactly because you can

2:45:14see you cannot get this effect where you have a where you have something at the top and then

2:45:19it starts sticking but it's pretty close if that banner wasn't there for example if i remove this

2:45:24now you can see you know it seems like this is position fixed which is pretty cool

2:45:34hey everyone welcome back and in this video i just wanted to quickly tell you one more

2:45:39css property css position property that is position sticky now i just i don't know why

2:45:46i wrote all these styles in line but it's fine you can also write them in different style sheet

2:45:51but because this is just going to be a quick video i just wanted to show you one way you can

2:45:56bring the benefits of position fixed that is just having to scroll just having a fixed element

2:46:02which is scrolls with your scroll bar and the benefits of position relative that is relative to

2:46:08your scroll bar basically for example take a look at codem.com this header we have something at the

2:46:15top in purple but the header is position relative as long as i don't start scrolling and does not

2:46:22reach here so the way we do it you can do it with javascript solutions as well but the way

2:46:27we actually do it now is using css position sticky so for example let's say i have a yolo div sitting

2:46:35just right in the middle and let's say this has a style of i don't know like display not display but

2:46:43background yellow now what i want to do is i want to make this as position sticky so when

2:46:49i scroll past this yolo it just sticks at the top and currently it's not possible because if

2:46:55you use position fixed then always stick at top right or always stick at wherever it is

2:47:01and otherwise you need javascript solutions but now you can go ahead and use position

2:47:06sticky and give this a top of zero a top of zero just tells it how much distance you need from the

2:47:14top when the stickiness starts so if i go ahead and go go and you can see now even i'm scrolling

2:47:21this just sticks at the top if that if i give this a top of 20 pixel you're gonna see and i probably

2:47:28know this is not the right way to write css it's too cluttered but i hope you are understanding

2:47:33because as developers you also need to understand a little bit of way of working with bad written

2:47:39code or at least bad formatted code so anyway if i give this a top of 20 pixel you can see if

2:47:45i scroll down it starts crawling just before 20 pixels in the height right so you can just also

2:47:51see a little bit of green background at that time and it has a distance of 20 pixels from the top so

2:47:57yeah that's pretty much it that is literally how the code dams header also works in case of this

2:48:03thing right this is not position fixed this is position sticky so now you know one way of how to

2:48:09make cool elements on the web right so yeah anyway that is all for this video i hope you understood

2:48:16something if you did make sure you are leaving a rating to the course if you have done that

2:48:21already that's awesome if not just leave a rating and help some people in the comments if you can

2:48:31hey everyone congratulations on achieving completing this milestone which is completing your

2:48:37very first programming course in web development now i'm assuming some of you are extremely new to

2:48:43programming and if you have completed this this is a huge feat so don't don't think that this is

2:48:50a small thing it's it's a great achievement to complete your very first coding course

2:48:55now the question is people usually ask what's next what's next and we are improving the code

2:49:01dams ui we are improving this whole interface to make sure you actually understand what's next

2:49:06but if for the matter of fact if it's not there yet or if you're even seeing this video that means

2:49:11there needs a little bit of update in the ui which tells you where to go next

2:49:15and in this case what you have to do is go to your learning path and pick up the full stack

2:49:21web developer learning path and take a look at the next course in this case it's advanced html5 css3

2:49:26but it might be something different in your case right so make sure you do that make sure you jump

2:49:32right into the next course and keep continuing your full stack your front end whatever you

2:49:37are doing in that particular journey but yeah that's pretty much it for this video

2:49:43hopefully you understood a lot of new things in this course and hopefully that makes you

2:49:49starts your front end web developer or full stack fifth developer journey whatever you are doing

2:49:55that is all for this video hopefully see you in the next course really soon

JavaScript Essentials

2:50:04hey everyone welcome to the very first video of this new course on javascript which is the part of

2:50:12full stack web developer learning path on code dam you can find this course on front-end web

2:50:17to proper learning path as well doesn't matter but what matters here is that we'll start from

2:50:23ground zero we'll start from basically assuming that you have no information about javascript and

2:50:30we'll build that solid framework of understanding along the way in this course before that make sure

2:50:37you have done the first three or whatever amount of courses you have before javascript in this

2:50:42learning path and the best way to follow this is from code dams learning path code damn.com slash

2:50:48learning paths so make sure you're following the learning path in order because if you're trying to

2:50:53learn javascript before actually getting to html or css or even i would say internet fundamentals

2:50:59which is important then you will have a hard time later on so that is all for the introductory part

2:51:05super excited to start this course with you hopefully you are too this is going to be

2:51:09an interactive course that means you will have a bunch of exercises and projects to complete

2:51:15along the way and i highly highly recommend to do them and not just watch videos only

2:51:25hey everyone welcome back and in this video we'll quickly take a look at how you can set up your

2:51:30development environment so that you are able to learn in this whole course and beyond that as well

2:51:37now for the vs code the offline setup i would highly recommend if you go back to the html css

2:51:42course and try to look to that video because we go in depth on how to set up uvs code for your local

2:51:50system otherwise what i do recommend and what i would also be using is the code dams online

2:51:56playground so you can go to codedump.com try to look for playground it might have a little bit

2:52:01of change to ui maybe by the time you're looking because you're right trading very fast so maybe it

2:52:06changes and once you go ahead you should see some sort of html or css playground just go ahead and

2:52:12open that the moment you open it you will be able to see that you get a live ide within your browser

2:52:20which also saves your work so it's completely fine to use it for practicing and come back to it later

2:52:26similarly you will find the same ide also embedded as exercises right so you would see them

2:52:33this ide interface in the practice labs further ahead so this will also feel a lot home to you now

2:52:39in order to edit this ide edit the files inside this you can see we already have these three files

2:52:45index.html script.js and style.s style.css well we are familiar with these two files

2:52:52and javascript is all about learning what goes inside the script.js and a little bit of you

2:52:58know the html file so don't worry about this if it seems confusing um you know you don't necessarily

2:53:05have to look at the javascript syntax yet we will go through this one by one what exactly whatever

2:53:11means but yeah once you have this screen up and running you can see whatever changes i'm making

2:53:16are automatically synced to the right side and you don't have to worry about

2:53:21um anything except the code here which you're coding so that is cool

2:53:30hey everyone welcome back and in this video let's just start with the fundamentals why do you even

2:53:36need javascript we will go into the depth of this a little bit but just to give you a very

2:53:42real world example of why you need javascript is this right here right so if when i when you

2:53:49change this text right here you see the page on the right refreshes right so on code damn you can

2:53:56see whenever you are making some change it happens automatically and this is one of the examples

2:54:00where we use javascript what we do we just simply in the in the code dams source code this id source

2:54:07code we are simply seeing that hey if there's any change in this file refresh this page well it's a

2:54:13little bit more complicated than that but you get the idea that if there's any change in this file

2:54:17refresh this page so you see programming is all about logic it's all about building those chain of

2:54:25logic and links and if else and going down that rabbit hole if you understand that you will be

2:54:33able to understand javascript in no time so our aim with this course is not only just to learn

2:54:38javascript but also learn programming in general because you would realize once you start learning

2:54:44javascript a lot of things are transferable or if you're somebody who has a bit of experience

2:54:50with some other programming languages you will be able to relate that javascript is very similar so

2:54:54that's the idea we also want to develop the core understanding of the language not just the the

2:55:00basic language itself because that's something you can do pretty much anytime anywhere right with any

2:55:06language but what really makes a good programmer if you is if you understand the core fundamentals

2:55:13but anyway let us start with a hello world of course like we always do and for this

2:55:19for this playground at least what i can tell you is whatever the syntax here is you can

2:55:25leave a bunch of these script files if they are still present by the time you're watching this

2:55:29if they're still present just leave them here this script file exists because we want to have these

2:55:35browser console logs reflected right inside um our area we don't want to go into the chrome dev tools

2:55:41but we'll see how we can work with that anyway i'm gonna remove this and has the hello world program

2:55:48for javascript all we have to do is we have to make use of something known as console.log

2:55:54hello world and don't worry we'll also take a look at what this is but you can see we get a

2:55:58hello world here in the console of the screen which is basically the console of your browser

2:56:04right so if you open this in new tab you will see we get nothing but if you go to

2:56:08the inspect which we have already done by the way if you are coming from html course we have

2:56:13used this panel right so if you go to console you will see we get this hello world with us

2:56:23hey everyone welcome back and in this video we're gonna be taking a look at a very simple thing in

2:56:29javascript which is variables and very simple but fundamental things in programming languages as

2:56:34well which is called as variables so what variable is it's basically a placeholder that holds a value

2:56:42that's all it is right so you can have let's say if i give you 10 plates to hold it's not

2:56:51possible right you would hold two plates in your hand and you need for example some different

2:56:58some table or some sort of thing to just put the rest of the eight plates similar thing exists with

2:57:03computers with cpus precisely cpus cannot hold a lot of information all together right they need

2:57:12some place to put the temporary information and that that's the temporary information is called as

2:57:18ram right so your ram inside your computer holds that temporary information random access memory

2:57:24in programming languages analogic analogous to that we have variables which hold temporary

2:57:30information which we might or might not use later in our program it depends on

2:57:35us right so how do you create these temporary containers well in javascript we make use of

2:57:43two keywords to create these and let me also introduce you with uh with javascript syntax

2:57:48with this and that is using let or const these are the two keywords which we use to create variables

2:57:55in javascript and the syntax is const let's say my first variable then an equal to sign

2:58:04and then the value which you want to set it to let's say 250 for example which is just a number

2:58:10so a couple of things you can see that i have a name of the variable i have a keyword

2:58:17which basically says that hey this whatever thing you're writing is in fact a variable

2:58:22and then i have a value with an equal to symbol that is how most programming languages work i

2:58:28mean there might be some difference in how the variable is declared or how the value is assigned

2:58:34but for the most part you will see that's how this works now once you have this variable you

2:58:41can pretty much do a lot of things with this right you can maybe add a few numbers you can subtract a

2:58:46few numbers you can do a bunch of stuff but with javascript you can not reassign a variable which

2:58:55has got a const value for example let's say for a moment let's pretend that you understand what

2:59:02console.log is right for now we'll just consider console.log as a simple function which puts

2:59:07the value here right in the in the bottom area so if i go ahead and console.log this

2:59:12you will see that i get 250 console locked here now if i go ahead and try to make this 251

2:59:21what you will see is that we get an error which says assignment to constant variable right so

2:59:27this const right here means that hey whenever you create this value you have to keep this the

2:59:33same value all the way and you might be thinking like what's the use of this i mean if variable

2:59:39actually stands for a variable right and you are saying this is a constant variable which is

2:59:45i don't know what's the word called in english uh but it's it's like you know opposite so you're

2:59:51saying constant but variable but this is super important because of number of reasons which we

2:59:57will discuss later down the line but this just means that once you initialize this variable

3:00:02with a value you cannot change it later down the line in your program right now of course

3:00:08there are a bunch of edge cases we need to be careful about but we will discuss that later

3:00:14now the second part which we discussed was how you can create a variable with let keyword

3:00:21led this keyword right here what this does it does the pretty much the same thing but you're seeing

3:00:29that i did not get that error anymore so what has happened well you see that with let you actually

3:00:37tell the javascript that hey okay i'm setting this variable but you can you're free to just

3:00:44change this value later down the line if you would like to right so now if i go ahead and console.log

3:00:49this my first variable you would see that we get two console logs the first one is 250 and the

3:00:55second one is 251 right so that is how it works that means with let you can reassign the values

3:01:05with cons you cannot reassign the values and if you look carefully what you will observe is that

3:01:10i am not using the let or the const or any other modifier after i assign it once or after i use it

3:01:17once and why is that because javascript already knows that this variable has been created right

3:01:23so we only need to use this initializer keyword or whatever you want to call this led or const only

3:01:29for the first time if you try to do it right here if i try to do let here you would get an error

3:01:36which says that identifier myvariable my first variable has already been declared this error

3:01:42message simply means that hey go ahead and see if you already wrote my first variable somewhere

3:01:48before in your code similar thing with const so if you change this to const you will get the same

3:01:53thing you know the same error basically so that means you should always use let or const once for

3:02:00declaring the variable and the rest of the places you just have to use either for accessing it or

3:02:06for reassigning it you just have to use it without anything basically right so this is all you need

3:02:13to know about variables in javascript there is also a third way to make variables in javascript

3:02:18using war we are right so this also used to be a way in javascript but please don't use it right

3:02:27for the reasons which we will discuss later this is dedicated this is no longer required

3:02:33do not use war to create variables in javascript it is supported and it will be supported for

3:02:38a very long time in future as well but don't use war right use let or use const

3:02:44and finally you would have observed that you can also create variables without actually

3:02:49defining anything without actually putting anything here at all which might seem like

3:02:55you know that i just wasted your six minutes now that you did not need to do that at all but don't

3:03:01do this again because of the reasons which you will discuss these reasons are due to scoping

3:03:06and we will discuss these issues later down the line but for now the best rule

3:03:10of thumb you have to remember at least for now is always use const or late

3:03:15some sort of identifier here and yeah that's that's all you need to remember at the moment

3:03:26hey everyone welcome back and in this video we'll be looking at a very important thing in javascript

3:03:32and in programming languages in general and that is the data types supported now javascript is

3:03:38a language which can store a lot of types of values in a variable like i said variable is

3:03:44a empty container which you can use to just hold values temporarily right as long as their scope

3:03:51lasts technically we will discuss about scoping so don't worry about that yet but what do i want to

3:03:56discuss here is all the kinds of values which you can give this variable and what does that mean and

3:04:03we'll also just keep an eye on the console at the bottom so that we can see what's happening

3:04:08all right so first things first numbers are simple right we understand numbers like 1 2 3 and so on

3:04:16right so whenever you store a number you will see that you never use quotes or anything right single

3:04:22quotes double quotes nothing that's it you just put a number you put an equal to sign and put a

3:04:26number now i want to store a string which might be my name which might be anything right so for

3:04:33example for my name i will just write mayhew right so this is a string and the way you store strings

3:04:40is that you enclose them into double quotes or single quotes javascript does not care if you use

3:04:47double quotes here or if you use single quotes it doesn't matter in some languages it matters

3:04:52does not matter in javascript the next type which we have is boolean which is either true or false

3:05:01so something like you're above 18 can only be true or false right it does not make sense to have

3:05:08an integer answer or maybe i mean a string yes or no is also fine but we for the boolean values for

3:05:15values which can only have two possible outcomes we usually go with true or false so you can go

3:05:21ahead and give this value as true again without the quotes or false right without the quotes as

3:05:29well so you have numbers you have strings you have booleans which is like um for example my

3:05:37age could be 22 above am i above 18 could be true and my name could be mahul right so this

3:05:52is like reflecting three different kinds of uh variables and you can see we get an error that

3:05:57my first variable is not defined because we are trying to console.log something which is not there

3:06:02right so another important thing which i would just pass on as a quick hint is always try to

3:06:07read error messages if you see an error if you see the code is not working try to see what the

3:06:12computer is telling you in a lot of cases it might just seem practical for you to just skip

3:06:18over it but trust me computer wants to help you so make sure to read the error messages

3:06:24so yeah we have the three fundamental types with us string boolean and number let's take a look at

3:06:30a couple of more so what i'm going to do is i'm going to write an a variable called friends right

3:06:38and i know that my friends well they could be a string that means i can

3:06:43just separate them in a comma but that's not the best way to store something which

3:06:48can have a lot of values a better way for that is to use an array now what this is an array if

3:06:55you're seeing this for the first time an array is a collection of usually the same data type

3:07:03right and why do i say usually because javascript is lenient javascript allows you to store

3:07:10an array with different kind of values as well this is completely fine

3:07:14so if i go ahead and console.log friends you will see i get 22 and true like this if i add mahul

3:07:21here as well you will see i get mayhew logged in as well so what is an array i mean what is this

3:07:28weird syntax and why do i have to write these square brackets right here well you see if you

3:07:34just write like this this is wrong syntax because well it doesn't really make a lot of sense right

3:07:41this square bracket just denotes that hey this is a start of an array which consists of ordered

3:07:48items that means the order matters here and you can access them with something known as index what

3:07:56index they have and we will discuss about arrays in great length but just to give you a quick look

3:08:02at this let's say if i want to access true from this array so what i will do is write friends of

3:08:07one that is friends and then in square brackets i will write one and you can see i get true

3:08:14because indexes in computers and in javascript especially start with zero so if you want to get

3:08:2022 in the console below you will write friends of zero if you want to get true you will write

3:08:26friends of one if you want to get mayhew you'll write friends of two this brings me to the next

3:08:32data type in javascript and that is what would happen if i write friends of three here right

3:08:38so let's just go ahead and take a look at friends of three and you see we get undefined although we

3:08:43don't have a string here calling called undefined right so what is this well this is not a string

3:08:50this you might get confused here by seeing that this is a string this is another kind

3:08:56of data type you can say or kind of value which you can provide to the variables and you can say

3:09:01some special special value as undefined right and again you can see it's not in quotes

3:09:09that means it's working fine and it's fine so if i console log this you see we still get undefined

3:09:16but what exactly is undefined well undefined is basically a value of a variable which has not been

3:09:24initialized so here we are obviously giving it specifically the value of

3:09:30undefined so that's why it works but let's say if i go ahead and remove this

3:09:35right well in the case of const we get an error that it says that missing initializer in the

3:09:41const declaration because remember i told you that const cannot change its value later down

3:09:46the line right so you need to give it a value then and there but if i switch this to let for example

3:09:52so i say let some special value and i console log this it saves me undefined but later down

3:09:58the line i say okay you know it should be 22. then if i console log this then it gives me 22.

3:10:05so undefined is basically you can see i did not assign this a value but it

3:10:08got undefined by default so it's a value for something which has not been initialized yet

3:10:14right so that is all you need to remember in terms of undefined and we can move forward with that all

3:10:21right the next one which we have is beginned now what do i mean by that that means big in number

3:10:30this is a number which is big which is which could be really big right so for example in this

3:10:37case you see my age is 22 which works fine but javascript has a limit on the size of this number

3:10:45right so if you have a number which is of certain magnitude let's assume 1000 in this case for the

3:10:53sake of simplicity javascript would kind of not work well with 1001 and 1002 and 1003 right the

3:11:01math breaks for javascript and why is that because computers have finite memory right so javascript

3:11:08has to cut off after some point that it has to say that hey i'm not going to store any number

3:11:14beyond this and it's a really really big number right it's a really big number it's

3:11:19this number is actually 2 raised to the power 53 minus 1 right which is a huge number but

3:11:27if you are working with large sets of data in javascript you might need even bigger numbers

3:11:33right so you might need a lot of bigger numbers which are much much much much much much bigger

3:11:41than 2 raised to the power 2 raised to the power 53 and if you try to let's just get rid of this

3:11:47if you try to console log this i mean this would work fine but the way i said it is that arithmetic

3:11:55for example addition subtraction multiplication would break on this number so the way you put

3:12:00the way you make this as a big number is you write an n after this and the moment you do that

3:12:08you would see that well we do not get a console log here but if i go right here in this console

3:12:15you would see it craze out kind of but we do get a console log and the best way to verify

3:12:20that this is a big end is using something known as a type of operator which we'll learn about

3:12:26very soon there are a couple of more data types you can say in javascript which are objects

3:12:32which are functions which are symbols and which is also null one one data mode one more data type

3:12:40is null just like we have undefined we also have a value called null which you just go ahead and

3:12:46use you will see you just get null right so the difference between null and undefined is basically

3:12:54null is like explicitly saying that this value does not exist or should not exist right whereas

3:13:01undefined just means that this variable has not been initialized yet so that's the difference

3:13:07right null is basically saying that this should be blank or this is empty and this should be empty

3:13:14undefined is just saying that hey this hasn't been initialized yet that's all but yeah there

3:13:19are like i said a bunch of more variables and data types in javascript which we will discuss do not

3:13:24worry about them but we will pick them up as the time comes but for this video i think that is all

3:13:35hey everyone welcome back and in this video let's just quickly take a look at

3:13:39type of operator right so like i said we can create multiple variables i'm gonna say type of my

3:13:47h as the variable name and i'm gonna write my h here first of all just to give you an idea of what

3:13:54i'm trying to do you see in javascript what you can do is you can assign the value of a variable

3:14:02as another variable right or maybe a bunch of more variables let's say you want to add a few

3:14:07variables here so you can do that that's completely fine but what you can also do

3:14:12in javascript is you can write the keyword called type off and you can see it immediately turns red

3:14:18because this ide knows that this this is a special keyword and what this expression evaluates to if

3:14:25you just take this expression right here what this expression right here evaluates to is a string

3:14:32which is the data type of that particular variable so a couple of things to mention

3:14:39here remember here is that this thing right here gives you a string value just like me hole is and

3:14:46the second thing is that the string value is actually a data type of whatever the variable

3:14:52you wrote after type off right so you can see in the console if we take a look at this we get

3:14:56number because my h is in fact a number if i use type off with this you will see we get boolean

3:15:04if i use type off with me my name that is we get string if you type off with friends you see we get

3:15:13an object and the reason we get an object and not an array because in javascript arrays our object

3:15:19right so don't worry about that yet it just means that you know it's some sort of special value

3:15:25for some special value which is actually null you see we still get object this is interesting

3:15:31this is a weird edge case in javascript as well which might get caught you off guard

3:15:35so how do you distinguish you might ask how do you distinguish between an array and a null type and

3:15:41there are ways don't worry about them but what you have to remember here is that if you write this as

3:15:45undefined you will get the value the type of as undefined right so null both null and arrays are

3:15:53type of object but undefined has a type of itself right that is important then if you move on to

3:16:00begin number you would see that we get big end and that's it that's pretty much all we have at the

3:16:07moment in terms of what whatever values we defined so yeah that's pretty much it for type of it's not

3:16:13super handy i wouldn't say that you would be using this a lot of times but it this is something which

3:16:19is irreplaceable when it is needed because this can help you in data validation or this can help

3:16:26you in determining what kind of data you're dealing with without actually taking a look at

3:16:31um the code above which sometimes is not even possible right if you are using some

3:16:36library or anything or you know just use an input from untrusted sources

3:16:41so that's that's a good um way to just validate what kind of data type you are getting

3:16:53all right everyone welcome back and in this video let's to do a little bit of math operations with

3:16:58numbers because numbers are fun and you will be using a lot of numbers in your journey so

3:17:03i'm going to start with cons and i'm going to show you um what is possible so right now i'm

3:17:08going to start with my h as 22 and what i can do is i let's say i want to increment a year

3:17:14as fast and i want to increment my h223 so i can do my h plus 1 right which is basically what you

3:17:21would also write on paper kind of right if you are doing math problem or anything and that's

3:17:27what you do with programming as well you just write plus one but you can see that i still get

3:17:3222 even though i tried to do my age of plus one and the reason for this is we are not assigning

3:17:38this value back to my age right because this plus one although it does increment this to 23 but we

3:17:45are not storing this value anywhere so how do we store this value well you might think that hey

3:17:51i can just go ahead and use like something like this and this is completely fine but remember what

3:17:57i told you about const is that you should not or you cannot actually um reinitialize its value so

3:18:05how do you fix this you have two solutions right now the first solution is you change this to lit

3:18:12and the moment you do that you will see that it works just fine why does it start working because

3:18:17let allows you to change the value after you initialize it const does not the second way is to

3:18:24actually create a new variable called my updated h and then do a my h plus one and in the console log

3:18:33the statement just pass in my updated age and the moment you do that you will see that you get a

3:18:38nice updated value this time i think this is the first time we are seeing something in the console

3:18:44which we did not explicitly write in the code right so this is a big moment where you are

3:18:49actually computing something for the very first time this is the very first time you're computing

3:18:54something right you're telling the computer that hey go ahead and add something to it and this is a

3:19:01revolutionary thing if you think about it because a computer which can add once it can add twice it

3:19:07can add so many times and it can do it and at an exponential speed right compared to a human

3:19:12so that's why computers are well fused because they compute that's what computer actually stands

3:19:18for as well but anyway that is a very simple operation right you can also add two you can

3:19:26also add three four five whatever whatever you would like to do you can do with this

3:19:31and the next thing you can do is you can also subtract things with a negative sign which is just

3:19:36a simple dash um not sure if zooming in here would really help but i hope that you all know that what

3:19:44addition and subtraction is i'm not probably going to go ahead on that in this course so

3:19:50the next thing you can do is multiplication right so 22 times 5 is 110 and you see that you get that

3:19:57in the console and also you can do division right so you see if you divide 22 by 5 you get 4.4 as

3:20:04the output which is again fine what you can also do in javascript is you can use double asterisk

3:20:10right here and this double asterisk symbol you can see it gives you a

3:20:14huge value because this is setting this to a power so this essentially means setting 22 to the power

3:20:21of 5 22 to the power of 5 and i think we haven't discussed what i just wrote here which is called

3:20:27as a comment in javascript so we'll do that in the next video don't worry about that

3:20:31but essentially what this means if i have let's say 2 and i have 5 then this should give us 32

3:20:38right because 2 multiplied by itself 5 times is 32 2 times 2 4 8 16 and 32 right so this is another

3:20:48operator these are super handy for example if you want to have let's say an average of a few numbers

3:20:57um what we can do is let's let's write a very simple program right a very manual but very

3:21:03simple program i'm gonna write my friend's age and i'm gonna have let's say 20 19 22 21 and 23

3:21:11right and i want to calculate my friend's average age using a computer i can do it with a pen and

3:21:19paper but let's use a computer now remember i told you how you can access the elements in an array

3:21:24by using index so i can get 20 if i just use average right here you would see i get 20. if

3:21:31i have a 1 we get 20 19 we if i have a 2 we get 22 and so on so what we can do is before calculating

3:21:40average we can calculate the sum of them and i'm doing this very manual way there are obviously

3:21:46better ways which we will look at later but right now you can see i can just go ahead and keep on

3:21:52adding them 0 1 2 3 and 4 right so there we go so now we have a sum which consists of all these sum

3:22:02and i'm going to say total friends which is one two three four five so i have five total friends

3:22:10and the sum of their ages is this so what i can do right now is i can say um

3:22:18again we have not discussed console log much but stick with me here we will very soon and then it

3:22:23will be much more clear but you can also pass all sorts of values in console log right separated by

3:22:28comma and they will all appear down here so what i'm going to do is i'm going to say sum of friends

3:22:35h and just pass a comma and a sum which just shows us this value 105 which is good and i'm going to

3:22:42say console.log total friends and this will be not five but actually my variable total friends

3:22:49here and then finally i can say average is equal to sum by total right and if i just do console log

3:22:58average friend age is average and you can see the console in the console we get 21 which is

3:23:07fair enough because 105 divided by 5 is 21. so you have written your very first javascript program

3:23:14by just calculating the average of a few numbers and yeah we that's that's a great start i mean

3:23:20you have figured out what math operators are and how to perform addition subtraction multiplication

3:23:26divisions and exponential and actually write a great program a great small program as well

3:23:36hey everyone welcome back in this video i will quickly discuss um something known as increment

3:23:42and decrement operators right now these are just fancy way of doing something which we have just

3:23:48done in the last video so first of all let me just clear this out and let me just go ahead

3:23:53and say my h again as 22. now we saw that if i just make this lit i can do my age is my h

3:24:02plus one and if i console log this you will see that my age in fact comes out to be 23.

3:24:09now there is another fancy way of doing the same line which line number two does

3:24:13and that is by writing my h plus plus that's it no late no reassignment nothing like that

3:24:20remember i told you that hey my h plus one would not work because we are not storing this value

3:24:25anywhere right you can see my h plus 1 still gives me 22 but my h plus plus gives me 23

3:24:32right so this is because these two pluses are special these two pluses actually evaluate to

3:24:40the same statement which we wrote my age is my age plus one so you might ask why do we need that well

3:24:47we technically don't i mean we would still be able to write code if that did not exist in fact a lot

3:24:52of languages also does not include the support of doing plus plus um like this but i mean just

3:24:59another feature right just like your phone has tons of feature a programming language also has

3:25:04tons of functionalities does not necessarily mean you have to use them always but it's good to know

3:25:10that it exists anyway there's another operator called minus minus which exists which is you know

3:25:1722 goes to 21. you might think there might be a star star operator but it would not make i mean

3:25:24i don't know like it could make a lot of sense if you just want to square the number real quick

3:25:28but no that does not work these increment and decrement operators only exist with addition

3:25:33and subtraction because these are the most common things which people usually do especially in loops

3:25:38which we will see when you want to loop over a certain statement you want to maintain a counter

3:25:43which just keeps on incrementing by 1 1 1 1 until it hits a certain condition so there

3:25:48is where we use these conditions a lot but you should anyway know about this plus plus adds one

3:25:55minus minus removes one and the fun fact about this is that you can add these plus plus

3:26:02after the variable or before the variable and there is a slight difference in these two ways

3:26:09which we will discuss maybe later down the line but nothing you should worry about at

3:26:13this stage right you can add this before the variable you can add this after the variable

3:26:19but of course you cannot add this before and after this would not work right this is

3:26:23like a weird syntax so if you want to increment it by two either do it twice or

3:26:30just write a single statement which just says my age is plus my ages my age plus two right so

3:26:39that is how you would work with it and that is how increment and decrement operators also work

3:26:49hey everyone let's just go ahead and quickly discuss about console.log in this video which

3:26:54we have been using for a long time but i haven't really gone over to what exactly we are doing here

3:27:00so you can see that console.log is actually just putting some value here but it is especially very

3:27:07helpful if you are doing this offline or just you know just trying to debug something some value

3:27:13what console.log does is before actually getting into that let's just discuss about what a console

3:27:19is right so if you see right here i'm not sure if you have used this before or not but we briefly

3:27:25discussed this about in the internet fundamentals that you have a concept of a terminal right so

3:27:30this is a terminal which is essentially a command line access to a computer right so whenever you

3:27:38are running a programming language you can tell that programming language to output certain code

3:27:45or certain outputs whether it's mathematical whether it's some object whatever it could be

3:27:52into this terminal into the console right so this area right here whenever javascript is running it

3:28:00has a special area not exactly the terminal but it has a special area called console

3:28:05which pretty much looks like this terminal right so where is this console in the browser if you go

3:28:11ahead and open this in the new tab right click on this page go to inspect you will see that there is

3:28:18in fact a tab called console right so you go to console and you will see all the logs which you

3:28:24generate right here as well so for the sake of ease what we have done at code dam is whenever

3:28:30you use a console log we just put it right here in front of you right so you don't have to just

3:28:36switch between codes and uh console all the time therefore you can use it from right here so anyway

3:28:43the point is that this console.log is a function we will discuss about functions in javascript

3:28:48in the next video probably but what a function more or less is this function is is that you can

3:28:55write console log open a circular uh open parenthesis not a circular bracket

3:29:02and go ahead and supply these values whatever you want to console log separated by commas

3:29:09right so let's say you write the second value as 2 3 mayhew whatever right so whatever you write here

3:29:18you can see it appears in the console as well as in the browser if i refresh this you will see we

3:29:23get this so this is cool because now you are able to see whatever kind of values you are writing in

3:29:31the console right or you have in your program why this is helpful because your program can contain

3:29:39um intermediate states for example let's say let's let's take example of the last case itself

3:29:45right where we were calculating averages of the friends so we had a sum variable right we had a

3:29:52um let's say the total count variable and so on so we had all these variables and these were not

3:29:59the values which we could actually see right which we could inspect from the code itself

3:30:04therefore we could use console to just print them out and check the values in a running program what

3:30:09those values are so in a way console.log actually helps you to introspect a running program as

3:30:16well so it's kind of used as a debugger as well right it's not a debugger but you can use

3:30:22console.log for debugging purposes if something is not working you can print the values which are

3:30:27temporary intermediate values and see what value is going wrong so that's the use of console log

3:30:34and of course you can print funny messages here as well want to work with us come join us at carriers

3:30:45you know stuff like this i think companies do this all the time right

3:30:54hey everyone welcome back and in this video let's just go ahead and take a look at functions

3:30:59in javascript what functions are how you can work with them and what do they mean so what i'm going

3:31:05to do is go ahead and create a very first function first of all and after that i'll explain it to you

3:31:11what that means so i'm going to go ahead and put this console.log statement inside this block i'll

3:31:18name this function and i will say make console log and like this and if you don't understand

3:31:25what i'm doing it's fine what you have to realize is what's the syntax of this the syntax of this

3:31:32is i have a keyword function then i have a name then i have these two brackets with me and then

3:31:39i have an openi opening a curly brace right so this is the syntax of how you write a function

3:31:47in javascript and a closing curly brace now whatever you write inside of this function

3:31:53is the function's body now what is the use of this well consider the statement console log of hello

3:32:04world and let's say you want to console log hello world but you also want to console.log a variable

3:32:11there right so you have two statements and it is possible that you might console logs this multiple

3:32:16times right so let's say we have another statement which says total count right so if we go to

3:32:23the browser logs for example let us see if this is still attached to our index.html script

3:32:31and yep it looks like it is but you can see that we do not get any locks right so why that is

3:32:38happening now the reason that happens is because this console log this function right here is a

3:32:45function and a function is a piece of block which does not execute until and unless it is called

3:32:53so how do you call this function you just write the name of the function in this case it's make

3:32:57console log and write these two brackets right opening bracket and a closing bracket and the

3:33:04moment you do that you can see we get the first statement and the second console log if i write

3:33:10it again you will see that even though i haven't really copied pasted this console statements

3:33:17but we still have two sets of console logs that is because we are using two console logs in this call

3:33:24function statement this is as simple as it can get so i can go ahead and write this i can go ahead

3:33:32and let's just go ahead and make another function where we will say function print all variables

3:33:39right and the only uh use of this function is to write all the variables my age is my age right my

3:33:51sum is sum and total count is total count right so now what i can do is whenever i want to print

3:34:01all of these variables instead of writing these statements over and over again i will say print

3:34:06variables then let's say if i make a change to my age then when i make a change to my age you

3:34:11will see that let's say if i make it 23 and then if i say print all variables again you will see

3:34:20that my age first of all was 22 then it comes out to be 23. rest of the variables are same

3:34:26so this is like one of the most useless use case of a function but there is a lot of use case of

3:34:33functions in terms of you will be using functions all the time in your code so it's important to get

3:34:39the basics right how you create a function what is a function body anything which goes into these

3:34:44two brackets and how do you call a function this is like a very 101 function 101 for you

3:34:55hey everyone welcome back and in this video let's just go ahead and see how you can

3:35:00pass certain parameters to a function and what does that even mean so you see functions are

3:35:06okay this code block is okay that if you want to execute it multiple times you don't have to

3:35:11write all these lines which is fine but the true power of functions come in the fact that they can

3:35:17work with dynamic data that means you can pass you can create a generic function for a certain

3:35:24certain you know operation and pass in some inputs to it and get a completely different output

3:35:31so how do you do that the way you do that is you can pass certain variables to this

3:35:38function or certain parameters and let's say in this case i have a function which adds to my h

3:35:47right so right now the only thing it does is that it just adds my h is equal to my h plus one

3:35:55so that's all it does right so i can say add to my h and if i console log my h after this

3:36:02console.log my h you will see that we indeed get 23 in the console now let's say i want to make

3:36:11this number dynamic the amount of age i'm adding how do i do that well i can just say that hey

3:36:17get my or you know not get my butt something like increment by something like this now this is a

3:36:26this is just a keyword i just wrote it in these two brackets in these two parentheses

3:36:30right now what this is is that it is an argument to this function and what are the argument what

3:36:38are arguments in general arguments or specific values which you can pass when you are calling a

3:36:44function like this so for example in this case if i want to populate this increment by with

3:36:505 i'm going to pass this like this so if i access this function if i access this variable right here

3:36:57if i go ahead and console.log this you would see that we in fact get 5 as the console log and you

3:37:04can see we don't have a lit or a const here we don't need that in an argument so you can just

3:37:09go ahead and name your arguments like that it's fine now the true power is that i can just go

3:37:16ahead and replace that one with an increment pi and now you can see i get 27 if i have adds to my

3:37:22h and then 7 for example you will see that we get 34 now because 7 plus 5 plus 22 is 34. right so

3:37:32this is how you pass an argument to the function now you can pass multiple arguments right it's

3:37:37not that you just have to pass one single argument you can say for example something like multiply by

3:37:45multiply by right and if you just pass this as 2 and you do something like

3:37:52you know you can do weird stuff if you would want but this comes out to be 54 right because well 22

3:37:58plus 7 22 plus 5 times 2 is 54. so that's cool i mean that's completely fine but you

3:38:06can see that you can pass multiple values here and remember what we discussed about undefined

3:38:12data type in javascript let's say if i did not pass this value right here you will see that um

3:38:19first of all what we get in the console is undefined for this argument because

3:38:24like i said it's missing that's what undefined means it's not initialized or it's not passed

3:38:30like that and second we also get another number so if you see nan anytime in your

3:38:35console that stands for not a number that means you're trying to use a mathematical operator

3:38:42on something which is not a number right in this case it's undefined in our case it could be string

3:38:48it could be function you might be multiplying it with a function or anything but yeah that's

3:38:52what it means so anyway i hope you understood the concept of functions you can create very

3:38:57simple functions um once we discuss one more part about them that is the return statements we'll do

3:39:03that in the next video and then we can get into a little bit of basic math with functions as well

3:39:14hey everyone welcome back and in this video let's just go ahead and take a look at how we

3:39:21can go ahead and make use of return statement in a function and what does that even mean

3:39:28so first things first you can see i'm right now i'm assigning this variable which is outside

3:39:33directly and then we just try to log it and that this console looks perfectly fine but

3:39:39this practice although this is a bad practice because we are this function is not pure in

3:39:44in the sense that it is mutating the state outside it but anyway leaving

3:39:48that aside let's say this was const right i don't want my my variable to be modified

3:39:55right now we are getting an error that we are assigning it to a constant variable

3:40:00and we can fix that i mean not exactly fixed but we can just remove this assignment and say

3:40:06that hey this is fine right because this is allowed we are not changing the my age here

3:40:12the variable here but how do we get the value of whatever this is this is being computed

3:40:19outside this function that means let's say this function says that it adds to my age right this is

3:40:26the end goal of this function so how do i get out the final end goal value for that we use a keyword

3:40:33known as return in javascript so what this return does is let's say if i add this return keyword

3:40:40what this does now is that if i store the result of this function in another variable

3:40:46my new age for example so what i'm doing essentially here is that i'm saying that hey

3:40:52whatever this function returns me which is done by this return keyword store this in this

3:40:59variable so i can say my h comma my new h like this and you can see we get 22 and 54 like that

3:41:07so what's happening here is that because i'm returning this computation i get that value

3:41:14returned into a new variable and if you do not store it then it's very well lost right it's

3:41:20basically lost at this point so yeah i mean if you need to store it you need to give it a variable

3:41:26like this now another thing with the return is that if you do not return anything from a function

3:41:34if it is empty or you know if it just has a bunch of statements like this you can guess what it

3:41:39returns it returns you undefined a value which is not set a value which is not initialized right so

3:41:46the b the default behavior of javascript is if you do not have a return statement in your function it

3:41:52just returns undefined implicitly if you're coming from a different programming language which might

3:41:58throw some errors if you're not having a return statement that's not that's not what happens with

3:42:03javascript you don't necessarily need to return always from a function but you should i mean it

3:42:09just makes clear that hey this is where you are pointing that it's the end of the control or end

3:42:15of the function call right even if you don't have anything to return for example let's say if you

3:42:21just want to increment some by 100 and that's it you can just mark an empty return statement which

3:42:29is also pretty much just means return undefined if you don't write you know anything else out

3:42:35in front of return it just means return undefined right that's it that's all it does right so

3:42:42this is one thing and another important thing is any statement after return never executes

3:42:49right so if i try to for example if i try to console log sum here and total count

3:42:57here you will see we have 305 because sum was incremented but if i have let's say total count as

3:43:05total count plus 200 you would see that in the console we still get total count as 5 which was

3:43:13the initial value and the reason for that is because like i said after return no statement

3:43:20gets executed and you can also see our editor pointing us saying that unreachable code detected

3:43:27that means you cannot your program cannot actually reach this part of code ever right it's an

3:43:35impossible condition why because well you always return so you're never going to reach below that

3:43:41so that is something you should keep in mind that whenever you write return

3:43:45you cannot execute anything after that right so that's important so yeah that's pretty much it

3:43:51in terms of return we will take a look at examples of return how they work you can return any single

3:43:57thing any single value in javascript right it's not that you have to return numbers or you

3:44:02have to return strings you can return all these types you can return arrays you can even return

3:44:08functions which is interesting and we will discuss about that probably when we are discussing about

3:44:13closures in javascript but you can do all sorts of fun stuff with javascript when you're doing that

3:44:23hey everyone welcome back and in this video we'll be discussing a very important thing in javascript

3:44:29and in general in programming and those are conditionals and conditionals just means to

3:44:34add if else logic if this is true then that should happen if that is true then some other

3:44:40thing should happen right and as developers all your work would more or less involve

3:44:47building up this logic and setting up this logic in the code so this is super important stuff let's

3:44:52just go ahead and discuss this so let's say i have a function called should should i get a license

3:45:04right and this think function accepts an h and it should return a true or false depending on should

3:45:11i get a license or not a driving license so what i want to do is i want to return

3:45:16true if the age is greater than 18 and false in the other case so what do i do

3:45:24is i make use of a statement called if h is greater than 18 then i say

3:45:31return true else return false and let me just tell you what's happening here so you see how

3:45:39i start an if block is i write a if keyword then a bracket the condition which should be matched and

3:45:46this is a symbol for you know greater than symbol i hope you understand this from your math class

3:45:52if the age whatever i'm passing here is greater than 18 just return true otherwise return false

3:45:59else just means that if this condition does not match then do that right and if i go ahead and now

3:46:06pass in let's say if i start console logging it so let's say i have should i get a license as

3:46:13100 of 800 so we get true here right makes sense if i have the same statement

3:46:21with me but with an age of 17 you would see that the second thing second statement we get is false

3:46:29and see that i'm console logging this function call itself this is just a shortcut of saying

3:46:35that hey i want my result to be stored like this and then console logging result these

3:46:40two statements are same right so i just eliminated one step by taking this value directly and putting

3:46:46it inside console.log so that would work right there's another way we can structure this code

3:46:52a little if you remember from the last video when i said that whenever some function returns a value

3:46:58it will not execute anything below that right so technically speaking we don't need this else thing

3:47:07if i remove this it's still equivalent why because take a look here if the age is greater than 18

3:47:16then we return true and we know once the function returns it will not go below this therefore the

3:47:23program ends if we do not return if we you know if age is less than 18 or less than equal to 18

3:47:30then we'd never enter this if block and this if block essentially ends right so it's technically

3:47:37acting as a else block itself this would not have been else block if i just wrote

3:47:42for example instead of console logging if we just did uh instead of returning if i just did

3:47:49this person is above 18 and let's say if i did this person

3:47:56is below 18 right and if i just had a single statement here single function call rather

3:48:04not even counsel logging it you can see i get both of these statements this person is above 18 and

3:48:10this person is below 18. even though this person is only above 18. so why does this happen because

3:48:15i'm not using return here right so it enters this if block but it never returns and therefore it

3:48:22executes the lower block as well but if i had a return statement here you would see that we

3:48:27only get a single console log which just says this person is above 18 because the moment it happens

3:48:32we just return right and that's it the execution ends or what you could have done is you can just

3:48:40remove this right and else and shift this line right here and it will still have basically

3:48:47the same meaning right you can still see we do not get a duplicate or you know a second console log

3:48:54now you might think what's a good way to go about and in programming generally what you will see is

3:48:59that there are multiple ways to do a single thing so you have to stick to a style you have to stick

3:49:04to a pattern and what i would recommend at the moment at least you can be as much explicit and

3:49:10as much clear as you can when you're using this if else blocks right because you clearly tell the

3:49:16other person who's reading your code another human that what you want this might this is also fine

3:49:22and i use it personally all the time this behavior of early return this is basically what we call as

3:49:28early returning um but yeah i would just say just stick to if else at the moment you will also get

3:49:33a little bit of practice so yeah that's pretty much it for if else introduction in this video

3:49:39hopefully you were able to think about how you can put in some logic using if else but

3:49:50hey everyone welcome back and in this video let's just go ahead and take a look at

3:49:54logical operators in javascript and what do they mean so like i said we have this function

3:50:00called should i get a license right and it just accepts an age at the moment let's just go ahead

3:50:05and extend this and i'm going to say let's say we also have a bright as the second parameter right

3:50:12and what i'm going to do is i'm going to write a condition here which will try to and try

3:50:19to count for both of these factors so we're going to say that if age is greater than 18

3:50:25we will say that well okay this person is above 18 that's fine else you know you can include else or

3:50:32exclude it because you already have the return statement so it does not really matter here

3:50:36else we are not gonna go ahead and do this right away i'm gonna say inside this else block itself

3:50:44you can go ahead and say if bribe is greater than let's say 100 we can say console.log you pass

3:50:55right else we will say this person is below 18. simple as that now if i go ahead and write hundred

3:51:05then obviously it will pass if i go ahead and write 5 and 100 like this

3:51:11you will see that this statement right here uh let's see

3:51:21we get the statement that this person is below 18 because this check fails because private is not

3:51:26greater than 100 it's actually equal to so if i pass in 101 you will see we get the statement you

3:51:32pass right and this is fine but we can rearrange this code a little bit so what i'm going to do is

3:51:40i'm going to rearrange this code and i'm going to write a should i get a license version 2

3:51:46right and in this case i'm going to start with the bribery condition so what i'm going to do

3:51:52is i'm going to say that if my h is less than or equal to 18 and i have a bribe of greater than 100

3:52:04then i'm gonna console log u pass and return what's happening here

3:52:11is that we are using a double ampersand sign right which just says that this condition should be true

3:52:18as well as this condition should be true if both of them are true then i'm going to enter this if

3:52:24lock right otherwise we just say that else if any one of them is false then we enter this else block

3:52:33and we say that hey this person either is greater than 18 or they have a bribe of less than 100

3:52:41so what i can do is i can go ahead and check else if and see i can write if here as well and else

3:52:50if here as well that's also a second syntax so else if age is greater than 18 that means in

3:52:57this case age is greater just greater than 18. so i'm just going to say console.log this person

3:53:03is above 18. and finally i'm going to say else i mean this you can write here that if bribe's less

3:53:11than 100 but from the logic you should understand that this else this if would run if and only if

3:53:19both of them are true right this would run if this condition is true and we for sure

3:53:26know that if this if did not run and this if did not run then this if would run and always run

3:53:35because the bribe might be less than 100 right that's the only that's the only condition

3:53:41that these two ifs would not run right so i'm going to go ahead and just write else if bribe is

3:53:48less than equal to hundred you know i'm just gonna say two less not exactly two less but the original

3:53:55messages we had right this person is below 18. and if i remove this code right here and if i

3:54:02switch this from license to license v2 you can see we still get you pass and for 100 you will

3:54:10see that we get this person is below 18 and for basically a hundred hundred we just get

3:54:16this person is above 18 right so you can see that these two functions are technically the same

3:54:24but you might find one more readable than the other well it's it could be the first one it

3:54:30could be the second one it's your choice but that's that's what i'm saying whatever feels

3:54:35more readable to you are logical to you you should probably use that this one is a little bit flatter

3:54:41in structure that means if i just even remove this you can see there's a single if else if else

3:54:47if chain right here this is a little bit nested but might be a little easier on the eyes right

3:54:52it depends on you but what i wanted to focus on in this video was this double amp sand thing which

3:54:59just means that this condition and this condition both should be true right so let's say i have

3:55:09i'm aged 50 and i give a thousand dollars as the bribe i still get into this block right why

3:55:17because my age is not less than 18. so what we can do is we can write this

3:55:24um let's say if i have this as the first condition or i write the bribe is greater than 500

3:55:35so what does this mean this means if you think about this i want you to stick with me here if

3:55:41this gets confusing just stick with me here and see what's happening we have the first condition

3:55:47age less than equal to 18 which is not gonna pass right so the moment javascript sees that

3:55:52this is gonna fail it just evaluates this whole expression as false right

3:56:01now the next thing javascript sees that it says okay i don't have just this expression i have this

3:56:08this another expression with me which has these two bars and these two bars are logical or so

3:56:14it means if false or bribe is greater than 500 and in this case we are passing thousand here so

3:56:21this is in fact true so we evaluate this part as true so what we say if false are true and

3:56:29false or true just means that it just needs at least a single value as true right so we are we

3:56:35end up with true and we just get you pass right so this is the breakdown of what's happening here

3:56:40that's it that's why you get pass here so if you are passing like 300 you will see we get

3:56:47this block because again just to quickly run you through this is false right this is false

3:56:54false and and anything is false because and requires every single argument to be true

3:57:00so this becomes false and bribe is greater than 500 that's not true because it's 300

3:57:07so 300 is not greater than 500 so this also becomes false and finally we end up with this

3:57:14so we don't run this if block we go to the next elsif block where we say if age is greater than

3:57:2018 which is in fact the case therefore we run this block and that's what you see right so yep that is

3:57:29how logical and and logical or works in javascript and there's another boolean operator which is

3:57:40like um you know white listed for example i have a white listed variable and i can say

3:57:48that if the person is not whitelisted this not operator then i'm just going to say console.log

3:57:55you are banned right and just return from here so what does this mean you can see we already got

3:58:03you are banned and if you can guess why that will be awesome we got this console log because if we

3:58:10just log this value as well you will see because i'm not passing anything i'm getting undefined

3:58:15as the value so if i pass this as true you know what this means this means that the person is

3:58:22in fact white listed therefore not of true is false right not of a boolean is the other boolean

3:58:31so if it's true then it's this expression is false if it was false then this expression was true so

3:58:37because this was true we end up with this right and this expression becomes false therefore we do

3:58:43not enter this block right so we move ahead and we get our regular output but that was not the case

3:58:50if i pass in false you would see that we get you are banned just like that

3:58:55and that's it now what you have to understand in javascript when you're dealing with this not the

3:59:01logical the the snot operator javascript considers true and false as the values which is fine but it

3:59:10also considers pretty much every other thing as a value as well so you can technically speaking pass

3:59:17in a string here and this will work now the reason it will work is that javascript is a dynamic typed

3:59:27language that means javascript tries to understand what is the type of the variable at runtime

3:59:35right it does not make efforts for you to just you know make sure you're using the right values and

3:59:41the right types of uh values basically where they are required so if you're using a string

3:59:46here javascript would try its best to convert the string into a boolean whatever rules are assigned

3:59:54inside javascript's engine according to them and then try to evaluate this so i'm just going

3:59:59to give you a cheat sheet here telling you a few things which you have to remember that is

4:00:05if you pass in 0 here this would be a falsie value right and let's just change this to

4:00:13right listed so you can see if i pass in 0 we get you are banned because 0 is a false value

4:00:18a false value is a value which will evaluate to false if casted into a boolean right which is what

4:00:25happens here so 0 is a false value undefined is a false value like you would have seen

4:00:31when we did not pass any argument null is a false value false is a false value right and there are

4:00:39a bunch of a couple of more right so you will discover them but for the most part always try

4:00:46to stick with booleans whenever they are used like booleans right you can use a string here but it

4:00:55wouldn't make sense and javascript wouldn't tell you that it's what's right or what's wrong so yeah

4:01:01that's pretty much it on your first introduction to some logical operators and how to use the not

4:01:05operators with conditions in a function and i think this is you have made a lot of progress so

4:01:11if you understand this that's awesome if you don't then don't worry try to rewatch some of

4:01:15the content practice all these labs and i'm pretty sure you will get the hang of this

4:01:25hey everyone welcome back and in this video we're gonna be taking a look at arrays in

4:01:29javascript how to work with them a little bit although we will see how we can work with

4:01:35the arrays in our different section but this is like a just a quick start for you

4:01:40so i'm gonna go ahead and remove these two functions and i'm gonna create

4:01:43a new function called add my friends right i'm gonna have an array here let's say my friends

4:01:53is equal to this array and what i'm gonna do is whenever i call this function add my friends

4:02:01this will accept a friend as the argument and i want to add this friend to this array right

4:02:09so what i can do is i can say my friends dot push my friend now what's happening here let's take a

4:02:17look at the console as well so that we have idea what's going on so what i'm gonna do is first of

4:02:25all write my name right away right so you can see the moment i do that i get the console log

4:02:31as mehul inside these square brackets so what this means is that i have just added one element to

4:02:38this my friends if i call this function again someone for example you will see i have mahul

4:02:45and someone in this array right and a couple of things which i mentioned about arrays is that they

4:02:51are ordered that means this order matters what is first what is second what is third and so on

4:02:58this order matters this push function right here helps you to push values to the end of the array

4:03:07right if you want to push a value to the start of the array you use a function called unshift

4:03:14so these are a couple of handy functions which you should know and you can clearly see

4:03:19that the order got reversed from the last one right because earlier you saw that mayhew was

4:03:25first element then someone was second because they were getting pushed at the end now if i go ahead

4:03:30and add the third friend you will see that this person gets added to the front of the array so

4:03:36unshift adds the element at the top which is like at the front and push adds the element at the end

4:03:44so this is one important thing about arrays second important thing about them thing about them is

4:03:51that they start with a zero index that means and we have briefly discussed this my friends

4:03:57of zero would be three in this case because we are unshifting this right so this is zero this is one

4:04:05and this is two right so if you do a zero one two cycle you will see that you get these different

4:04:11different elements together super important stuff another thing is that you can always get the size

4:04:17of this array how many elements there are in in this array by writing a dot length with this

4:04:24and this comes out to be three and this three is not this three just let's just change this

4:04:29so that it makes more sense you will see we still have this three this three is the length of this

4:04:35array right how many elements are there so we added only three elements but if i had some

4:04:40default friends here you would see our length was actually four why because we already added one we

4:04:48already had one and we added three more and when we console logged our friend's length we had four

4:04:55so this is how you work with arrays in general now let's say i have a function or you know i i

4:05:05wanted to remove this last value from this array so what i can do is if you can think about it

4:05:11one way is i can just go ahead and i can say my friends of uh you know 0 1 2 3 is undefined right

4:05:22that's something i believe is fair enough to think about and if i console log my friends you will see

4:05:29that now we have we still have four elements but the last one has got undefined so how do

4:05:35i really remove this element right here well we can use something known as my friends dot pop as

4:05:43the method and this is a function right this is a function so when you call this what's gonna happen

4:05:50is that it's just gonna give you the end value the last value which you pushed and it's

4:05:57just gonna remove that right from the original area array as well so if i console log this as

4:06:04final array and console log the my friends you will see that our final array does not contain

4:06:12this default value right this is removed and i also said that it gives you pop actually gives

4:06:18you the last value so i can just say last value is this because this returns you if you remember from

4:06:25the last return video it returns you that value so last value if you console log this you will see

4:06:33is in fact the default right so what it did is that it took the last value

4:06:39assigned if you want to assign it to a variable it's fine if you don't want it's fine as well

4:06:44and then it also removes it from the primary array which you have

4:06:48right so if i do a couple of more pops for example if i write this two times instead of once

4:06:56and move this you will see my final array is just two elements if i do it three times you will see

4:07:03it's just one element if i do it four times i lose all the elements and if i do it five times

4:07:08well it does not matter after your element is your array is empty this function would

4:07:14just return you undefined right you guessed it right because there is nothing to be returned

4:07:19so it returns you undefined and it removes nothing so you will always just keep on getting this empty

4:07:24array if you write a lot of these statements so that's how in general how you work with arrays

4:07:30in terms of pushing popping and inserting elements one final thing which we can take

4:07:36a look at is we can also insert or you know modify values based on the index so like i said

4:07:44you can access the first value like this where you have someone like this you can also modify this

4:07:52so if you say something like like i said i had a typo here so if i say something like

4:07:57someone and then i console log my array you can see that my typo was updated from the last copy

4:08:05right so you can change the values which are stored in an array

4:08:09if you know the index of the value which you want to change index is basically everything in

4:08:14an array if you know the index you can pretty much do anything with that particular element

4:08:23hey everyone welcome back and in this video i'm gonna be introducing you to loops in javascript

4:08:29one of the most important things again in a programming language and what loops allow

4:08:33you to do is it allows you to run a bunch of statements over and over again so you might

4:08:40think that's what functions did right we can just call a function again and again which is fine but

4:08:46you still have to write functions certain number of times right you are writing this

4:08:51once then you're writing this twice what if i wanted to insert 100 of such friends then

4:08:56you would need to write 100 search calls so sure i mean you can create a function call of 20 and then

4:09:02call it five times and so on but that's that's not what i'm talking about i'm talking about

4:09:07actually repeating a piece of code a set number of times or even infinite or even arbitrary

4:09:13if you want so how do we do that we do that with loops so what a loop is there are kinds of loops

4:09:21but we'll be taking a look at for loop in this video so i'm going to start with writing for

4:09:27as the keyword and there's a set syntax you have to follow here so i'm just going to show

4:09:32you that once so i'm going to say for let i is equal to 0 i is less than 10 i plus plus right

4:09:39and i'm just going to console.log i here real quick so let's take a look at what's happening

4:09:47well you see first things first is that we in the console we get 0 to 9 as the values printed

4:09:54right we never wrote 0 to 9 anywhere in the code but it got printed so that's our first observation

4:10:01our second observation is this line number 8 right here what the hell is happening here so

4:10:06you can see that we have the first block as the initializer this is the place where we initialize

4:10:14a variable which will control the loop right this case it's i i is a convention you can name this

4:10:22anything you want then we write a semicolon very important very important syntax this could not be

4:10:29left out or missed in the second part we have a condition this condition basically says until how

4:10:38long this loop should run right so we start at 0 and we have to run the loop as long as i

4:10:45is less than 10. that's fair and what do we want to do as long as you know this loop is running

4:10:54on every single iteration that is every single time we complete everything inside this uh

4:11:00loop body we want to run this part so whenever you complete it you run it whenever you complete it

4:11:07you run it and the fact that you can see that we start at zero this means that

4:11:12the very first time this loop runs the very first time then only this runs and this runs

4:11:19this statement always runs after an iteration has completed right so that's why we get 0 first then

4:11:27we check hey if i is less than 10 nope it's not um so we get into this console log and just puts

4:11:35out zero in the next part we increment this so i becomes one we check if i is less than 10 nope

4:11:43still not because i is one so we put out one again we increment i becomes two we check if i is less

4:11:51than two nope it's not so we put out two all the way this happens till eight so we are at eight we

4:11:57just console log eight we go back we make it 9 we say is 9 less than 10 yep it is so we put out 9.

4:12:06we go back we make i 10 we say is i less than 10 nope i is not less than 10 because 10 is not

4:12:15less than 10 10 is equal to itself but it's not less than itself so that's where we know the loop

4:12:21should stop and the loop stops that's it so this basically gives you 10 iterations which is 0 to 9

4:12:28which are 10 in count right and you can do pretty much anything you want you can multiply this i

4:12:35with 2 this is just a number right which just gets populated you can multiply this or you can

4:12:40raise this to a power of 2 whatever you want to do i mean you can pretty much have a lot of fun

4:12:45with the numbers part here but what you can also do is probably like do a my friends.push

4:12:53as i right so you're just pushing 10 numbers into an array and you can say my friends like this

4:13:03so you can see we have a default and then we have a zero to nine numbers available in this

4:13:07array which is like a quick way of initializing an array with some set values but yeah that's

4:13:14how you can do it and yeah that's pretty much it for your introduction part to loops you can pretty

4:13:20much control all of these variables if you want you can make this 20 right and we have already

4:13:26discussed i plus plus this could very well be i is equal to i plus 1 as well that's completely fine

4:13:34right nobody's judging you or anything and it'll just work fine but in loops what we usually do is

4:13:40we use these plus plus or minus minus incrementers right and like i said you could also do plus plus

4:13:47i and it would not make a lot of difference it's one on the same thing for the loop at least right

4:13:57hey everyone welcome back and in this video let's just quickly discuss about continue and break two

4:14:03important statements in loops which you should know and how to work with them so if we take a

4:14:10look you would see that we run all the way from 0 to 20 in this case let's say i only

4:14:14want to push even numbers to this array right let's say this is just even numbers and if i

4:14:21remove this function as well now what i want to do is i just want to make sure that we have

4:14:290 2 4 8 6 10 12 these numbers right here so how do i do that well the first way to do that is

4:14:37you actually change this condition so instead of incrementing it every single time you increment it

4:14:44twice right every single time just once you increment it twice which gives you pretty much

4:14:49the same result which we which i just said right that you need to get even numbers so that way you

4:14:56are reducing your iteration count as well as the numbers you are pushing and that probably is the

4:15:02best solution right another solution is that you can go ahead and say here that if i modulo 2 is 0

4:15:12and i think we haven't discussed the triple equal to or double equal to yet so stick with me here

4:15:18we will discuss that later but this just means that we are saying that hey if you divide i with 2

4:15:25do you get the remainder as zero if you do then we know that it's an even number because even numbers

4:15:30when divided by 2 gives us 0 remainder otherwise we know this is an odd number so i can say

4:15:36let even numbers let odd numbers odd numbers i can say odd number start push

4:15:44i right and if i console log them in both in order you will see we get even an odd number separated

4:15:52so that is how that is another way you can do that that's fine but a third way to do this

4:16:00is you just skip an iteration right which is pretty much what we are doing here if i do

4:16:06something like this this is pretty much what i'm doing right but let's say i have a function here

4:16:13which says skip number and i have a number like this and whenever i pass

4:16:21a number for example let's say i have this even numbers inside this array and i remove this

4:16:30and i just return even numbers right fair enough simple program and we know all the parts here

4:16:37let's say i have a skip number of 10. now what i want to happen is that whenever

4:16:4310 arises here i don't want to push it right i don't want to do anything so sure you can do

4:16:50something like if i mod 2 is equal to 0 and i is not equal to number then push it which is again

4:16:59magically it works right and again this means that i is not equal to the value here this means

4:17:06that this result is in fact equal to the value here right just making sure you know about the

4:17:11triple equal to and not and then double equal to symbols here these are important stuff right

4:17:17so make sure you understand them as well along the way but what i wanted to discuss is a little

4:17:23bit of alternative let's say i don't want to push this in a condition i always want to add this and

4:17:29now we have a problem because now we get all the numbers however what i can do is make use of a

4:17:37couple of handy statements in the loops and that is the first the first one is called as continue

4:17:44so what continue does is that it says that i can say if i mod 2 is equal to 1 then i want

4:17:51to continue so remember just like return just does an early return from the function itself

4:17:58for example if i just wrote return hello from here you wouldn't see all of this stuff happening and

4:18:05we will only get hello in the console similarly anytime you are inside a loop and the loop body

4:18:12contains a continue or the you know when the code is executing it encounters a continue

4:18:18the iteration is marked as done right so it's kind of like a i won't say a return because it keeps

4:18:26the loop running but it kind of like skips the current iteration and whatever has been done it's

4:18:31done okay that's fine but it moves to the next one right so if i just keep on writing continue here

4:18:38you would see we actually get in blank array right because nothing happens in this loop

4:18:42for all the 20 cycles we just waste them so instead of that what we do is that we say that

4:18:48for every single odd number we want to just skip the cycle if i switch this to zero you

4:18:54will see we only get odd numbers because for every single even number we skip the cycle

4:18:59right similarly what i can do is i can say if um i is equal to the number again i want to continue

4:19:10because i don't want to add that number and if both of these conditions don't match

4:19:15then well the code will come here it will execute and it will add those numbers so right here you

4:19:20can see we get 0 2 4 8 6 12 whatever that is not added if i supply 2 here you would see we have a 2

4:19:27missing now and so on so that's how continue works let's say we have a number which is break number

4:19:37now what i want to do is i want to break out of the loop if i get that number if i don't get

4:19:46that number then it's fine so so far you can see let's say if i have a i mod 2 condition with me

4:19:55that's fine but what i want to happen is that the moment i get this number which is passed here

4:20:02it should break out of the loop right so how do i do that well for that i can write if number or

4:20:12you know rather if i is equal to number then break now pay close attention to what's happening here

4:20:19you're seeing that i passed in 10 and the results which you get is 0 2 4 6 8 because the moment

4:20:27this i became 10 and this number got 10 this number was also 10

4:20:32then we ran the statement and it breaked out of this loop that means it came to the next line

4:20:38and it just said return even numbers so that's why we get all the previous work which has been

4:20:44done by this if i write for example 2 here we will just get 0 why because the moment i becomes 2 we

4:20:53just breaks out of the loop right that's that's what we do now there's a very slight difference

4:21:00between break in a loop and redone in a loop which is in a function because if you think about this

4:21:08think about this carefully i told you how return works right whenever you write a return nothing

4:21:14works under that so that's kind of true but in a more logical way what i should say is that the

4:21:21moment your function executes return nothing else runs right nothing else runs everything else stops

4:21:27so if i return here instead of breaking what would happen is that we will get undefined why

4:21:34because we are not returning any single value so let's say if i return and say early return

4:21:42so or even better like instead of early return i just say even numbers

4:21:47so what's the difference between doing this between doing this and just writing break here

4:21:53the difference is that if there is anything which is in between these two loops which might be some

4:22:00important work like you know just console logging that final numbers length is even numbers.length

4:22:10right if we have the statement then the statement would never run because you just returned out of

4:22:16the loop right and you did not just return out of the loop you also returned out of function

4:22:20so that statement never runs if you want it to run you just want to break out of the loop you

4:22:27don't want to return out of the whole function so the moment you change that you will see that

4:22:31we also start getting the final numbers length is 1 and so on so this is a kind of introduction

4:22:38for break return and continue in a loop which is running inside of function

4:22:45return can only be used with functions break and continue can only be used inside loops right if

4:22:53you just write break here it wouldn't make sense and you will get another message if you write

4:22:58continue here it wouldn't make sense break and continue only make sense for these loops right

4:23:04so yeah that's pretty much it for the language syntax hopefully you're able to understand how

4:23:08the language and how the dynamics are working out if you do then make sure you're leaving the

4:23:13rating to the course recommending these two other people in your family in your

4:23:17circle and your peers whoever wants to learn javascript that really helps the platform

4:23:26hey everyone welcome back and in this video let's just go ahead and discuss about equality

4:23:31in javascript and how that works so what i'm going to do is first of all make some space here

4:23:36and i'm going to start with just a console.log statement we're going to keep this simple

4:23:40so i'm going to say starting with 1 is equal to 1 right and you can see it console logs true

4:23:48so whenever you are checking for equality like this this expression in itself would

4:23:54give you a boolean value what do i mean by that for example if i have a result

4:23:591 equal to 1 and if i do a type of result you will see that i get a boolean right so this can even be

4:24:05either be true or be false and in this case we know it's true because well one is in fact one

4:24:12you would have seen that i'm using three equal to signs here and i'm using one equal to sign here

4:24:17so what's the difference between these three and one so what you have to remember is in javascript

4:24:23whenever you use a single equal to sign that means assignment that means you are assigning

4:24:30a value in this case you are assigning result to one right if you are using double equal to

4:24:36or triple equal to in javascript you are comparing a value to something else right this is important

4:24:44because javascript also comes with a double equal to variant and double equal to variant is a little

4:24:50less strict i mean this still evaluates to true but if my one was a string then also it will

4:24:57evaluate to true right and depending on how you are looking at this it might or might not make

4:25:02sense but if you use a triple equal to it will not try to type cast things right javascript will not

4:25:10try to typecast things and it will give you false why because string and number are inherently not

4:25:16the same thing however if both of them are strings that's a different story right but yeah in general

4:25:24in general always make use of triple equal to until and unless you know what you're

4:25:29doing that's the best practice you will find thousands of code pieces and a lot of things

4:25:35with a double equal to sign and double equal to usage that is fine but whenever you're writing

4:25:40new code always use triple equal to don't ever use double equal to that's just i mean that's

4:25:46just not a good way or good practice to go about plus you will have a bunch of buggy code

4:25:51if you're not careful with the types like i said if you're comparing strings and numbers and you

4:25:56know doing bad comparisons all the time javascript has a history of not reporting those errors to you

4:26:02in fact javascript just tries to use its own little brain which it has and sometimes it

4:26:08results in horrible disasters so you don't want to do that try to stick with triple equal to

4:26:13which will just reject your results if they are not type equivalent or value equivalent

4:26:20and yeah that's pretty much it that's all i wanted to discuss i mean you can compare

4:26:26all sorts of values fg fdg you know anything you like right i'll just work out of the box

4:26:39hey everyone welcome back and in this video let's just go ahead and start with

4:26:43objects in javascript so so far we have seen the primitive data types and used functions as well

4:26:49but objects are super interesting super important because objects is everything in javascript your

4:26:57function can be an object your arrays are object and objects are object so very simply speaking an

4:27:04object can be created as follows so you can say my object like this and just create an empty uh

4:27:11you know this curly braces right now the objects in javascript are stored in the following way

4:27:20you have certain keys and then a column and then certain values so you have a key name

4:27:25and then a value right and you can put this key name in quotes again right here does not matter

4:27:32whether it's single code or double quote so the moment you do that what's going to happen is that

4:27:38this is an object which has a key called keyname and a value called value you can define multiple

4:27:43values and multiple keys here so i can say keyname2 for example and then a value 2.

4:27:49so now if i try to console.log this object right here you will see that we get the full object key

4:27:55name as value and key name too as value 2 right simple as that now how you can access the value an

4:28:03object and what does it even mean what do you have to remember in objects is that the way you

4:28:10access a particular value is through its key so the premise is how you store the object

4:28:18is that you store it in such a way that you know the key more or less or you can derive it and you

4:28:23don't probably know the value or you know you want to store it against the value so what i can do

4:28:29in order to access this value right here is i can use the square bracket notation just like we used

4:28:34with the arrays with number 0 1 2 but instead of writing 0 1 2 i will write key name like this

4:28:43and when i do that you will see that i get value in the console which is the value of this and this

4:28:49could be pretty much anything right it could be a string it could be a number it could be a function

4:28:56it could also be a function right it could be a function like this which is anonymous function

4:29:04it could very well be another object itself right so you can have another object so if you want to

4:29:11go into you know this object for example key name let's say 2.1 and you say hello world then if i

4:29:20go ahead and copy this and use the square rocket notation again in a nested fashion you can see

4:29:26this gives me this object and then keyname 2.1 gives me hello world right so that's how this

4:29:34works the object uh you know extracting the key out of extracting the value out of all these keys

4:29:44there is another way you can make it work and that is first things first you don't need to have codes

4:29:50around the key name if it does not contain spaces or any weird characters or does not start with

4:29:57any weird characters so what do i mean by that if you have a key name like this keynum 2.1 you have

4:30:03to you use the quotes in this case right because this is now just bad syntax but if you don't have

4:30:10any spaces or anything you can pretty much use and set the key without quotes in javascript right so

4:30:17similarly for this this is also valid syntax now similar alternative exists for us here so you have

4:30:26an array like notation here which is fine if you want to access but if your key name is valid that

4:30:33means it does not contain a this does not contain weird characters or does not contain spaces

4:30:38what you can do is you can use something known as a dot notation so you can just write a dot and the

4:30:44name of the key which you want to access right in the second case we have to use the square notation

4:30:51because if i try to use the dot notation you will see it does not make a lot of sense because this

4:30:55way it does not know there's a space it does not know where it ends right so in this case we have

4:31:01to use a square notation and this should obviously be in quotes because otherwise it will be

4:31:07evaluated as a variable right and you don't need a dot then so yep that is pretty much how objects

4:31:14work in javascript you can define nested objects you can do basically any sort of and all sorts of

4:31:21nesting here these values could be null these values could be functions these values could

4:31:26be undefined these value could be nested objects strings booleans everything you can think about

4:31:32right and you can look them up with the help of their key names and that's how this works

4:31:38so hopefully this was a good introduction for you um for getting started with objects and there's a

4:31:44there's a lot of use of objects in javascript we will be working with them all the time

4:31:54hey everyone welcome back and in this video i want to discuss a very important thing

4:31:58a very important concept in javascript and that is known as how the objects are passed

4:32:04in a function and in general here and there so what i'm going to do is i'm going to create a

4:32:09function called mutate which basically mutate just means to change something and i'm going

4:32:14to have an object being accepted here right and let's just go ahead and create an object like uh

4:32:21let's name it something else my profile for example so i can say this is named as mehul

4:32:28and h as 22 right and in this object whatever object i pass for example i have a second profile

4:32:37let's say second profile where the name is john and ages 42 right so now if i go ahead and say

4:32:47object dot h just console logging that what you will see is that when i do something like mutate

4:32:59my profile we get 22 in the console if i do mutate of second profile we'll get 42 in the console fair

4:33:07enough now before doing any sort of work in this what i will do is i will do a primitive mutate and

4:33:16i will have a primitive value here right and what i'm gonna do is i'm just gonna add one to it so

4:33:23i'm gonna say primitive plus plus right and what this primitive mutate does is that it'll accept

4:33:31a number so let's say i have 100 here and i do a primitive mutate of number right and if i console

4:33:38log this primitive what we see in the console is one zero one which is you know understandable

4:33:46you want increment hundred you get one zero one but if i console log the number here back

4:33:53you will see that this number is not changed right it is 100 although it was made 101

4:34:00inside this function but this function actually has this primitive variable in scope plus

4:34:08this call when this call was made this number got copied into this function's execution context

4:34:14right so this means this primitive is a copy of this number it's not this number which we are

4:34:22incrementing here with objects however this is different because with objects if i try to do

4:34:28the similar thing object.h plus what's going to happen is that you will see that if i console.log

4:34:36second profile here we will see that the age in fact gets increased by 1.

4:34:43so it was 42 before i passed it inside this mutate function i just incremented the age object.h

4:34:50the age property of this object and i console logged it and you can see it suddenly turned 43

4:34:59right but if we go by this logic it should not have modified the original variable

4:35:04but that is not how objects work in javascript the way objects work in javascript is by reference so

4:35:10when you create this object you can think of when you're passing this in a function you can think of

4:35:16an address being passed so instead of the actual object let's say you have passed an

4:35:22address something like 0x1234565 for example right this could be anything now whenever javascript is

4:35:30trying to access the property of this object it will try to go to that location in the memory

4:35:36and search for that property and then increment it now the reason this increments the older object as

4:35:43well the outside object is because both of them are pointing to the same object in the memory

4:35:49right you just pass the address here whereas when you're using a primitive you actually

4:35:55copy the value so if this is a number if this is a string if this is a boolean if this is

4:36:01any primitive type bigint it gets copied so the original value isn't mutated but

4:36:06in case of objects the address gets passed or the reference gets passed and that is basically where

4:36:14the change takes place so this is very very very important behavior of javascript which

4:36:21might catch you a little off guard if you don't know about this so this is

4:36:24super important to know but yeah that's pretty much it for this video hopefully you were able

4:36:29to understand that whenever you pass an object you are always dealing with a live copy of that object

4:36:36and whenever you pass a primitive you are actually dealing with a fake copy of that object right

4:36:48hey everyone welcome back and in this video let's just go ahead and discuss about

4:36:52scoping in javascript which is again a very important concept so what scoping is well you see

4:36:59that when you're trying to work with javascript a lot of times you would see that you have to create

4:37:07this opening and closing curly brace now a general rule of thumb in javascript is that whenever you

4:37:14see these opening and closing curly brace that means that this is a scope and what is a scope

4:37:21a scope is an area in which a variable's lifetime is right so if you create a variable for example

4:37:29hello and assign it a world you can do whatever you want with this variable here right you can

4:37:37console log it you can um you know if this is a lid you might also be able to change it and so on

4:37:45right so if i run this function this works fine we will get world in the console but

4:37:51if i do console.log hello outside this you would see we get an error that hello is not defined

4:37:58why because the scope of this variable is bound inside this opening and closing curly brace

4:38:06right if i take out this line out of the function you can see that we get two console logs the first

4:38:13one from the function call and the second one here right so why that is why this is working now

4:38:20because in javascript what you have to realize the scope of this variable is actually the scope which

4:38:28it is in that is in this case it's globally plus any other scope which is defined as a child of

4:38:35that scope right and all the scopes are basically children of the global scope so that works fine

4:38:42what do i mean by that let's just take a look at another example let's just say i had hello inside

4:38:48this function now what i can do is i can go ahead and say that if something is true then console.log

4:38:59hello now if we take a look here this statement will always run because this is well if true will

4:39:05always be true but what's happening here is that i can access this hello variable inside this scope

4:39:13see we have a opening curly brace and a closing curly brace therefore this is also a new scope

4:39:18but this is a child scope of this function because it's inside this it's embedded inside

4:39:24this therefore i can access all the variables defined above just just as usual right you see it

4:39:31works however if i move this inside this you would see that this statement right here the second one

4:39:39starts giving us error why because now this hello variable is in the scope of the variable or not

4:39:46exactly variable but in scope of the statement of this if right so you cannot access this outside

4:39:52the if block so you have to remember like function creates a scope this if else also creates a scope

4:39:58anywhere where there's a opening and closing curly brace and loops also create a scope what do i mean

4:40:04by that let's write a simple loop i zero i less than 10 i plus plus i'm going to console.log i so

4:40:12what you can see here is that we get let me just remove this what you can see here is that you get

4:40:19one two zero two nine and the console log but if a console.log outside this loop you would see it

4:40:26gives us an error right and although it seems it might seem like this is just outside loop and not

4:40:32inside these parentheses but the loop variable is also tied to the scope of the loop so you can

4:40:39access this eye you can do pretty much anything you want with this eye inside this loop but this

4:40:44i would not be available outside the loop why because its scope is not defined outside the loop

4:40:51if you could have defined i here for example and if you remove this declaration you can

4:40:57leave this space as empty it's it's totally fine right and if you do something like this

4:41:02now you can see that when i console log this i get i as 10 the last value

4:41:08why because our scope wasn't expired in this for loop we can access it right

4:41:16so this is one way of creating a scope if else block is another way like i showed you

4:41:21and functions is also a way if you want every single variable to be accessible everywhere

4:41:27you can just go ahead and create all the variables at the top so any variable you create in the

4:41:32global scope can be accessed in the functions right until and unless they are shadowed which

4:41:38we will discuss in the next video so yeah that's pretty much it for this one i hope you understood

4:41:43what the scopes are how the scope work and it's basically the same thing for constantly both so

4:41:49it's fine i mean i just showed you the example of lit i guess but works the same for the const

4:42:00hey everyone welcome back and in this video let's just take a look at variable shadowing

4:42:05in javascript and what that means so what i'm going to do is i'm going to go ahead and actually

4:42:10just clean this up and i'm going to say cons to my variable or you know let's say my age has 22 right

4:42:18and i'm going to create a function um print my age right and i'm gonna console.log my h and whenever

4:42:28i call this you see we get 22 in the console which is fair enough that's what we would expect right

4:42:36but what happens if i try to create my age as 25 here well you would see that we get no error

4:42:45because you know we can see in the console we get 25. so why do we get an error when we do

4:42:52happen to create a variable in the same scope but no error when it's in a different scope

4:42:57or in a nested scope rather well there's no why to that that's that's just the rule that

4:43:02you can create any sort of variable in a nested scope but the problem here is that now there is

4:43:10virtually no way to access the older variable the older value i mean you cannot access my age

4:43:18as 22 because it has been shadowed by a local variable and why the way it works is as follows

4:43:27if you don't have a local variable that is a variable in the local scope javascript will go

4:43:34to one scope above and it'll ask do you have that it will say yes and it just prints that

4:43:40this can be shown in an even better way if i wrap this whole thing in if true

4:43:45so if i wrap this like this and give this an indentation what you will see is we still get 22

4:43:52and if i move this a little bit up and define my age as 27 you would see that we get 27 now right

4:44:01because it takes a look here it says that hey i did not find it do you have it it says yes i do

4:44:07therefore we print 27. if i remove this you would see we print 22 because this also does not have it

4:44:14so it asks above and that got that so it prints 22. now the only thing which we need here to

4:44:23shadow this variable is just a declaration right not even an initialization if i just have a lit of

4:44:30my h what you will see is that we print undefined right i did not initialize this that's it you just

4:44:36need to define it somehow the moment you define it it gets shadowed right so the above variable

4:44:43are not used or cannot be used so this is important in order to you know just make

4:44:49sure you understand that you don't shadow over variables which are required because

4:44:54then there's no way to access that global kind of variable right so that's how shadowing works

4:45:00in javascript variable shadowing nothing fancy but you should just know about how this works

4:45:10hey everyone welcome back and in this video let's just go ahead and start with the most important

4:45:16thing in the browser javascript that is document object model and what document object model is is

4:45:23that it connects your html to the javascript world so so far what we have done and what we have seen

4:45:30is that you can use javascript to do calculations to call you know to calculate prime numbers to do

4:45:36all sorts of mathematical and computing stuff but that is not what we learned javascript for

4:45:41right we are learning this because we want to make sure we use this in web development and we

4:45:46have already seen that html and css are the rock stars of web development whatever you write here

4:45:53the browser processes them parses them and shows them on the right now the big question is that how

4:46:01do you let javascript control this html world and the and the simple answer is that javascript

4:46:09by itself does not ship with any way to interact with an html document so how does it work

4:46:17well you see that your browser in this case chrome actually exposes another set of

4:46:24api to your javascript world in order to interact with this html simply put i'm just saying that

4:46:33there is a special object here which exists which allows you to tap into the html world and

4:46:40that object is not coded in the javascript world itself it's coded in the c plus plus and c world

4:46:46of the javascript engine which is a relatively lower level language compared to javascript

4:46:52right so what is that object that object is called document and we will we will take a look at this

4:46:59document object a lot we will use this a lot of times so if you console.log this document object

4:47:06you will probably be seeing something like this mess but instead of seeing this mess what you

4:47:12can do is open this in a new tab and go to the console of this tab right here and you will

4:47:18see if you ignore this error you will see this as the document console now this looks awfully

4:47:25familiar with what you would see in the elements tab right so this basically means that there's

4:47:31a variable in javascript called document which pretty much is this representation of some kind

4:47:39but not exactly because let me just quickly go over through what is the difference between this

4:47:44representation and the html you are writing so what happens is when you load a page

4:47:51your browser sends your server sends this code to the browser right this is just plain html code now

4:48:00your browser first of all needs to report to two people here the first person is javascript and the

4:48:06second person is css right css needs to style the page javascript needs to add interactivity

4:48:14but before both of them can do their work the browser has to create a certain

4:48:22tree like structure from this text documentary presentation so that

4:48:28the css or the javascript can navigate that tree and reach to the exact node they want to work with

4:48:36right because this makes sense if your css code has to be performed if it wants to be you

4:48:42know fast it needs a good way to reach to the correct elements fastly right you cannot just

4:48:49you know brute force or hack your way into this so what javascript does is that it creates

4:48:56a tree like representation of html document which you sent it and calls it document object

4:49:03model that is what dom stands for document object model is a programmatic representation

4:49:09of the html document which is sent by the browser and basically it is the real view

4:49:17of what you are seeing on the screen as well so if you remove an element from dom it is gone from

4:49:22the screen if you add an element to the dom it appears in the screen the synchronization of

4:49:27the dom and the screen is done by the browser right you have no control over that you cannot

4:49:33change that behavior but you can control dom which indirectly controls what appears on the screen

4:49:39right that's it that's the thing that's that's all javascript does it can manipulate the dom

4:49:45which in results can lead to good or bad user experiences depending on how you do that

4:49:51so that is all that is what dom is and we will discuss a little bit more about dom and all the

4:49:57stuff in the advanced course but yeah we will discuss a bunch of apis in the next few videos

4:50:08hey everyone welcome back and in this video let's just go ahead and take a look at how we

4:50:14can actually get hold of an element on the page now in the last video i told you what document is

4:50:21it's basically a way for us to tap into this html code which is represented as dom in the browser

4:50:29so we have this document with us now this is an object right that means it comes with certain

4:50:35properties which could be functions which could be just regular properties and so on

4:50:41and the implementation of all of those properties are defined in the c plus code

4:50:45not in the javascript world so you cannot pretty much recreate them yourself you have to use them

4:50:50so what i'm going to do is i'm going to say document dot query selector

4:50:56and then i'm going to write h1 right which is the name of the tag we have here now if i do a const

4:51:02of heading right here and if i just console log this guy what you will see is that i get hello

4:51:10world in the console with an h1 so what does that mean that means we are targeting this element this

4:51:17heading right here is actually holding a reference a reference not a copy a reference to this

4:51:25what do i mean by that that means anything i do with this heading now will automatically get

4:51:29reflected on the browser so let's try a couple of properties i know that there's a property

4:51:35called heading dot inner text and i can set it to whatever i like so let's say i said it to hello

4:51:43mayhal instead of hello world you can see that's what appears on the screen immediately right so

4:51:51yep that is how you select an element with a document.queryselector and that is how you update

4:51:57any of the property of that element right and it automatically gets reflected on the screen now a

4:52:02quick point here about query selector this thing right here what goes in here is basically the same

4:52:10thing which you write in your css style sheet and i have a couple of styles from previous videos but

4:52:16what you have to remember is that whatever you write here actually goes as the same thing what

4:52:23you write in a css selector right so if i had for example this as h1 id hello then i could write

4:52:32this as hello as well for selecting id right and it will still work if this was class

4:52:40h1 class hello then i would have to change this to a dot right and then it will work hello me hold

4:52:47right so it's basically the same selector which you use in the css which you can use

4:52:52with query selector and this is like just the one way of many ways of doing this

4:52:57but yeah that's how it works but yeah that's pretty much it in order to get your first element

4:53:03grab your first element with a css selector store it in a variable and then start manipulating it

4:53:09we will do a lot of manipulations in the coming videos so don't worry about that

4:53:18hey everyone welcome back and in this video let's just keep on doing some dom manipulation

4:53:23and what i'm going to do is i'm going to show you another variant of this and that will be

4:53:27query selector all so what does that mean that means let's say i have a ul tag here and i say

4:53:34list item one list item two and three right so let's say we have a bunch of list items with us

4:53:42and what i want to do here is i want to say that okay what i want to do is i want to replace all

4:53:51the text inside this these list items so what i can do is i can get all list items

4:54:00via document.query document.queryselector ulli right but if you try to console log this you will

4:54:08see that we only get the first item in the console no other item and why is that because by default

4:54:16query selector only returns to the first matching element

4:54:20right so it starts from the top it sees okay okay not found not for notepad and there we go boom we

4:54:25found the element but if you use css you will realize that css actually targets every single

4:54:30one of them right so css if i give a background of yellow for example it will target all of them

4:54:37so strictly speaking this is not exactly like css then right well it has a variant

4:54:43called document.queryselectorall which can act as the following right so right now you can see

4:54:49it it console logs it as an object but truly speaking it's not an object it's a node list

4:54:56so let's just open this in a new tab and actually see a good console from the browser dev tools

4:55:00until we fix that in the code dams environment uh but in the browser dev tools if you go to console

4:55:06you will see that we get a node list as a console statement now this low node list

4:55:13is pretty much very similar to an array but has a couple of differences which we will discuss

4:55:19when the time comes but for now for the most part you can think of node list as an array

4:55:24right so you have three elements you can see and three list items here as well

4:55:29right so what you can do now is just like an array you can i trade over this with a for loop

4:55:37so i can say for let i is equal to zero i is less than all items dot length i plus plus

4:55:45what's happening here is that we are trying to loop over this until we exhaust all the

4:55:49elements in the list and i just plus plus on the i right because this length will give us 3 which

4:55:55is basically the amount of items we have on the screen so the next thing i can say is i can say

4:56:00list item is all list items of i because remember like i told you earlier that you can access

4:56:07the nth element or any element with the index right so in the first iteration this would be zero

4:56:12so all list items of zero will give me access to less than one then two and then three and

4:56:17then so on if there are any more okay so once we have this i can say dot inner text is yo

4:56:27you know and the moment i do that you can see all of the three items turn into you right so

4:56:34that's how you can make use of query selector all and i trade over it and get awesome results

4:56:40when we learn a little bit about es6 in the one of the sections in this course there would be a

4:56:47neater way to do this i mean for loop is fine but we also have some declarative uh ways

4:56:55to run the loops now in javascript but this is also completely 100 percent fine right if

4:57:01you want to use this this is 100 fine but yeah that's pretty much it for this video hopefully

4:57:06you understood how query selector all works this returns you an array of html nodes query selector

4:57:12only returns you a single html node which is the first matching element and that's a big

4:57:17difference you have to remember right sometimes this would be fine sometimes you might need this

4:57:27hey everyone welcome back and in this video let's just take a look at a couple of more

4:57:31ways to actually get to the elements and we'll start off with the get element by

4:57:37id which is i think the only popular um other thing apart from query selector which exists

4:57:44so what get element by id does is that let's say if you have a paragraph

4:57:49paragraph like this and this has got an id of para well you can access this with

4:57:59para document dot query selector para like this but what you can also accept is this

4:58:08word is document dot get element by id and then just the name of that of the you know whatever

4:58:16the name of the id is and one quick notice you have to see here is that query selector

4:58:21tries to use the css selector like format but get element by id does not use that right

4:58:28so that means um it's a little different and the reason why this is a little bit different

4:58:34because this only works for ids right it will not work for classes or anything and this is slightly

4:58:41more performant than query selector if you run in it into millions of elements right because i mean

4:58:50not that you need to know this but technically speaking get element by id creates a hash

4:58:55map of um all the ids on the page with their corresponding references right so this is like

4:59:04a truly o1 kind of lookup if you know what i mean and that's fine if you don't know

4:59:08that's fine as well so that means this is a slightly faster look up compared to this one

4:59:14but for almost every real world scenario you'd never need to know the difference in speed you

4:59:19will never really observe the difference as well this will only come handy if you're doing a lot of

4:59:23loops and dom manipulations and maybe in millions of times or tens of thousands of times per second

4:59:30right so anyway you can stick to just query selector if you would like that's that's what

4:59:35i wanted to say but yeah this exists that's one thing another thing which i wanted to discuss

4:59:41is that whenever you have a node with you for example you have this tag

4:59:46you can pretty much use the query selector again on that so what do i mean by that that means let's

4:59:53say you have a ul for example so i'm gonna do ul as document dot query selector ul right and if i

5:00:04console log this ul fair enough it gives us the ul tag but if i do an li i can do something like this

5:00:13or what i can do is i can just say ul dot query selector li right or ul dot query selector

5:00:20all li and if i console log this li part you will see we have a bunch of lis or if

5:00:27i just do a query selector of a single one we just have the first matching result now

5:00:33the reason this works is because if you think about it when javascript constructs a dom tree

5:00:40every node is also a kind of a small tree right body is a small tree which consists of this

5:00:48these three children and these three are the child of this ul as well

5:00:54so you can think of body as a small tree similarly for ul and any other

5:00:58nested elements so that's why javascript exposes the queryselector method on these

5:01:05nodes as well but what you will not get is a getelementbyid method so if you write getelement

5:01:14by element by id you will see that this method does not exist on the node um which you got

5:01:24right and why is that because like i said because this is a bit performant and it uses hash maps

5:01:30and indexes javascript does not give access of this method to everyone therefore you can only

5:01:36use this when you are using document right so you have to use get element by id bit document

5:01:41but you can use query selector with pretty much any node you like query selector and

5:01:45query selector all so these were a couple of points i believe you should know but yeah that's

5:01:51pretty much it all you want to know about query selector and going into the depth of the tree

5:01:58at this point we'll take a look at a few examples which will clear this out even more in future

5:02:08hey everyone welcome back and in this video we'll be taking a look

5:02:11at event listeners in javascript which is super important super interesting and amazing topic

5:02:17and what this does is that it finally allows you to use your cursor in an interactive way on the

5:02:23page so what do i mean by that that means that now you can create let's say you can create a button

5:02:31called click me and let me just get rid of this as well and you can have an h1

5:02:38saying counter and then a span id counter like this right and whenever you click on

5:02:47this counter this button the counter goes up so how do we do that right now nothing happens right

5:02:54so the way to do this is actually let's just give this button an id of increment

5:03:02and i want to get this button first so i'm going to say increment button is document

5:03:10dot oops document dot query selector increment right now i want to attach an event listener

5:03:19to this that means whenever something some click happens on this button i want a function to be run

5:03:26so what i can do is i can write increment button dot add event listener and then call

5:03:32it as a function so what the name says it says it literally says add an event listener and what we

5:03:38can do is i can specify the first argument as the type of listener i want to attach

5:03:44in this case i want to attach a click listener that means whenever somebody clicks on this

5:03:49i want something to happen right and what do i want to happen i want to run a function now

5:03:56the function which we specify here can be an anonymous function an anonymous function

5:04:01is a function which does not has a name so you just start writing a function like this

5:04:05right so it could be an anonymous function or you can define this above you can say like function

5:04:12increment counter like this and just pass the name of the function you don't want to call it

5:04:19because this will actually call the function you just want to pass the name of the function

5:04:23right so the moment you do that whenever you run or whenever you click this button

5:04:31what will happen is that you get all these console logs right which says run right

5:04:38so this means you have tied a function call a function to an event on the page

5:04:43using browser apis now this is interesting because now you can do all sorts of fun stuff

5:04:50you can create a counter which says zero you can increment this counter and you can finally

5:04:57what you can do is let me just get the count of counter element first document.getelementbyid

5:05:07counter right this was our span tag right here and we can implement the counter variable which is our

5:05:13global counter and then i can also say counter element dot inner text is equal to counter right

5:05:21so now whenever i click on this you can see we are incrementing the counter on every single click

5:05:27why because this function gets called this function gets the element it increments our older

5:05:32counter and we add that counter as the inner text right and whenever we set it with an equal to sign

5:05:39it replaces the value so on every single click we increase the counter now you can do a pretty

5:05:45much a similar thing and you can develop a decrement counter decrement counter like this

5:05:53create a copy of this you can create a decrement button we will get a decrement button like this

5:06:02this would be decrement for example and we will have another button here called decrement

5:06:11right so this would be increment counter this would be decrement counter

5:06:19right so now whenever somebody clicks on decrement button what i want to do is decrement the counter

5:06:27and the decrement in the decrement case we just have to decrease the count right and that's it

5:06:33that's all you need to do in order to play with this counter and if you see that you are using

5:06:38this counter multiple times you can also take out the reference to the global scope

5:06:43and just get rid of them right now it's much more cleaner and simpler to use

5:06:53hey everyone welcome back and in this video what i want to do

5:06:56is actually keep up with our counter experiment and build a little bit of understanding of

5:07:02javascript using this example so the first thing we'll do in this one is actually try to add

5:07:10an element to the screen using javascript and what do i mean by that that means actually constructing

5:07:17an element in the html world which is on the screen with the help of javascript so first things

5:07:24first what i'm going to do is i'm going to create a ul here which just has an id of list items

5:07:32right and every single time i click on increment counter we will add a sentence in this ul

5:07:40so how we will do that well let's see so again the first thing we need to do is actually

5:07:48grab this ul element so ul element element is document.getelementbyid as list items right

5:08:00so the moment we have this ul element then we need on the increment part somehow we need to append

5:08:07a list item to this so first of all let's just see how you actually even create an

5:08:12element so the first step is create an element and second step is append that element so in

5:08:18javascript in order to create an element we have a special api called again on the document object

5:08:25and that is known as document dot create element so this create element right here is a function

5:08:35which takes in the name of the tag which you want to create in this case we want to create an li so

5:08:41i'm just going to go ahead and pass this li as the element right so that's first thing the next

5:08:48thing is we just append that element right and the way we append that element is again using a dot

5:08:55append child um special function and this startup and child special function pretty much exists on

5:09:03every single node which we have right so we have selected these nodes and all of them contains

5:09:08dotted child but we want it to happen on the ul element so i'm going to say ul element dot append

5:09:16child and then li and this should be you know the second sentence and that's it that's all it takes

5:09:23to create an element and append to it right so now if i click on increment you can see these bullet

5:09:28points getting created because a list item is getting appended every single time i click on this

5:09:34right although we cannot see anything because we haven't really added any text content

5:09:39but that's how it works that's how you create it so yeah that's that's how you would create

5:09:45a list item dynamically and now let's just go ahead and take a look at how you add

5:09:50text to it now what you have to understand in javascript is that everything can be a node

5:09:58right in the dom world not in javascript but in dom world so these html tags which you see

5:10:05in the dom world document object model world these elements are nodes right even the text which you

5:10:13have are nodes these text nodes are special and are actually called text nodes right so what you

5:10:21do if you want to append a text node to this li you first of all create that so you say a text

5:10:28node is document dot create text node and then you write the data the text which needs to be put in

5:10:37so in this case i would say a sentence and then i would specify let's say

5:10:44um counter right so that's to just keep the count of what where we at and then what i will do is i

5:10:51will say li dot append child text node like i said every single node which you have has an

5:10:58append child method even the ones which haven't been appended to the dom yet right so this node

5:11:06when it is created at this particular point it's still in memory it's still in javascript it's not

5:11:11appended to the dom therefore it's not visible once we do all the processing and everything

5:11:17then we finally append this right so the the moment we do that something like this happens

5:11:25now you can see that on every single click of the counter the sentence is increasing

5:11:30with the counter which is pretty cool right now this just keeps on increasing

5:11:36now that is cool but let's say now i want to make the sentence bold how do i do that now

5:11:44i have to create another tag right i have to go and create a document.createelement

5:11:50create element there should be a b tag then text node is there b tag should append the text node li

5:12:01should append the b tag and then finally ul element would append dli

5:12:06right and in fact not even this because we have the text node like this li append the

5:12:12b tag we would create a text node too because we don't want the counter to be

5:12:18you know bold so i'm going to say create text node counter and i'm going to say li dot append child

5:12:26text note 2 and then finally this happens right so if i now click on this you can

5:12:31see that sentence is bold why because sentence has been appended inside of a bold tag in html

5:12:38and the counter is not bold because it is just directly appended inside the li now this seems too

5:12:45much right this seems like too much work at the moment so what you can do is you can pretty much

5:12:52replace all of this very easily you can say that instead of all this hassle what i want to do is

5:13:03this li element should have an inner html of the following and you can say this is b

5:13:12something and then plus a counter that's it and if you do something like this the

5:13:18result is pretty much the same thing as you did with all of these lines right

5:13:24so what's the difference well the difference is that this code is actually what the browser

5:13:32has to do anyway in order to understand what every single element is right the document

5:13:39object model is consisting of all these nodes and text nodes and everything so when you do this

5:13:44you are implicitly you're explicitly telling the browser what needs to be done right here

5:13:50when you do this thing where you pretty much just say li dot inner html is a b tag sentence

5:14:00b tag close and then counter when you're doing this thing then you are implicitly telling what

5:14:06the browser should do and then browser takes this puts this as the html this whole thing

5:14:11as the html of the tag right and constructs or reconstructs rather the dom tree of uh the browser

5:14:20right so this is super important this is super super important that inner html can be used for

5:14:25these small shortcuts right so you should remember that it has its own tradeoffs that means this is

5:14:32not exactly equivalent to the other thing which i showed you because for example let's say you want

5:14:36to add an event listener on this b then there is no way you can do that but in the other example

5:14:42if you are creating every element individually you can add an event listener so that's one trade-off

5:14:48there are a bunch of other trade-offs but for this example it gets the job done right and for

5:14:53the most part you should just know the both ways you should go about but that's obviously easier

5:15:00but yeah that's pretty much it for this video hopefully you understood how you can add elements

5:15:06to the screen with just javascript we will be taking a look at more on this later down the line

5:15:18hey everyone welcome back and in this video let's just go ahead and take a look at how you can go

5:15:24ahead and remove these sentences as well so for now if i decrement the counter you can see nothing

5:15:30really happens and i can just only increment it and then only the sentences get added but what if

5:15:37i also want to remove these sentences as and when they get completed or you know not completed but

5:15:43as and when i click on this decrement let's see so the first thing is whenever somebody clicks on the

5:15:49decrement button what you have to see is that this decrement call right here is made

5:15:57right so we have to do some magic inside this function all right that's the first thing the

5:16:04second thing is we need to get to an element which we need to remove right so in order to do that we

5:16:11need well we do know what the element will be it will be a sentence with a counter in the front

5:16:17of it but that's a little harder to catch right from the contents of it so what we can do is we

5:16:24can go back to our basics and understand that in the html side anywhere when you have a data

5:16:32star attribute that's just a custom value or a custom attribute for you like i mean sure you

5:16:38can have an attribute like mehul 2 and you can probably grab that from javascript as well but

5:16:44this is not valid html5 right a valid html5 document would be data mehul 2 for example

5:16:52so anything you write after data dash is allowed basically it's just for custom data so what we can

5:16:59do and then we can use basically the id of this is using this attribute to get access to the html so

5:17:07what we can do is this at this point when we are creating an element i can say li dot set attribute

5:17:18and i'm going to say this as data dash counter to counter right so this is the name of the

5:17:26attribute and this is the value of the attribute so when i do that what's going to happen is that

5:17:32if i console.log this li right here what you will see is that when i click on this we get an li

5:17:40which has a data counter attribute set to one and then two then three four five and so on right

5:17:48that is awesome because now what we can do in the decrement counter function is we can

5:17:53grab the reference of that particular item so i can say const li is document or you know if you

5:18:03want you can also just start with the ul item if you want ul element dot query selector and then

5:18:10i have to catch it via its data value right and the way we can do it is again by using

5:18:16css attribute selector syntax where we write the name of the attribute specify the value like this

5:18:25and say this is just counter right because let's say the counter is 4. now when i click

5:18:32on this decrement counter this gets called the counter right now is four we have the data counter

5:18:38equal to a value of four we get to this and we have this li with us right

5:18:45and then that's simple the next thing we have to do is just call a remove on this right and that's

5:18:51it that's how you remove that's how you can remove basically any element from the page once you have

5:18:57that once you have its reference so now let's try this out i clicked on it multiple times and when

5:19:03i click on decrement counter you can see we just remove the elements in order right so when i click

5:19:11on this the counter is seven we get to the seventh sentence that's what this li is and then we

5:19:17finally call remove we decrement the counter and we increase uh you know repaint that on the screen

5:19:24that's it that's all it does in terms of removing the element but what's important

5:19:29here is that you are able to set the attribute using a function known as set attribute

5:19:35right similarly you can also get the attribute so you can say number is get attribute

5:19:46you know li dot get attribute um and data counter right you can do something like this but this

5:19:56number right now is actually a string right this number is a string because this attribute value

5:20:03although a number but is stored as a string in the html world right so

5:20:09we need to parse this as an integer so how do we do that we use a function called parse end

5:20:16and the reason we write 10 here is because we want to pass this number in base 10 right so that's

5:20:23recommended that you write this 10 here so once we have this number what i can say is if my number

5:20:33modulus let's say 2 is 0 then i want to remove this that means it will only remove

5:20:41even elements not the odd ones so let's just go ahead and increment the counter

5:20:48and let's start subtracting so now if i click on decrement you see that it does not remove

5:20:5419. but if i click on decrement again it removes 18. again 17 does not get removed

5:21:0116 removes and so on so if i keep on clicking this you will see that it leaves me only with the odd

5:21:08elements because of this check right here right so yep that's pretty much how you can retrieve

5:21:14the attribute that's how you can set the attribute and manipulate it in various ways you would like

5:21:20and basically you can do this with pretty much every or any single attribute right it

5:21:25does not need to be a data attribute it could be class names it could be ids it could be anything

5:21:34hey everyone welcome back and in this video let's just take a look at how classes can be manipulated

5:21:42with these get and set attributes right and how you can change and add some dynamic behavior

5:21:47in with the help of class manipulation so what you can do is let's just say

5:21:55for a yellow class which we have here and let's just say we have a red class here

5:22:00or the background of red so what i can do is i can set the attribute

5:22:08to class and i can say this is red or yellow depending on what kind of counter value we have

5:22:16so i can say if my counter is 0 count of modulus 2 that means for every even ones

5:22:22i want to set this class to be red and for every odd ones i want this class said to be yellow right

5:22:30as this is just you know just another simple example of showing you how you can manipulate with

5:22:34javascript so you can see now we get alternative red and yellow stuff here we are doing a little

5:22:43little communication with the css world indirectly through html because we have

5:22:48already defined a couple of classes in css and we just communicate that via html attributes right

5:22:56so that's how it works now this is one way of manipulating css with javascript another

5:23:04way of manipulating the css with javascript is that you actually set the css style sheet

5:23:11yourself and how you can do that is just like any other property like in a html or in a text

5:23:19there also exists a property called style and the style includes a bunch of useful

5:23:26you know css values which you can see we have maximum height width height and width opacity

5:23:34overflow padding all sorts of values exist here whatever you can do with css you can

5:23:38also do here with javascript right so in this case i just want to do background

5:23:45and i want to set this to red right and in this case in the other case i want to set it to yellow

5:23:55so that's it now when i try to do something like this we still get the same result but instead of

5:24:00relying on the css classes now we are actually directly communicating with the css world using

5:24:07javascript so we have skipped the html step where we add the class and html communicates to css

5:24:14but here we are just directly using our knowledge of css style sheets in javascript to

5:24:22you know just add some styles here right and you can also customize it even further li dot style

5:24:28dot let's say padding you can say as 10 pixel in this case and 20 pixel in the other case

5:24:36so in this case what will happen is when i click on increment counter

5:24:40you can see the red boxes are a little smaller than the yellow ones because the red boxes only

5:24:45have 10 pixels of padding so that's how you get an awesome nice result but yeah that's pretty

5:24:52much it that's how you work with css in general inside of javascript we won't get into a lot of

5:24:57these properties because if you do then you know you can spend a lot of a big part of the day here

5:25:04manipulating just css with javascript but yeah you should read a bunch of documentation

5:25:09about this on mozilla developer network you should google about this if you're interested

5:25:19hey everyone welcome back and in this section we will take a look at some of the most popular es6

5:25:26plus features which you should know about so what is es6 plus features well es6 if you don't know

5:25:32what es6 is it stands for ecmascript standard 6 or es 2015 which you might have guessed came

5:25:40out in 2015 so why the hell are we talking about something which is so old well that is because

5:25:46es2015 brought a major upgrade to javascript standard and added a lot of cool features and

5:25:53new syntax to it right and even though javascript updates every single year after that but still the

5:26:00majority of upgrades were brought into es6 and all you see the lit the const all these stuff

5:26:07are actually from es6 update right so the first thing which is awesome about es6 is destructuring

5:26:17syntax what do i mean by that it means let's say you have an array like 1 1 2 3 you have an array

5:26:27which is four five six and you want to create a third array which is the mix of both so how

5:26:33do you do that well instead of running into loops and trying to figure out the logic you

5:26:39can just destructure an array one another a two and when you do that and if you console log this

5:26:48you will see that the elements of both of them are merged right let's try to do one without

5:26:55destructuring and see what happens so when you do it without destructuring you can see that you get

5:27:00one two three as separate elements but four five six in itself is a big element right so it's an

5:27:06array of arrays and if you don't even destructure this one you would see that it pretty much is an

5:27:13array which includes a couple of elements and both of them are arrays which include three elements

5:27:18each right so the way you destructure it oops is using these three dots inside an array and it just

5:27:27it just temporarily blows out these boundaries of the array right and it just puts them right here

5:27:35in that particular place so you end up with something like this right so it works with

5:27:43works awesome with arrays even if you have an array of object for example let's say you have

5:27:48an array like name mayhew and let's say you have an array like you know an array of objects name

5:27:58john for example and if you do the same thing you will see we end up with a couple of arrays

5:28:04not a couple of single array with a couple of objects which are now merged together

5:28:08right awesome the next destructuring which you can do and merging is between objects so you

5:28:18can have an object one where name is mahul you can have an object two where h is 22

5:28:27and you can have an object three where you want both of these properties so how you can do that

5:28:33well you can use the same syntax you write three dots and name and you write three dots not name

5:28:39sorry you write three dots and object one three dots and object two right and the moment you do

5:28:45that you console log object 3 you will see you've got a single object with both of these properties

5:28:53and for some reason if the properties overlap or you know collide so if this was john

5:29:00then whatever properties written the last that means in this case object 2 is destructured the

5:29:05last will hold more um you know weightage in the sense of overwriting so you see

5:29:12the name finally is john and not mahul and the age is 22. why is that because john overwrote

5:29:19this name property because both were same right so that's something you should also know about

5:29:26and one final thing which i think you should know here is that in es6 if you have the name

5:29:33of the key is same as let's say this is key name is same as cool for example this is the value

5:29:41if the name of the key is same as the value the variable which you want to set it to for example

5:29:47if you want the key name to be key name what you can do is you can just omit this key name on a

5:29:53column syntax and just leave it like this and keep on with your business for example some

5:29:58other key some other key as 100 right so this is perfectly fine you can see key name is still cool

5:30:05even though you did not write key name as key name even if you did write it like this it's

5:30:10not wrong i mean but es6 allows you to skip that part and just stick to a syntax like this

5:30:21hey everyone welcome back and in this video let's just take a look at es6 arrow functions well es6

5:30:28arrow functions is interesting because it changes how we define functions in javascript not exactly

5:30:34changes but also gives us one more option so what i can do is i can create a function like

5:30:40this right which is pretty cool right i can just do whatever i want with this but the arrow

5:30:47function also allows us to create a function a function like this where we specify the function

5:30:56in this manner right and pretty much whatever you write inside this function as the body

5:31:02would remain same inside the arrow function you can have variable declarations you can call other

5:31:08functions you can return values here it's fine it'll do the same thing but there are a couple

5:31:13of differences here the first difference is that you can see it's defined with a const or a lit

5:31:20right so what this means is that you can call this function below its declaration

5:31:27and it will not give you any error but if you try to call this function above its declaration

5:31:33then you will get an error that cannot access this function before initialization this thing is not

5:31:41a case when you have a function with a function keyword so if you call this below the function it

5:31:48will not throw you an error if you call this above the function it will still not throw you an error

5:31:55right now the reason for this is because by default javascript takes all the functions

5:32:01which are there and hoist them at the top right the word is hoists hostems at the top

5:32:10right so this concept is what javascript does and that's why you are able to access this function

5:32:17before even kind of it is declared in the order right because javascript changes the uh picks

5:32:24this function and puts it at the top so that it's available for every single code but it

5:32:28does not do that with these functions which are which are arrow functions defined by constant lit

5:32:33and therefore you have to you know you will get an error like this

5:32:39so that's one thing another thing is also a difference in lexical scoping

5:32:43of this but we'll get into that in the more advanced course that's fine

5:32:47but one more interesting part about this function is that you don't have to write a return keyword

5:32:53if you skip the function body as well so you can just write 200 here for example and if you

5:33:01console log this you will see that it returns you 200 right if you pass in a number and you get an

5:33:09argument like argument here you can also just power it to a 2 and you can see we get 10 000

5:33:18here right which is what is returned from this function so this explicit uh you don't have to

5:33:26explicitly write it written here it is implicitly returned if you don't have a function model

5:33:31if you do have a function body well then you have to just write return just like any other person

5:33:36or any other function but otherwise this will work just fine another cool thing about these functions

5:33:43is that you can omit the brackets if you have only one argument right so technically speaking that's

5:33:52as simple of a function as it can be in javascript in today's time right and yeah it looks pretty

5:34:00cool it's clean it's decent and i can understand that it takes an argument and powers it to two

5:34:06and that's it it returns the value right but this does not work if you have a couple of arguments

5:34:13if you have another argument then you do need brackets otherwise it will not work or even

5:34:18if you have no arguments then also you need brackets right the removal of brackets only

5:34:23work if you only have a single argument then it's fine it's even fine with brackets but yeah it's

5:34:29your choice whatever you want to do so yeah that's your introduction with arrow functions and you can

5:34:35pretty much use them just like regular functions for example if i have a const button as document

5:34:44dot get element by id of increment i can say button dot ad event listener click and instead of

5:34:52specifying a function here which might be a little verbose i can just specify an arrow function

5:34:58like this right and i can just say console.log clicked now whenever i click on the increment

5:35:05button you can see i'm getting all these clicked console logs which is pretty cool right

5:35:15hey everyone welcome back and in this video let's just go ahead and discuss about

5:35:20array functions in es6 and what does that mean so you see that we have an array which can consist of

5:35:29multiple elements and you can do whatever you want to do it with it the best and the most versatile

5:35:36way is to actually start a for loop on these arrays right i less than ar dot length i plus plus

5:35:42now you have the current element with arrow i and you can pretty much do anything you want here

5:35:49you have ultimate freedom right but sometimes you might not want a lot of verbose syntax like these

5:35:58so in those cases we have certain helper functions which are declarative in nature that means you

5:36:05just tell them what to do you just specify a conditional and they will just do it so let's

5:36:11take a look at first the first one is a new mapped array and the way this works is you write arr dot

5:36:18map and then you specify a function you specify a function which is called with a functional element

5:36:29on every single pass now what do i mean by that when you call this function and if you

5:36:33just console log this log the element and you return let's say 100 for now from this function

5:36:41so right now if you just console.log arr as well and console oops not here console.log arr and

5:36:51the new mapped array what you will see is right here because of this console we got one two three

5:36:59four five six seven eight nine whatever which are the elements here and the final console log is the

5:37:07original array and with a new array which has all the elements set to 100. now why is that because

5:37:13you can see i'm returning 100 from this method and like i said whatever you return from this

5:37:19method actually takes the gap or actually takes the place of the new or the older value right and

5:37:27very important thing is that this map dot map does not change or does not mutate the original array

5:37:34right so that's important this new mapped array is completely different from the older one so now

5:37:42if you want to square an element you can you can every element you can just simply use this

5:37:48you can see this is now the square of all the individual elements or you just want to say

5:37:55um eight times real quick i love code damn for example if you want to say this eight times real

5:38:01quick that's how you do that right and it will be just there so this is one important function

5:38:08new mapped array how we can create its equivalent in this for loop let's just do that so i'm going

5:38:14to say let's just say we do a new mapped array for equivalent because we need an first of all

5:38:22we need a new empty array because we don't want to modify the existing one so what i can do is

5:38:28for the map part i would just say for equivalent dot push and then the expression which i have here

5:38:35right so if i have just i love code dam i will just do this if i had something like you know

5:38:42which we had earlier element times 2 i would just do el times 2 power 2 and be done with it

5:38:50now the advantage of this function over this is that this can be reduced a lot so i can trim this

5:38:57down to an arrow function where it just gives me an element and just returns me the square of every

5:39:05single element right so that's all we need to do in order to get the new mapped array but with for

5:39:11loop we have to do so much more work right so that's why these elements or these methods are

5:39:17interesting let's quickly go over through another one which i find really interesting and useful

5:39:22and that is the filtered filtered array and what this does is just like map it takes in a function

5:39:32but in this case you don't return an element but rather you return a boolean value either a true

5:39:39or a false so let's say if i return false here the filtered array right here would be empty right why

5:39:47because for every single element in this array we returned false and whenever you return false

5:39:54it will exclude that element it will filter that element out hence the name so if i return true

5:40:00you will see that we get all the elements back so if i do something like if element is less

5:40:05than five then this expression will evaluate to true therefore we only get one two three four

5:40:11if element is greater than five then we will see six seven eight that's it right so that's how you

5:40:18can filter out elements like this so for example you could have an array which is like friends and

5:40:26you just have these friends as name x and h 17 then you have a second friend which is named y

5:40:35and age 21 and you have a third friend which is named znh22 right and you just want to filter out

5:40:43only friends which are above 18 right so the way you would do that is you will write friends.filter

5:40:50element now this element is the single object right so i'll say element.h is greater than 18.

5:40:59and the moment i do that i will see this filtered array actually consists of only two people y and z

5:41:07right which is which are the people basically 21 and 22. it removed the x and the thing you have to

5:41:13note again with filter as well is that it does not create or does not mutate the array so our

5:41:20original array actually consists of you know the x element but the filtered one does not so that

5:41:29is important but yeah that's pretty much it about filter and map there's another one called dot find

5:41:38which is also interesting which just finds the element until and unless it gets a match tries to

5:41:45find so let's say i want to find my friend x right find x so i go ahead and say friends dot find

5:41:56the element find the friend or you can just write friend here if you want i want to find that friend

5:42:04where the friend dot name is x right so when i do that you will see that if a console.log

5:42:13this guy find x you will see that it returns me that exact element present in that array right so

5:42:21i just get name x and 817. if i had something like some some more prop as true for example then i'll

5:42:29also get that right away because it just gave me that object right away right so that's how you use

5:42:36find as well pretty simple um allows you to do a bunch of things and finally we also have a method

5:42:45which does not return you anything in all these above cases it always returns you something right

5:42:51but this method right here does not return you anything but just acts as a for

5:42:56loop kind of right for do pass in just gives you a quick access to all the elements and how

5:43:02do we do that we do a friend start for each let's say friend and right here you can just

5:43:09use this information to print do whatever you want right so if i do a friend like this

5:43:17it'll just print out these individual records right these three records in three different lines

5:43:23so it's just a simple iteration over your array now this could be um your regular area as well

5:43:30in this case you will just get a number from one to eight but yeah that's how you do that so yep

5:43:37these were a few methods which i believe would be helpful for you when you are working with arrays

5:43:42in javascript and that is all for this video hopefully you understood how to use them what's

5:43:48the difference how to work with arrow functions and why you would probably want them over a

5:43:53generic for loop for the most part for loop is also fine if you want to include it but sometimes

5:43:59just to keep your code a little decent and clean you can use these methods wherever appropriate

5:44:10hey everyone welcome back and in this video let's just go ahead and take a look at es6 template

5:44:17literals which is probably my favorite feature of es6 introduced and that means you can now

5:44:23i mean after es6 you can now first of all create multi-line strings so earlier if you had to write

5:44:30a paragraph about me what you would have to do is this is me and then if you try to go to new line

5:44:37this will break right you can see all sorts of syntax highlighting problems as well in order to

5:44:44fix this you would have to escape the new line characters with these back backtick symbols not

5:44:50backtick sorry these backslash symbols but there's a new version of creating a string introduced in

5:44:59javascript which is about me latest and in this case remember i told you that quotes don't matter

5:45:08in javascript right whether you write double quotes or single quotes it's all the same thing

5:45:13but in javascript there's also a third type of way you can create these strings and that

5:45:17is using back dicks and these backticks are the symbol which are probably on the left of your one

5:45:23numeric key and when you do this you will see that this is me and this will not break

5:45:29and you see we don't even need to escape the new lines it will just work fine

5:45:34right so this is pretty awesome what's another awesome thing about this

5:45:39is think about something like this my name is mehul and i am 22 years old right and let's say

5:45:47i had an object here saying person which had a name property has mahul and an h property s22

5:45:55now i want to inject these two properties in the sentence dynamically so how do i do that i would

5:46:01have to concatenate it like this i would need to say person.name and then the same thing for

5:46:10person dot h and i mean it's it's fine at this point even because we just have a couple of things

5:46:18to concatenate but this gets real get that gets that this gets ugly real quick if you have a

5:46:25bunch of variables you want to concatenate right and even bad if you want to perform

5:46:30some math or anything this is super convenient with string literals or template literals here

5:46:37the way we do it is i say my name is a dollar sign then an opening and curl closing

5:46:43curly brace and then write any javascript expression you want

5:46:48and i am and you see we don't have to ever close the uh close or open the codes so it just

5:46:55naturally sits in the sentence my name is this and i am this and here you would see that we have to

5:47:01include all these pluses you know these codes we have to open and close the codes and so on

5:47:08so template literals also allow you to include variable output just like that and you can see

5:47:14that about me latest is pretty much just like you would expect it to my name is fehul and i'm 22

5:47:21years old and a similar thing exists with about me as well right basically the same sentence so

5:47:30yeah that's pretty much how the um template rules work in javascript and that's how you can use them

5:47:43hey everyone welcome back and in this video we will probably discuss one of the most important

5:47:48things in javascript that is a promise and we will also discuss about fetch api within this video so

5:47:56first things first let's say we have an external file or an external api route from where we

5:48:01want to fetch the data right in this case it's data.json in some cases it could be even a remote

5:48:07url right so what we want to do is we want to make use of something known as fetch api which is a

5:48:16function provided by the browser and this function just takes in a url in this case data.json

5:48:23and returns you a special object right this object is not the response data because network

5:48:31requests are unstable and asynchronous and can take a variable amount of time so this does not

5:48:37require return you uh you know uh the response right away but it returns you a promise object

5:48:47right this variable returns your promise object so couple of things this is an object

5:48:55and this is a promise you know one thing about these two things what is an object right an object

5:49:02is basically which you can where you can access further properties or methods right

5:49:08so what is a promise a promise in javascript is basically an object which promises it does not say

5:49:18that it will definitely but it promises to resolve to a value in future sometime in future right

5:49:27so what it says that okay right now i am this promise object but i swear within two seconds

5:49:34it says within two or three seconds maybe more i will have a definitive value that's fair

5:49:41but how do i know that it has got a definitive value well in order to do that what we have to do

5:49:48is we have to write a dot then on this even if you write dot then you see we have three things here

5:49:54dot catch finally and then so we start with dot then and this dot then what it

5:50:00does is that it accepts a function of which the first argument is data right

5:50:06and what is this data this data is actually the result value right so whatever this promise said

5:50:15if it resolves any time in future then this function gets run this arrow functions in our case

5:50:22and this arrow function will run with the first argument being what this promise resolves to right

5:50:30so in this case in our case of requesting data it returns it results with the data

5:50:35which is actually the response so if i console.log this response right here

5:50:42what you will see is if i refresh this let's see you see we have this response right here

5:50:47logged with us which pretty much has a bunch of useful information but it still does not contain

5:50:54the body of you know the response so how do we get that well you see right here let's see if i can

5:51:02see it here not really but this response actually consists of something known as response.json

5:51:10right and this method right here is another promise so i can say this is promise object 2.

5:51:18right so this is another promise which returns us the actual data right so again this promises to do

5:51:27that sometime in the future not exactly right now so again we can bind it 2.10

5:51:34and say once it has data once it has a result just let me know right and i can just console.log

5:51:42the data finally here and when i do this you can see i see record and value finally

5:51:48in the console right so what happened here let's just quickly revisit first

5:51:54things first fetch is an api from the browser which returns you a promise object a promise

5:52:03is an object which promises to deliver a value sometime in the future it might be

5:52:11uh in a second it might be in a couple of seconds it might be in 30 seconds it might be in 30

5:52:16minutes right it's not fixed when this dot then would run it could run as soon as it has the data

5:52:24well as soon as it has the data this dot then runs and in this case in case of fetch in order

5:52:30to read the response we can use a dot json here which parses the response as json automatically

5:52:39and then response.json also returns as a promise it does not return us the data

5:52:44right away therefore we have to do a dot then check again and then finally we console.log it

5:52:51now a great thing about promises is that you can chain them that means every single dot then call

5:53:01always returns a promise even though you are not returning here anything if you return null

5:53:08if you return undefined undefined you know even if you do something like this then also

5:53:15this is a promise object again this is the beautiful thing about dot then that no matter what

5:53:23you return from here it always returns a promise with the value being what you return from here

5:53:30with the result value being what you return from here right so what do i mean by that

5:53:35i can say a dot then here and then final data for example final data and i can say console.log final

5:53:44data is and then final data all right so what's happening here is that you see final data is null

5:53:53right why this is null because you can see i returned null from here from this promise object

5:54:00if i returned 1337 from here you would see my final data is 1337. so that's what amazing about

5:54:09promises that if you return a static value then also it will be a promise if you return an actual

5:54:16promise then also it will be a promise right with the value being what happens when it gets resolved

5:54:24so if you think about this a little what you can do is instead of doing a den then check here

5:54:32you can simply return this promise object so you can say from subject to is returned

5:54:39why would you want to do that because now this gives you the advantage of saying that you can

5:54:47nest these promises instead of just you know instead of just chaining them in one go so now

5:54:54you can see it looks much cleaner than previous iterations and it's much better to read as well

5:55:00right and you can just keep on going technically speaking you can just keep on going and going and

5:55:05going and going if you want you can just keep on going that and it'll still work but there's no

5:55:11need to right so that is a very basic and general introduction to promises we get a little bit of

5:55:18more introduction and in-depth introduction to promises in the next advanced practical javascript

5:55:23course so don't worry about them yet but yeah you should know about promises and working with

5:55:29fetch api like this so that is all for this one i'm gonna see you in the next video really soon

React Fundamentals

5:55:42hey everyone welcome back to another video course an interactive course i should rather

5:55:47say not a video course on code damn which will be on react now react is very special it's very

5:55:54close to my heart because i have been using react for a very very long time in fact in the

5:56:00very first versions of goddamn this platform which you see were built purely in react and

5:56:06yeah i mean it's it's a great framework it's a great tool to have on your list and i'm super

5:56:12excited to start this course in order to tell you the best way to work with react.js and whether

5:56:19your goal is to get a react developer job build your own projects get an internship whatever it is

5:56:26i'm pretty sure that this course would be a solid foundation to that goal so in this course you

5:56:32will find videos and you will find hands-on lab exercises like this but for reactions which you

5:56:38have to do within your browser so make sure you are doing those labs you are completing these

5:56:43exercises you are practicing because practicing is super important and i don't want you to

5:56:50get stuck in tutorial help therefore we will be completing labs in this course

5:56:58as soon as we understand or as soon as we covered an important concept there would

5:57:03be projects to build there would be labs to complete and i'm excited to start this course

5:57:13hey everyone welcome back and in this video let's just go ahead and set up your development

5:57:18environment first how would you develop how would you write this react code which i'm talking about

5:57:24so first things first react is a javascript library that means it's not as different as

5:57:29writing in html and css in javascript which we have been doing so far in the last three four

5:57:35five courses but with the react let me tell you what happens with html and css and javascript

5:57:42you know these are three static files you can create an index.html style.css and script.js

5:57:48include them into one another and you're done with the react there's a build process in between

5:57:55to convert the code you are writing the javascript you are writing into something which browser can

5:58:01understand i mean browser can also understand react directly but let's just assume for now

5:58:08you can assume that you write react in a way and then the browser understands it in a different way

5:58:16although both are javascript but there's some differences which will address

5:58:21so in order to make that javascript compatible from what you're writing to what browser sees

5:58:27we need an intermediate server a build process right so for that we need a little bit of special

5:58:34setup so in order to do that what you can do is a you can set it up on your computer which i'll

5:58:40just quickly show you or b you can use the code damn react playground which we will be using in

5:58:46this course so the best way to follow along is to just use code damn playground and your labs

5:58:52would also be in that interface so that would be pretty much what you would probably need but

5:58:58in case you want to follow locally that's how you can do it go to your terminal your shell whatever

5:59:04you have if you have one if you're on windows you can open powershell or command line and write npx

5:59:12create react app and then the name of the app which you want to create let's say i want to

5:59:18just create hello world and hit enter now the moment you do that you will see that npx uses npm

5:59:26and sets up uh create react app but create react tab actually uses yarn internally and these are

5:59:33like both package managers i'm sure if you have seen the npm course in the learning path which

5:59:40you are following on code damn if you haven't seen pro it's probably ahead um but we will cover npm

5:59:46and yarn in depth in those courses but anyway the moment you do this you will see it will take

5:59:52some seconds um sometimes it's fast sometimes it's flow depending on your internet speed but

5:59:59once it's done you will see that a folder is created for you which you can cd into and start

6:00:06your project and looks like we are almost done here with just a few more updates there we go

6:00:14now you can go into hello world and if you open this in vs code you will see you can start

6:00:19programming right in order to start the server you have to write these commands yarn start yarn build

6:00:24yarn yarn test is not required yarn build is also not required just yarn start with starters start

6:00:30the server this is how you set up locally another way which is the recommended way which will help

6:00:36you avoid all this clutter and setting up on your computer and slow internet speeds is actually go

6:00:41to code down playgrounds right here and click on this react playground react 16 playground

6:00:47we'll update this to react 18 and beyond real soon so you don't have to worry about

6:00:52the versioning i mean it might seem like it's react 16 it's too old but we'll update this to

6:00:57react 18. anyway so the moment you open this you will see that you have a playground booted up in

6:01:05seconds not minutes in less than 10 seconds so once you do that you will see that you

6:01:10also have a terminal at the bottom which we can use pretty much to control all the parts

6:01:16you know just restarting server or if you want to navigate in the server if you want to do ls and

6:01:22stuff you can do that right in our case we don't want to do anything so we just start back our

6:01:28build process which i mentioned like we need a build process in the middle so we

6:01:32started that back and right here in the hierarchy structure you can see we have a bunch of folders

6:01:38we can take a look at and it pretty much matches very closely to what you will have inside of your

6:01:44local setup public src node modules we hide the node modules folder because that's something you

6:01:50probably don't want to enter if you do want to enter you can use the command line anyway right

6:01:56so anyway once you do that if i open index.jsx right here you would see that there is a bunch

6:02:01of code already present in these files so what is this all code and how does this work we will

6:02:07take a look at that in the next video because that's the video we'll be writing hello world

6:02:17hey everyone welcome back and in this video what i want to do is tell you how you can

6:02:22write a hello world program in react.js and before that let's just take a look at

6:02:28what exactly is happening right now at this point when i open this in a new tab

6:02:34so you see that we get a nice little page for us which says edit src react.js but how does

6:02:40this even work i mean if you remember from in the internet fundamentals thing you know

6:02:45that you need your server needs to send an html file first right in order for anything to start

6:02:52so if we take a look at this page source you can see we have a bunch of html right here

6:02:57right which is probably auto generated so we won't go into the source that much what i would go into

6:03:05is basically this public and index.html file so what this file is this file is served

6:03:13whenever you load that website right you load your development setup so what this file is it's pretty

6:03:20much boilerplate it's a template right you don't you would not be working in this file in the html

6:03:25file why because what you have to realize when you are working with a framework like react you do not

6:03:33basically write html in html files right you construct that document object model the dom thing

6:03:40which i was talking about inside of javascript that is important that when you're using react we

6:03:47don't write html and manipulate it with javascript we actually create the whole html or you know

6:03:53most of the part from javascript world itself right so for that all we need to do in this case

6:04:00is we have an index.html file we have this special tag which you don't need to remember like you

6:04:05don't have to remember this information which i'm telling you but this is just just me telling

6:04:10you how everything is working we have the special tag which is pointing to a file slash dist slash

6:04:16index.js and you might wonder that i'm not able to see this directory anyway right any i'm not

6:04:22able to see this directory anywhere so how does this work well the reason this works is because

6:04:28remember i told you that these are not static files i mean these are static files but they are

6:04:34served by the server called snowpack in our case now this server could be any any server right it

6:04:40could be create react app which we saw in your local setup in this case it is no pack it could

6:04:46be es build it could be any sort of server the the point of the server is to build or slightly

6:04:54or lightly build your code which is being shipped to the browser right even in the development mode

6:05:01why because if you take a look at this thing right here you see we are writing some sort of

6:05:06html in the javascript world right and of course this is not supported in javascript

6:05:11out of the box i mean you cannot really write javascript you cannot really write this html

6:05:16like thing inside javascript right away right it will not work so why does this work well

6:05:22because this is the snowpack right here which is sitting right in the center injects some sort of

6:05:28code or manipulates or you know just creates this behavior which allows your browser to understand

6:05:35what is going on here right so this is like super important stuff in the sense that you should

6:05:44always remember that whatever you're seeing in this public dot html public index.html file

6:05:50it might or it might not be true what do i mean by that for example in this case slash disslash

6:05:56index.js this file when accessed is not actually looking at a at a file system file but is actually

6:06:04served automatically by this process right here right which just sees that hey if this page is uh

6:06:13accessing this slash disk index.js file let me go ahead and serve this page this generated code out

6:06:21of the mem out of the build process so anyway what you have to remember at all from this video is

6:06:29that you will always work with javascript files or most of the times you will work with javascript

6:06:36files when you are working with react right you would not be interacting with dot html files

6:06:41for the most part right so this is super important but yeah i mean once we have this

6:06:47in case of just doing hello world let me just go ahead and first of all delete this so that

6:06:52we can do a little bit of minimal hello world and i'm just gonna say react on.render h1 hello world

6:07:01and h1 closes that's it that's all i would do and we could probably remove this as well let's

6:07:10see if i refresh this page because we had some major changes out there deleting files and stuff

6:07:16you can see we get a nice little hello world right here so we'll go into this what is happening here

6:07:21in this program and how everything is working but yep this is your hello world the very first hello

6:07:27world you have done on react and i mean you don't even need these css files if you really

6:07:33want a really really minimal hello world then what you can do is let's see something like

6:07:43this yep i mean you can do this and you get a very basic hello world in react so all you need

6:07:50is a bundler which is snowpack which is running in our case an index.html file which is like the

6:07:55first file which is served and just a single file saying dot render hello world and there

6:08:02you go and this is basically this element we'll get into this how this is working

6:08:06but if you're smart you would be able to see that we have a div id root on the page

6:08:10and that's exactly what it's targeting right so yep that's pretty much it for this video

6:08:16hopefully you were able to write hello world in react yourself if not we would have a lab

6:08:22after this when you have to write so that's how you would be able to practice with me

6:08:33hey everyone welcome back and in this video we'll be taking a look at how the hello world

6:08:37program works in react because it's super important stuff and super fundamental to get

6:08:42right when you're starting off so what i want to do first is start from the very first line here

6:08:47which is importing react from react and for those of you who don't know what this import syntax is

6:08:53i'm sure we have discussed this in the javascript basics course some some course before

6:08:58so if you are watching this and if you know that's fine but for back for those people back

6:09:03in the audience who are relatively new to this this is just the syntax of new es6 import syntax

6:09:11if i go ahead and create a file let's say calculator dot js right

6:09:17and if i go ahead and create a function add num1 num2 and if i just console or you know just return

6:09:25num1 plus num2 what i can do is add a keyword called export in front of this and now

6:09:32any single file in this project can import this function right so it's basically making

6:09:39your code mode more modular so i can go into this index.jsx and i can say import

6:09:47add from calculator right and what i can do is i can say

6:09:56console.log add five six right and what this will do is um

6:10:07let's see i don't think we'll get a result like this so maybe we can just probably alert this

6:10:12so what this will do it basically give me an alert of 11 right console.log is probably being

6:10:18blocked by snowpack here so a load just works so i'm able to import this function from this file

6:10:24now quickly i was able to see that i had to write these curly braces when i'm importing now we would

6:10:32probably discuss this more in the es6 syntax es6 import syntax but the tldr here is that if you

6:10:38use just export then you have to add these curly braces because you can do it for multiple multiple

6:10:44functions or multiple variables you know looks like we need to disable this alert there we go

6:10:52and if i do a subtract for example and return num1 minus num2 this will also work so i can import it

6:10:59like an object like syntax but not really right so if i do something like this this will also work

6:11:05you might sometimes see that your import is not working just give it a refresh it should

6:11:11and if you use something like export default function abc and return 100 for example

6:11:20then in order to import this into some file you just use that without the curly braces

6:11:27right that's basically the crash course on es6 import export syntax so right here you can see

6:11:33i mean there's a lot to it don't really just you know consider this as the ultimate tutorial

6:11:39i have kind of like oversimplified a bunch of things here as well but that should be

6:11:43enough to get you started but what i want to do here is i just want to show you this

6:11:49react and react on what they are doing they are basically importing these two important packages

6:11:55react and react on and further down the line in the further advanced tutorials about react what

6:12:01we will understand is that react is nothing but a ui library which handles trees right that's

6:12:10all reactors react knows how to differentiate how to diff not differentiate how to diff that

6:12:18means take difference of two virtual dom trees and just tell the renderer in this case the browser

6:12:26what are the differences which needs to update on the screen right so let's say if you had a

6:12:30thousand hello worlds and i click on the third hello world you do not need to repaint all the

6:12:37thousand hello worlds right you just need to repaint that third hello world that's it that's

6:12:42all reactants to browser and that's all react does and that is the function of react now people

6:12:48realize that this behavior is awesome and we can actually make it generic right so they took react

6:12:55out of the browser and started using it in places like mobile for example you have react native

6:13:01now when they did that they also realized that this has to be generic like i said so what they

6:13:06did is they split react into two parts the first part is the reconciler which is basically what

6:13:12i said that this uses the diffing of trees to understand what's happening and ui consists of

6:13:20trees right whether you are on web whether you are on mobile it consists of a root element then you

6:13:25have a bunch of elements and so on and so forth and what the second part was of the equation was

6:13:31the renderer so in this case react needs to know how to create elements on the screen for example

6:13:37react needs to know about document.createelement right when you're writing this h1 hello world

6:13:43and react has to render everything in this div id root then react needs to know how

6:13:47to create this h1 right or how to create that div so react dom has that job react tom tells

6:13:56uh the react how to create these elements on the screen right so yep that is how it works and what

6:14:04is happening here is that react dom has to get a first initialization point of how react should

6:14:12start or where react should start rather so what it does is it the first argument it takes is a

6:14:18root element and the second argument it takes is basically the place where you should mount

6:14:26that react tree right whatever that is so you have one root element which can

6:14:30contain multiple elements and you need a place to mount that on the screen so you just create

6:14:37some random place you it could very well be body but it's usually recommended that you just keep it

6:14:42some div or something so that you can still use other parts in your html so that's what we do by

6:14:47default document.getelementbyid root and there we go so that's all it does that's all hello world

6:14:54program does but it does a lot of things right and soon by the end of this course or maybe in

6:15:00you know some other course we will also discuss about the react 18 and beyond features which

6:15:06include a bunch of interesting stuff right it includes concurrent ui and stuff like this where

6:15:12this definition actually changes where you don't have react.render but something known as create

6:15:18root we will learn about that don't worry about that it's it's ahead but this is like the old and

6:15:26you know solid way so far of creating react

6:15:34hey everyone welcome back and in this video i just want to upgrade to react 18 so that we can

6:15:40also use a bunch of reacted in features as we go ahead because that's the latest react right now

6:15:45and i'll probably update this whole course or you know parts of this course if react 18 also

6:15:51becomes outdated but anyway at the moment what we have to do in order to just upgrade to react 18

6:15:57first things first you can see we have a yarn.log file that means we are using gyan as the package

6:16:01manager here so i'm going to say yarn add react at the rate alpha and what i'm doing why i'm doing

6:16:09alpha because react 18 is an alpha at the moment and that's what we need to have right similarly

6:16:17i'm gonna do yarn at react dom at the rate alpha right and the moment i do that you will see

6:16:26that basically if i get package.json you will see a react and react dom both are on react 18 right

6:16:36awesome so once we do that let me just go ahead and refresh restart the server here real quick as

6:16:42well so yep if i refresh on this you see that we still have pretty much no change at all hopefully

6:16:53it's just the bundler is just starting off the build process so there's that but yeah i mean

6:16:59it should probably give us the same output more or less let us hope and there we go there we go

6:17:11so we have an h1 rendered on the screen but right now we are running react 18. you can see it in the

6:17:17terminal and we can also verify this real quick um on how you can use a new react feature which is

6:17:25known as create root so what is this root api for now you don't need to worry a lot about this if

6:17:31you're starting off but i'm just showing you this so that you can show off to your friends that hey

6:17:35you are on the latest and greatest react so i'm going to say container here is my root element

6:17:43and instead of reactdom.render i'm going to say react dom dot create

6:17:49root of this container right and i'm going to say this is my root element and then i'm

6:17:55going to finally say root dot render what do i want to render h1 hello world there we go

6:18:05and boom we basically have the same hello world but in a two different in a different syntax right

6:18:12earlier we used to have react.createelement now we have react.createroot and if you're confused

6:18:18it's fine i mean it's fine to be confused because the real benefits of react.createfood

6:18:25would be out there when you actually understand react internally very well right which is the aim

6:18:31of this course so anyway i just wanted to put this out that we are using the latest course

6:18:37the latest technology so that you don't feel like you're watching some course from 2017 or something

6:18:48hey everyone welcome back and in this video i want to go ahead and explain components to you now what

6:18:54component is it's basically the fundamental building block of react now how react works

6:19:00is think about this in the following way let's say i go to codedam.com which you can see right here

6:19:06on the screen you can see that if you think about it you can split this layout into multiple

6:19:12components the first one is this header which is sticking at the top and inside even header

6:19:17we have these links right here right the next layout which you can think of is these repeated

6:19:25areas right you can see these areas are repeated multiple times then this is this block right here

6:19:30on the right which is floating so you can split pretty much all of this into multiple components

6:19:36and finally we have a footer at the end right so what you can do is in react the way you work is

6:19:44that you split this whole ui into different sort of components and then code them all individually

6:19:50and then use them together right so the first step you need to do in order to start your programming

6:19:57journey basically is to just go ahead and create a folder let's say components right here right

6:20:04inside this i'm gonna say i start with head header dot jsx and if you're wondering about what this

6:20:11jsx is the extension it just stands for javascript extensible extensible javascript now what this is

6:20:20it's basically the syntax which you are using right so if i say for example function header

6:20:26like this and let's just return header just like regular html and i just say hello world

6:20:33or you know not hello world too much hello world is there already this is header

6:20:40so what's gonna happen now is that when i export this export default header i could go ahead and

6:20:48use it right here like this right and of course i have to import it as well so i'm going to import

6:20:54it like components header right and the moment i do this you can see on the screen i get this is

6:21:01header which is pretty awesome because now what i can do is instead of creating this as header

6:21:08i can also create my initial app.jsx component right and what this app.jsx component will be it

6:21:16will pretty much be what we are doing right here but instead of app basically i would say a div

6:21:22and instead of h1 i would just embed our header right here so it might seem that i'm just going

6:21:30a little faster but we need this boilerplate code in order to understand it better but the moment i

6:21:35do this you can see now i can switch from header to app and all i need as my root component is this

6:21:42app right here right and there is no change basically in the header part because it still

6:21:49renders fine but now i can split this website into multiple paths header for example i can include a

6:21:56footer and in the middle there they will go the content so i can say this is divided content

6:22:03and i can say that this is pretty much like hello there right so if i have a p

6:22:11opening and p closing you would see that we get a hello there which is pretty awesome

6:22:15right now you can make all sorts of changes here and this will work just like that

6:22:22so yeah that's pretty much it that's how you work with functional components

6:22:26in react all you need to do is make sure that you create the root component

6:22:31as a single component and then that component will be kind of like you know your bootstrapping way

6:22:38of layout we can include header which are different components we we can include bunch

6:22:44of regular html and we can include footer etc as well which we will see very soon as we proceed

6:22:54hey everyone welcome back and in this video let's just go ahead and explore about jsx in

6:23:01javascript and in react basically so what this jsx is it's basically this weird syntax which

6:23:08you're able to write which looks like html but it's not html so what happens with javascript or

6:23:16in react in this case is that earlier when react was new what you had to do is you had to import

6:23:22react first and then you have to do some weird stuff like react.create class and then pass in um

6:23:30basically an element and stuff like this and i don't even know if this was create class or create

6:23:35element or something like that but what you have to do is you have to actually write in javascript

6:23:41to create the html like structure right just like with dom what we do we do uh let's say a ul is

6:23:50document dot create element a ul right then for an li i do the same thing document.createelement li

6:24:00then what i do is ul dot append child li right and then what i would do is for example i would say li

6:24:08dot append child document dot create text node and so on right so this is this is super verbose right

6:24:16all this code all these four five lines of code is doing is generating this syntax ulli three dots li

6:24:24ul that's it so so much information is there even though we had so much better syntax like

6:24:33html already in place so what react does is that it combines the best of both worlds that means

6:24:40you get the best of javascript world that you can compute and do all sorts of stuff in a function

6:24:44but at the same time what you're also able to do is you're able to write html like syntax here

6:24:51now your browser does not understand this right your browser by default does not understand this

6:24:56therefore we have snowpack babel stuff like this running which converts this compiles it down into

6:25:02different syntax and that is what is understood by your browser now that is awesome because

6:25:10now we can as developers we can write in great looking syntax and the browser can understand in

6:25:18the syntax which it wants right so this looks very very close to html with a couple of differences

6:25:24which you will understand um but yeah that's that's great right because now you can write html

6:25:30like syntax in javascript but the problem here is or rather i should say a great a great great

6:25:36feature here is that you cannot write invalid html right if i let's say if i remove the stiff tag

6:25:41you will see the whole code breaks right now this is because of the internal validation performed by

6:25:50javascript on this jsx syntax which you're writing but nonetheless this is awesome because now you

6:25:56cannot write a broken html technically this would work if this was in an index.html file but it

6:26:02does not work in a react case so that's awesome so anytime you are seeing this error message like you

6:26:08know unterminated jsx contents that probably means that you have messed up somewhere in your html

6:26:14like looking syntax so this is one thing another thing which is super important and critical in

6:26:20which you have to understand that in javascript uh in react at least for now at least right now when

6:26:27you want to create a class to an element or assign a class name so that you can style it with css you

6:26:33don't use the class keyword right you don't use the class keyword you use the class name keyword

6:26:39right and why is that because class is a reserved keyword in javascript and there are reasons for it

6:26:45the way javascript is compiled how it gets transformed so react developers just said screw it

6:26:52we will not allow people to use class but rather just you know just go with class name so a lot of

6:26:57places when you are reading react.js code reactors code bases old and new you will see that they are

6:27:03using class name instead of class this is not a special attribute if you take a look at the dom

6:27:08for example if i open this in a new tab and let's say i inspect this by taking a look like this

6:27:18and if i increase the size you will see if i go to elements we get a class of dsf dsf right not

6:27:24a class name but rather a class right here so this is another thing the third thing you should know

6:27:31about jsx is that you can write actual javascript expressions right here right so you can do hello

6:27:40two plus two like this and you will see that it actually spits out hello four right here instead

6:27:46of hello you know two plus two literally so in order to write a javascript expression all you

6:27:52need to do is open a curly brace and close a curly brace and write whatever you want here

6:27:58now you might think what can i write here and what cannot i write here so think about this

6:28:04in the following way you can write whatever you want here as long as this is something which you

6:28:13can also pass in a function call right what do i mean by that let's say you had a function called

6:28:19dummy right with just console logs whatever you're printing let's say this is one argument right

6:28:26whatever you're sending so you can call this dummy with two correct you can call this dummy with

6:28:33this a string value correct you can call this dummy with an array like correct you can call

6:28:39this dummy with x greater than 5 or you know not x but let's say 4 greater than 5 is true then

6:28:45hello otherwise world like this like ternary operators and stuff

6:28:50you can do this stuff right but what you cannot do is you cannot write if something then do something

6:28:58right this does not make sense you cannot pass this as an argument similarly you cannot write

6:29:03this if else statement like this right here in this stuff right all you can write here is

6:29:09what you can probably pass in a function call as well and we will understand we will actually

6:29:15understand later down the line that that is a very good way to realize this because the syntax

6:29:21is actually converted by babel and others is actually converted into a function called

6:29:26argument itself right so this jsx expression actually becomes a function call argument

6:29:32so anyway that's it that's all you have to remember so you can say that if i am am i above 18

6:29:44if this is true for example i can say am i above 18 is true then i am

6:29:51above 18 for example otherwise i just return null and null is a special jsx element which

6:29:58just not does not render anything right it will not render anything on the screen

6:30:03so if i make this false for example you will see that this is then gone

6:30:08right because well i'm not above 18 so it renders null so instead of this you can say i am too small

6:30:15right something like this so now you can see if i toggle between true and false you will see

6:30:21it just changes into a i'm mobile 18 and i'm too small right so on and so forth so yep that

6:30:28is your introduction with these javascript jsx how react uses it and how you can work with it

6:30:36as well we will be using a lot of these components and a lot of stuff and we will

6:30:40be playing around with some dummy applications as well so make sure you are able to understand

6:30:45this you are able to complete the practice labs on code dam and move forward from there

6:30:55hey everyone welcome back and in this video let's just go ahead and learn about something

6:31:00important which is known as short circuiting in javascript and how does that work because

6:31:06the further concept which i'll be discussing is based on that so we need to understand this

6:31:10fundamentally in javascript first so in javascript what happens is let me just go ahead and actually

6:31:18do nothing here except for a simple console log in the browser and i want you to guess the output of

6:31:25what would happen right so just checking up once you can see we get one so that's fine what i want

6:31:32to do is i want to say true and let me just switch it to terminal so you cannot guess it right away

6:31:40and false so i want you to guess what would appear in the browser in the console

6:31:47if we take a look in the console you see we get false right now the reason we get false is because

6:31:54when you use double and in javascript what it tries to do is it tries to keep on checking

6:32:02the argument as long as it does not find one falsely value what do i mean by that if i have

6:32:12let's say hello double and mayhew double and undefined if i have an expression like this

6:32:24you see we get undefined in the console now the reason for that again is because hello is a truthy

6:32:30value right it evaluates to true when you force typecasted into a boolean similarly mahul is a

6:32:37string it's a truthy value but undefined is not a string or you know it's not a truthy value it

6:32:44evaluates to false that is why ampersand these double ampersand will keep on checking which one

6:32:51is a false value and the first value which they find they will stop at that what do i mean by that

6:32:56if i don't have any falsie value at all you see we get mahul in the console which is the last value

6:33:04so pay close attention what's happening here if i have an expression which is just this

6:33:09so if i assign this to a variable which is thus just this we will get undefined

6:33:14if i assign this expression to a variable we will get mayhol as the value right if i have undefined

6:33:22in between you will see again we still get undefined because remember i mentioned it

6:33:27will go ahead and keep on looking until and unless it cannot it does not find the first false value

6:33:34and in this case it just finds it because you know it's the second value so it does not look forward

6:33:39so this is known as short circuiting behavior in javascript and why this is important because what

6:33:46it allows us to do is do conditional rendering now what do i mean by that let's say i have a div here

6:33:53instead of just an h1 which just says h1 hello world right and what it does

6:34:00is that it has a paragraph which may be visible right so this paragraph may or may not be visible

6:34:10and the way this works is that let's say if i want to make this an expression a jsx expression

6:34:17remember we talked about how you can make a jsx expression with these curly braces and in fact

6:34:23as a matter of fact you can write html like tags of jsx within these expressions as well

6:34:30but what's powerful now about this is that i can bind this to certain expressions so i can say

6:34:35something like true and double and this thing now what does this mean taking a look at this

6:34:42it will try to evaluate and you know just keep on evaluating as long as it does not find a falsie

6:34:48value right and in case it does not find a falsie value it will just return you the last one so in

6:34:54this case this whole expression actually just becomes this single p tag right similarly if you

6:35:01had a false here then you see nothing appears on the screen right because by default faulty values

6:35:08just are not visible um in a jsx expression right even if you have something like zero here which is

6:35:15also a false value so you can see here here this is a little fun why because you can see zero gets

6:35:22rendered on the screen because zero is a false value so this whole expression becomes zero and

6:35:27react just shows you zero right but in most cases if you know this is a boolean expression this is a

6:35:34common pattern which people follow right a boolean expression for example like age greater than 18

6:35:41and and this thing so what does this mean let's say if there's a variable called 18 uh h which

6:35:47is 18 you can see it does not render it but if i change this to 20 for example you can see now

6:35:53we get the p tag on the screen right so this is super super interesting and super important stuff

6:36:00which is one way of doing conditional rendering in javascript conditional rendering just means

6:36:05that sometimes the element might appear on the screen sometimes it might not right

6:36:10another way of doing conditional rendering is using ternary operator which you should

6:36:14probably know about so this basically also requires you to specify the false case

6:36:20so you can say that if age is greater than 18 then you want to do this otherwise you want to

6:36:25just render null or any false value right you can also write false here but null is basically what

6:36:30you should write because null is a jsx element a jsx component a valid jsx component as well

6:36:39all right i think this is pretty much it all you need to know in order to

6:36:42conditionally render elements we will learn more about them when we work with state in javascript

6:36:53hey everyone welcome back and in this video let's just go ahead and take a look at what props are

6:36:59in react and how they work now we will be spending a lot of time with these things so you don't have

6:37:05to necessarily worry about them right away but it's good to know about them so what props are is

6:37:14basically in react what happens is just like in java in html we have discussed if you go to a

6:37:20page source for example you see we have this html then it contains a head then it contains a body

6:37:27and so on right so what we know here is that html constructs a tree like structure which is called

6:37:34as dom right similarly what react can also do is it also constructs a tree-like structure which is

6:37:42also called virtual dom but the point here is that react can also have custom components

6:37:49right so let's say we have a new component here which is custom.dsx or not dsx but jsx

6:37:57for now so if i have react from react and if i do something like function custom like this

6:38:05what i can do is i can just return h1 hello me whole right so let's say this is a greeting

6:38:13component which is like a very common example but there you go so now what i can do is i can just

6:38:20say custom like this and it will just surrender hello me right after importing this like this

6:38:30but the problem here is let's say i want to change this name to something dynamic right

6:38:36so this should be supplied by an api or something so what i can do when i'm rendering this component

6:38:42is i can actually pass it custom data alongside this component which helps it to render properly

6:38:49now this data could be optional this could be mandatory depends on how you

6:38:53have created the component but in this case what i can do is i can give this

6:38:58this give this function a new argument the first argument called props now this props argument is a

6:39:05custom object which is supplied by react to this function when this is rendering right so you could

6:39:12pretty much use these props in in here and react will make sure that these props are available

6:39:18when this function starts rendering now we know this props is an object but what is it exactly

6:39:24well this is an object in which keys are the keys which you pass in here as attributes so i can have

6:39:32something like name and the values are in fact the values which you pass in the attribute value so i

6:39:40have decided that i would just write name equal to may whole for this custom attribute custom

6:39:46function and what this would transform the props into into something like this name as mayhem right

6:39:54so what react is doing under the hood is that it will transform this calling signature and it

6:40:00will make sure the props which you receive in this custom component is in the following object format

6:40:05so all i need to do now is that go ahead and just write a jsx expression here called props dot name

6:40:13and voila you can see that i get hello meijo instead of hello mayor which was also before

6:40:19but we could change this to pretty much like anything and it will immediately reflect right

6:40:25so this is pretty powerful because now what you can do is you can create a very generic component

6:40:33like you know i think we discussed an example of e-commerce website right so this could very

6:40:39much very well be a uh item in in in the website right it could be a singular item and then all

6:40:47of the data which it needs in order to render whether it's price whether it's title whether

6:40:51it's description whether it's rating all of that could be supplied by props and how would

6:40:57we get that data in props through an api through a fetch api call or whatever we'll discuss that

6:41:03but yeah this is your introduction to props and one more thing which is possible here which is

6:41:09usually not possible in the html world that is that you can supply this uh jsx expression as well

6:41:17right so we discussed that you can do weird stuff like two plus two here and it will evaluate into

6:41:22four you can pretty much do the same thing you can pass pass like variables you can pass expressions

6:41:29you can do anything you want and you can see it renders correctly if i pass an age like this if

6:41:35i square this you could pretty much do a bunch of stuff here with props and of course i mean you can

6:41:41pass multiple props here so you can say greeting message as hola for example and what you can do

6:41:51is just replace this with props.creating message and this will also work right so you can customize

6:41:57it as much as you want it's up to you but yep that's pretty much it for your introduction with

6:42:03props we will be using this a lot again like i say uh with jsx expression and everything because

6:42:09this is more or less how javascript works and react and how reactants itself is used a lot right

6:42:21hey everyone welcome back and in this video let's just go ahead and take a look at how you can

6:42:26basically add a dom event listener kind of thing in react world now this is basically

6:42:32how you would do exactly in javascript but with a little bit of differences in javascript you

6:42:37would have remembered that we use add event listener to add certain events right in react

6:42:43we do it in a little different way the way we do it is that we don't use ad event listeners

6:42:49and anything but we directly go ahead on the element let's say this button says click me

6:42:54and on this button right here i would just go ahead and start writing on click

6:42:59and see that the c of this on click is capital this is important because if you make this small

6:43:04your handler will not be called so what this is is that first things first you can see that i'm

6:43:09directly given giving it a javascript expression now the reason for that is because i want to pass

6:43:14in a function here it does not make sense for this on click to be a string right so what i'm going to

6:43:21say is i let's say this is button click function for example and just create this function outside

6:43:29our component which just says console.log i was pressed right just like that so now what i can do

6:43:39is i can just go ahead and start clicking this button and you can see in the console i start

6:43:42getting i was pressed so all you need to do and all you need to remember in react is the way

6:43:49the eventlessness work is that you have an on and then whatever the event is um as an attribute or

6:43:57as an as a prop rather i should say right so this is a prop which you which you're passing

6:44:02to this button which you react internally binds to actual event listener on the page

6:44:07right now the funny thing about this is that if you actually open this in a new tab and try to

6:44:13take a look under the hood of how this is working you will not find this on click attribute in the

6:44:20in the rendered dom right so if you take a look here you would see there is no on click attribute

6:44:25present here right and the reason for this is because this binding although it works this is

6:44:31internally binded using add event listeners and stuff right it's not just directly an inline html

6:44:38sort of uh function binding so this you should remember but yep this is how you would work

6:44:44with it and one more thing which you would often find a lot of people doing is that they would be

6:44:50defining their their callback functions for events right into the component and this might seem like

6:44:57a crazy thing to do that defining a function inside a function if you have never seen it before

6:45:02but this is pretty common in react world right what you want to do is you want to keep your

6:45:07functions as tight as possible so you would just try to keep everything enclosed in a single scope

6:45:13so this is perfectly fine practice and in fact this is actually mandatory if this

6:45:18function wants to access any state variable or anything which we will take a look at

6:45:22very soon but yep this is pretty much it how you should go ahead and attach a click event

6:45:29listener for example and that is how react binds it to your real elements on the page

6:45:41hey everyone welcome back this is an important video because in this one we will be starting

6:45:46off with introducing the concept of state in react so so far what you have seen is pretty much

6:45:56useless till certain extent because we are not using react to its full power what react is

6:46:03really capable of it's capable of creating these static pages and static stuff it's fine but the

6:46:10true power of react is realized when you actually add interactivity and stateful components now what

6:46:16is the stateful component or what is state in general so you see most useful applications or

6:46:23most applications which involve some sort of user interaction need to be stateful that means they

6:46:29need to remember what has happened in the past for example in games if you are playing tic-tac-toe

6:46:36you need your game needs to remember the past that is which one which box is square which boxes which

6:46:43works as occupied which box has not been occupied which who's the winner and so on similar thing you

6:46:51need to you can do with react components as well by introducing the concept of a state so let's

6:46:57take a look at a very simple example in this one let's say i have a counter like this which is just

6:47:04a number you know like you can right away see that i did not use a 0 right inside this but i gave it

6:47:11a number right and we can get rid of the custom component you can see i have a counter of 0.

6:47:17let's say this button increase the counter and the next button decrease the counter right and i have

6:47:29this first function which just you know pretty much just console logs i was pressed

6:47:34now what i'm going to do is i'm going to import a function called you state from this react

6:47:39library and i'm gonna say stick with me here for a while counter set counter is you state of zero

6:47:50now there's a lot that needs to be explained here so let me just go ahead and explain it first of

6:47:57all before we even move forward so first things first u state is a function internally provided by

6:48:03react it's a function right it's a it's a regular function you can think of but this function is

6:48:10called a hook in react right so anything which starts with use it's a convention technically

6:48:17speaking but react considers anything which starts with the use as a hook right what is the

6:48:23difference between a function and a hook nothing on the technical sense but if you are using a

6:48:30react linter react will warn you if the u state hook or you know if any hook as a matter of fact

6:48:39is conditionally rendered that means all of your hooks needs to be at the very top of the function

6:48:44right anyway what we need to discuss right now we can just forget about the hooks complexities for

6:48:50later down the line but what we need to discuss right now is that this hook right here u state

6:48:56accepts a default value so what this default value is is that when this app component would render

6:49:05for the very first time this is the value which would be used as the default value for counter

6:49:12and the way i have destructured this you would have observed that this

6:49:16u state actually returns you two values right so i could have also done something like counter set

6:49:24and then i know this is an array so in order to display this i would do a counter set of zero

6:49:30so what this does you can see it gives me zero if i re if i make this hundred

6:49:35and refresh this page you will see i get a counter of hundred why because this is the

6:49:41default value which is available to us right and the counter set of one is actually a function

6:49:48so what that function does is that if i call that function with any value that is what the zeroth

6:49:58value or you know the counter value becomes now this is important because let me just go back to

6:50:04the previous syntax because that way you would be able to see it in a much better way so now i

6:50:08have counter for example now what i'm telling is that let's say in this function i say the counter

6:50:16becomes negative 250 right so the moment i click on this button you will see that this right here

6:50:23updates to minus 250. so let's go and you can see it updates to minus 250. so what happened what

6:50:30happened this is this is the exciting part and this is the part where you have to be most careful

6:50:36you just told react declaratively what you want to do and react automatically matched it to your ui

6:50:45super powerful stuff why because what you have here is just a counter right

6:50:52and a set counter function the moment you click this button you scale this set counter function

6:50:58with a new updated value and what react did under the hood is that it repainted this ui it recreated

6:51:05this function it actually recreated this whole function right it called it again and it saw

6:51:11that okay this counter variable now in the last render it was 100 but in this render it's -250

6:51:18so i'm gonna go ahead and show this on the screen now the important part here is when

6:51:23this function is called again so this is like we can mark this as the first

6:51:28render right so in the first render what happened was that this u state the array value which

6:51:35this returned was something like 100 and then a function right this is what this function returned

6:51:42but in the second render which happened when the moment i clicked this button

6:51:47second render let's just make this an underscore so that it does not complain

6:51:52what this u state returned was negative 250 and a function important the same code everything same

6:52:00but react knows that this is the second render right react is aware about the state of the render

6:52:06so this allows react to you know basically allow us as developers

6:52:14to use const even though this variable technically changes in the next render right so this is why

6:52:21you have to remember why you can use const with state variables because state variables are not

6:52:26mutated they are actually created again in the next render so in this case in the second render

6:52:32this is what you state returns therefore your counter is minus 250 react creates a new tree

6:52:38new render which shows you minus 250 here and everything else is same right so yep that's

6:52:45pretty much it that's how i think that's more than enough on what you should know about when

6:52:49you're starting your first you know introduction with react state we will be using state a lot so

6:52:56it's just getting started but yeah that's pretty much it for state in react that's how it works

6:53:08hey everyone welcome back and in this video let's just go ahead and complete our application

6:53:13which we were trying to develop which was just increasing the count of this counter

6:53:17right so what i want to do is for you to think about how i can increase the counters count by one

6:53:25because that's what we are trying to do right so if you think about it the most

6:53:30obvious thing which might occur to you is that hey let's just go ahead and let's start it with

6:53:35zero first and let's just go ahead and set it to counter plus one right because it makes sense

6:53:41i mean and in fact it also works if you just click on this button you can see

6:53:46it starts on increasing right it keeps on increasing and increasing and so on

6:53:52now this is absolutely fine to for this application and it will work just fine as well

6:53:59similarly what we can do is we can create another function

6:54:02so we can just say this as increase we can just say this as decrease

6:54:09increase like this decrease like this and in this one i would just say this has negative one

6:54:16and now we have a little application for us which increases and decreases the counter declaratively

6:54:23and the reason i just keep on saying this word declaratively is because you can clearly see

6:54:28nowhere we are mentioning that the ui should update or you know document dot

6:54:33query selector dot inner text is equal to counter plus one we are not doing

6:54:38any of that we simply say that this is a state variable to react and we control the variable

6:54:44we only control the variable we do nothing else and and that's it react handles the rest

6:54:50and if any one of you have any doubts about why don't we set like counter plus plus or anything

6:54:56like that you can clearly see that we are using const so counter is a constant you cannot do this

6:55:02and we also discussed this briefly in the last video but yeah i mean understand this carefully

6:55:08that state variables always need to be updated by their setters you cannot update them directly you

6:55:14can technically create this as a lit as well which would allow you to do this thing but react will

6:55:19not care about this expression which you wrote and this will be a bug right your ui would not update

6:55:25so just a quick help tip out there that you need to update your state variables with the setter

6:55:31defined all right once you have this application you can see it pretty much works flawlessly

6:55:38but what i also want to discuss in this video itself is that there is another way you can

6:55:43increase um or decrease or do whatever you want with the setup function now

6:55:51this will be a little hard to me for me to explain right away all the details why this works but what

6:55:57you have to understand is that the setup function also accepts a function as the value now this is

6:56:04slightly different from an integer or a string or anything like that because if i go ahead and

6:56:10set this counter for example if i set this to the string right and if i click on this you can see

6:56:16we get this random string if i set this to let's say i don't know like you know some random number

6:56:25and again when i click on this i'll get that random number but if i set this to a function

6:56:30then something special happens because react internally is configured to see that if there is

6:56:37any native boolean string object any such value like that then pretty much just set it directly

6:56:45to the variable but if there's a function supplied then do a little different things right so

6:56:52maybe if we can just figure out the algorithm of how the set counter works or you know the

6:56:57pseudo code this is probably something like this so set counter is a function we know that it has a

6:57:03value right so what react kind of does i mean of course you can consider this in a different way

6:57:10react says if type of value is a function then i want to do want to do something else

6:57:18otherwise it just basically says set counter as value right which is basically just internally

6:57:25setting the value as the same but basically just saying counter is equal to value

6:57:30and then basically re-render kind of like this so what does what happens here if this is a function

6:57:38well if value is a function this is what react would do so react would say updated value

6:57:44is value of old value and then counter is updated value and then re-render so what's happening here

6:57:55what's the difference you can see a couple of things the first thing is react will actually

6:57:59call this function which you have passed to it and the second thing is react will call this

6:58:04function with an argument which is equal to the older value awesome so in this case what we have

6:58:13is a code where i can accept an old counter value which i just told you right and whatever

6:58:21i returned from this function would be set as the new counter value that's the thing

6:58:26so if i return for example 200 what's going to happen is that it's just going to set

6:58:34this counter to 200 and i had to just do a quick refresh of the page but anyway we are back

6:58:40and you can see i returned 200 from here and if i click on this you see we set this to 200 now this

6:58:47is important because now what i can do is i can also say old counter value plus one right and if

6:58:54i click on this you can see now we are actually doing the same thing right but in a different way

6:59:03this also works fine but here we are using the older approach now you can reduce this

6:59:09a little bit using arrow functions so you can say this is basically old counter value

6:59:14as old counter value plus one something like this and an old counter value minus one

6:59:22and you're gonna see that both of these things work just like before right this

6:59:28thing is also working like before and the other one is also working like before

6:59:33so the question now is that which format should you use should you use the functional update or

6:59:38should you use the you know the value assignment thing remember for now for

6:59:45reasons which we will discuss in future when you have a little bit of advanced react knowledge

6:59:51whenever possible whenever possible use the functional updation criteria as long as the

7:00:00newer value depends on the older value so what do i mean by that in this case you can see the

7:00:06counter depends on the old value that means this is a dependency the old the new value cannot be

7:00:13computed if you don't know the older value right that's why we were using counter plus one here

7:00:17right similarly in decrease as well as long as the value depends on the newer value try to use the

7:00:25functional updation way and there is there are a bunch of good reasons for this which we will

7:00:31discuss later um but yeah this is just a general rule of thumb if your value does not depend on the

7:00:37older value at all i mean just like at wrote 200 here for example if you are doing something like

7:00:42this where it does not depend on the older value you might as well just go ahead and do it like

7:00:47this it doesn't matter right it really doesn't does not matter but yeah functional notation

7:00:54is super important if your older value depends if your newer value depends on the order value

7:01:04hey everyone welcome back and in this video i just quickly want to create a very small

7:01:09project which might help you just understand a bunch of things and react again very simple

7:01:14stuff and that will be a random quote generator right and i just want to think you to think about

7:01:21how you would create something like this so what this would involve is pretty much nothing

7:01:27it will just involve a button with you which will just say click me and it will involve an area

7:01:35it will involve an area called div where the code appears right and this quote is a random code

7:01:42so first things first we know because this code is going to change this would be this should be a

7:01:49state variable right because only state variables when those are updated then react re-renders the

7:01:55component right so we can import use state from here and that's it now what i want to do is

7:02:04i want to go ahead and create an array of quotes which include all the codes which you want right

7:02:11so something like if you are good enough never do it for free even though you're getting this react

7:02:19course probably for free right but yeah i mean the better courses and the hands-on laps would

7:02:26be paid but you get the idea then let's see what else do we have i am not afraid of a man

7:02:36who practice one cake you know something like that thousand kicks one time but rather one cake

7:02:46thousand times something like this this is this is like one of my favorite

7:02:50quotes so that could also be one then we can have something like abc because i'm

7:02:58lazy def ghi and so on but you can pretty much use an api or anything like that so what i want

7:03:06to do is first of all we can initialize this with the you know the first code if you would like but

7:03:12second thing which i want to do is i want to go ahead and let me just refresh this real quick

7:03:18i want to go ahead and create a function randomize randomize quote and call it

7:03:27just when i go ahead and click on this button right so right here now what this button would do

7:03:34is that we'll just set the state um to a new code and remember that in this case we don't have to

7:03:40depend on the previous state right so we don't need to necessarily use the functional approach

7:03:46so we need to generate a random element in this array and the way you generate a random element

7:03:51in an array in javascript is like following so you say random code is codes and then

7:03:59math dot random into quotes dot length and then you just wrap it down into math dot floor

7:04:11so just to explain you what's happening here if you haven't seen this code ever before

7:04:18this right here math.random returns us a number between 0 and 1 and it'll never

7:04:23return you one right it will always return you 0 and probably a number like 0.99999 whatever

7:04:29so it will never return you 1 that means this number will always be smaller

7:04:36than codes.length right so this means if this length is one two three four five

7:04:43this number at max could be four point nine nine nine nine nine whatever right but it is finite

7:04:50and then finally if this is always less than five or you know in this case the length of the array

7:04:57then math.floor will bring it down by one right so it will make the 4.99999 in worst case a 4.

7:05:05in any other case this will always lie between 0 and 5 exclusive of 5 and this will just flow it

7:05:12down to 0 1 2 3 4. so it pretty much depending on what map.random does you're going to select

7:05:17one out of these so it's a random code it's a truly random quote and you can just set this code

7:05:22like this now when you click on this you can see every single time randomly you get a quote

7:05:29right see up i mean you can now use your css imported css and style this a little if you want

7:05:36but that's how you pretty much create a random code generator with react

7:05:40so yep that is all for this one hopefully you are able to follow along pretty simple

7:05:44stuff nothing fancy but yeah covers a bunch of important concepts in javascript and react

7:05:56hey everyone welcome back and in this video let's just go ahead and take a look at how you

7:06:01can create a side effect when something happens now what is the side effect well in general if

7:06:08english is your first or second language you know that side effect is basically something

7:06:13that happens after you do something like maybe taking a wrong medicine or anything like that

7:06:19so similarly in react what happens as a side effect is let's say you update this variable right

7:06:26and you want a side effect to happen in your code which is you know not necessarily bad like in in

7:06:32the analogy but you get the idea so the side effect is basically something which happens

7:06:37after you have done something so what you do in order to do that in order to have that listener

7:06:43set up or a call back kind of thing set up is make use of another hook called use effect

7:06:50now what this use effect hook is is let me just go ahead and actually show you before even explaining

7:06:57this so import it just like this and use effect right here just sits as a standalone hook

7:07:03it does not return you anything it does not do anything it has two parts however the first

7:07:09argument is a function which can be anonymous functions in the most cases it's just anonymous

7:07:14and the second function is a dependency array now if i go ahead and console.log

7:07:22i was ran right or i i ran or whatever

7:07:27so what you can do is refresh this page for example and you will see the first element

7:07:34which you get is iran and that's it so what's happening here well you see use effect although i

7:07:41told you that this is a side effect but this also runs all the times after the component is mounted

7:07:48for the first time right so you see it was mounted for the first time when i increased the counter

7:07:55you know it got mounted again because we discussed how the first render and the second render works

7:08:00so this is the center second render right but we did not get iran again because we

7:08:06have no dependencies at all this function is not listening for any dependency or it's not observing

7:08:13any dependency you can see i can just keep on decreasing the counter and nothing happens here

7:08:18but pay close attention to what will happen here the moment i give this a counter

7:08:23variable as the dependency and remember this is an array right this is not a regular just a single

7:08:28value this is an array of values that means it can accept more state variables if you would like to

7:08:34so anyway now when i click on this you can see any single time this counter variable changes

7:08:42we get an iran information and if i try to console log the counter here as well you would see

7:08:49give it a refresh we start with an iran of zero which is fine i mean it makes sense

7:08:56now when i increase the counter you see we get the console log of iran of 2000

7:09:01careful on what i'm gonna say next now you can see that the second console log which we get iron

7:09:09of 2000 means that this use effect actually ran again in the second render of the function right

7:09:19so when you call the set counter and updated it to 2000 it did not run in the first vendor how do

7:09:25we know that because if it did run if it did run in the first render we would have got a zero here

7:09:32why because counter was zero in the first render right in the second render we know

7:09:37that this copy was created this copy was created again by react internally

7:09:43so this was like app and in this case this was 2000 and now we know that this returned at 2000

7:09:50and therefore this function when it ran it console log 2000 therefore we know that this function

7:09:56actually ran in the second render and not in the first render right another thing with use effect

7:10:03is that it runs after the component gets mounted or repainted so what do i mean by that this means

7:10:11in the second render this whole thing was mounted and visible on the browser

7:10:16before the console log appeared now this might be hard to actually prove or justify

7:10:20until unless we put a debugger statement or anything something like that but

7:10:25you can trust me on this one right that the use effect actually runs after the ui is mounted right

7:10:33so what's the use case of this well let's say you have a to-do list where whenever you update a list

7:10:41order you save the um order or anything on the back end right so in that case all you need to do

7:10:51is create a use effect add an order or something like that which a variable which defines the order

7:10:57of the list and then basically just write a fetch request here that whenever something changes or

7:11:04maybe like a local storage save request here you just update it automatically again this is super

7:11:11declarative why because you're telling it that this code has a dependency on this one your net

7:11:16delay you're not telling it how to execute it what should happen when should it re-render and so on

7:11:22right all of that is managed automatically um by other code on the on in your code base right so i

7:11:30hope this makes sense if it does not then don't worry yet because there's so much we need to do

7:11:36and we will do uh in order to solidify these concepts but yeah this is a start

7:11:46hey everyone welcome back and in this video and i think in this whole section of many

7:11:51section which we have we will build a to-do application from scratch using all these

7:11:57videos and by the end of this section you would probably also have a full blown lab where you

7:12:03have to create the same application pass the test as well i'm super excited to start this

7:12:08and let's just go ahead and take a look at how you can build one if you want what you can also

7:12:14do is open that lab at the end of the section in a new tab or anywhere on and start building it

7:12:21as we learn and use these videos as a you know as a unblocker if you would like to you can feel free

7:12:29to just go ahead and start building it yourself as well you pretty much know all the information

7:12:33more or less you need to know but we'll cover a bunch of concepts in these videos as well

7:12:42hey everyone welcome back and in this video let's just go ahead and start creating our

7:12:46to-do application in react how it can work so first things first what i'm gonna do is

7:12:51create a div in this application space and i'm just going to give this an h1 of best to do hap

7:13:00ever like why not all right so what we want to do is we want to do a couple of things in this app

7:13:06the first thing is this should have an input field of course this would be an input type text you can

7:13:13give it an id or a class if you want to style it with the css but i'm just going to keep it raw at

7:13:18the moment and what i want to do is also create a ul unordered kind of list which just shows us

7:13:25our tasks here whatever we enter now a couple of things here first thing is whatever i'm typing in

7:13:32this i need to have a reference i need to have a track of what i'm typing why because the moment i

7:13:38hit enter i want to take this text and append it as a task and second thing i want to just

7:13:44take care of all these to do's in in themselves right so what i'm going to do is i'm going to

7:13:50go ahead and create a state variable called to do's and set to do's and we know that these state

7:13:56variables can be pretty much anything right any sort of data type which we have in javascript so i

7:14:02can keep this as an array of to-do's right instead of just having a single string which you would

7:14:08probably need to split and do something which will also get ugly arrays is best suited for this task

7:14:15so now once we have this to do's what i want to do is i want to render this inside this ul tag

7:14:22and how do you render elements what is the standard practice how do you do that

7:14:27well what you have to remember here is that es6 array methods play a very important role when

7:14:33you are working with javascript inside of react because whatever we write is a jsx expression

7:14:40right we know we discussed in jsx that we can only write expressions which we can also pass

7:14:45in as a functional argument because technically that's what it gets compiled down to

7:14:51so what we usually do when we are writing jsx expression is we do not make use of

7:14:56for loops like this for let i is equal to 0 is less than to do start length i plus plus because

7:15:02you see we cannot really write this this sort of code right what we need to write here or what we

7:15:09can write here however is the array methods right so what we can do is i can write for example to

7:15:15do's dot map to do and then i can just return an li which has this to do so let's just take a

7:15:25look at what's happening here let me just add my name mahul and let's say john as the second name

7:15:32so what's happening here is that we took both of these elements right for each of these elements

7:15:40dot map runs this function and returns a new array right a new array of information

7:15:46so you can see i ran this and i you know just put an li around them now this thing right here is

7:15:54equivalent for me storing allies directly inside of the state this is also fine and completely

7:16:03acceptable so if i do something like this and i just go ahead and directly try to use to do's here

7:16:13those two examples are the same thing right if you write these elements directly in the state

7:16:18like this or you just map it over and then use it here both are same things because this thing

7:16:26as i said in the jsx video also gets compiled down to a javascript like representation anyway right

7:16:32so this is one on the same thing but the reason we avoid storing it in this way is because this

7:16:38gives us less flexibility i mean sure there are ways to extract out um you know this text

7:16:45from this but it's ugly right it's complicated so what we do is instead we keep it in the simplest

7:16:51data type we can which is string in our case and then we construct it on the fly what we want to do

7:16:59using functions like map or filter or anything which returns us an array right because

7:17:06jsx can display an array with you know the jsx elements right like i showed you you can have a

7:17:15couple of lis here and you can just display that array as it is right and it will run into properly

7:17:20so that's important so anyway for now i can just say this is my example and be done with it

7:17:28right so that's it now if i add another name here let's say hello for example you'll see we

7:17:34have another one so what we want to do is once we have the setup is whenever i write something

7:17:40and press enter then this should uh basically append it right here so i'm going to divide

7:17:46this task into two things first of all i'm gonna just create a button which will say create to do

7:17:51and then we will also add the enter functionality which i was talking about so with button we know

7:17:57how to access the event which is using on click so let's say this is create to do like this

7:18:04and what i do is inside of this create to do i say i want to append this to do whatever we

7:18:12have written now before we are able to do that i also need to extract out this value right and

7:18:19in javascript or in react rather i should say how you do that is you set an attribute called value

7:18:26to a state variable or to any particular value right so let's say if i set this to

7:18:32one two three four five now what will happen is that even if i try to edit this i will not be

7:18:38able to edit this input field and trust me i'm typing on my keyboard at the moment but i'm not

7:18:43able to edit this because this value attribute if set if this value attribute is not undefined

7:18:50then react will consider this as a controlled component that means this value has to change

7:18:58here itself if you need to update the ui right and because this is a string static value this will

7:19:05never happen because you know the string would not update automatically so this has to be a variable

7:19:11and the way we do this is the follows so i'm going to say this is let's say my

7:19:15task i'm going to say set task and i'm going to initialize this with an empty

7:19:20string right because that's what our value would be initially so this is my task right

7:19:26now still you would see this is not very helpful because i'm still not able to type and the reason

7:19:31for that is same because you know this task is empty string and we are not updating this

7:19:37so what we want to do in order to make sure this control component behaves properly

7:19:42is we want to say something like on change and then i want to do something here

7:19:51on change event receives an e which is just like the javascript event which we receive which we

7:19:57have also discussed in the javascript course and what this e does is that's you know e or event or

7:20:02whatever you want to name it this event contains useful information about what has happened or what

7:20:08has been entered in this text field so what i can say is i can simply say set task to event

7:20:15dot target dot value right so event.target gives us this input field and the value gives us the

7:20:21current value which is in so now if i start writing you would see that i'm able to write

7:20:26pretty much just like i would used to you know in a regular input field but the advantage here now

7:20:32is that on every single keystroke this on change runs and we always have the updated task value

7:20:39right with us and yep this is important because now i can access this task value

7:20:46directly whenever um this create to do is called so what i can do is i can just say console.log

7:20:53the task value is this task like this and if i go to browser logs for example and start typing

7:21:00and click on this button you will see i get the correct task value right here right if i update

7:21:05one two three click we get the correct task value always now it's simple right here to update this

7:21:12because all we need to do is we need to set the to-do's and append one more to do here right

7:21:20now remember what we discussed about the set state in this case the next the future state actually

7:21:27depends on the current one why because we want to append this to the existing array right so in

7:21:34this case we will use the functional updation methodology right so i would say old produce

7:21:41and what i want to do is return all my old to do's but also add my task like this

7:21:49to that right so what's happening here is that i'm just appending this particular new value to these

7:21:55old to do's right and that's how i'm doing this so if i try to go ahead and add a task one here click

7:22:03on this to do you can see we have a task one added and if i go ahead and try to add task two click

7:22:10create to do we have a dash too and pretty much you can do anything you want here and this will

7:22:14be created now it has a bunch of things we can improve and a couple of optimizations as well

7:22:25hey everyone welcome back let's just go ahead and proceed with our optimizations

7:22:30and things which you can add in the to-do application which we looked last time so

7:22:35first things first what i want to do is whenever we have this on change event fired i also want

7:22:41to probably just you know blank out the task because right now if you add it you see the

7:22:47task still remains here so that's one thing which i want to do so the way i would do that is just

7:22:53by setting the task as empty like this and here what might happen is you might think that hey

7:23:02what if this code runs before this code and then this task is old and it does not

7:23:08get appended right and you might be right right so if we go ahead and try this out

7:23:14and create a to do although this kind of works but i would say we are in a scary territory

7:23:21because it is not given that the react executes this part of the code synchronously right it might

7:23:28very well be executing it asynchronously so if i go ahead and console.log one here and if i go

7:23:34ahead and console.log 2 here and if i go ahead and write a statement and create a to do you can

7:23:42see we get two first and then one later that means react is not executing this function synchronously

7:23:48right so a safer way for updating this would be actually to set the task as empty here and then

7:23:56use the task like this right so this is what probably what is probably will stick to as well

7:24:04but yeah the moment you do that created to do it's working just fine now the second thing

7:24:11which we can do is like i said right now the enter does not work right for us now there are a couple

7:24:18of ways to fix this the first way to fix this is you actually have a key down event on this input

7:24:25field as well so you have something like on key down and you just say try to check for enter key

7:24:33something like that and the way this would work is that you would just go ahead and try to look at

7:24:40the event which you receive here so event received as this event right here now if i try to go ahead

7:24:47and type something here you can see that we have a lot of console coming in so instead of looking

7:24:54there we would probably stick to the native console right here and what i would do is write

7:25:00one two three for example and let's just ignore this exception for now because this is because of

7:25:07the web console script which is custom to go down to editor you would probably not see this

7:25:12by the time maybe you're watching this video but anyway what this even contains is you can

7:25:18see the key and the key code so if i try to hit enter here you would see the event which we get

7:25:25has a key code of 13 and a key of enter right so we could very well just use key code right here

7:25:31and i can just go ahead and say that if e dot key code is in fact 13 this means that we have got a

7:25:42enter input in this field right so you pretty much just want to run the create to do function

7:25:49because we already have done the work in that right and yep that's pretty much it

7:25:54so if i go ahead and give it a refresh for example try to enter something and hit enter

7:26:00you would see it just works just like if i enter something and click on the button

7:26:05right so this is pretty cool this is one way another way which is less javascripty

7:26:12is to actually go ahead and stick to the basics stick to the native things and what is that well

7:26:18you might have seen that in html world you already have this behavior where you enter something

7:26:25hit enter and the form gets submitted right if you go to very old sites which are just constructed

7:26:30with html you will find this behavior where you just enter something in the text box hit enter

7:26:36and the form gets submitted right the page reloads because html actually includes this functionality

7:26:43internally so how do you execute this thing you wrap the whole thing inside a form element

7:26:48and this is just html there is no javascript or there is no react part involved in this one right

7:26:56and the second thing which you do this is fine you can keep this input but the button which is the

7:27:01button which on click or you know should happen or it should be present how it should be present

7:27:07is of type summit right so this button should have a type of summit why because if this does not have

7:27:16a type of summit then this form does not know what should happen if you hit enter on an input field

7:27:23so right now what's happening is that this on click would work fine but if you hit enter you

7:27:30will see that your page reloads right so if i hit enter you see it gets entered but our

7:27:35page also reloads and why is that because that is the default behavior of forms in html right they

7:27:42just reload the page without any attributes if you don't give it a path or anything and

7:27:46even if you give it a path it'll reload it at that particular location so what we want to do

7:27:52is we want to add an event listener on this so i want to say on summit i want the create to do to

7:28:00run and right here what we will observe is that we don't no longer need the on click on this button

7:28:09and why is that because whenever you click on this button as well the create to do function fires

7:28:14right so if i write this click you can see it refreshes or if i write and hit enter it adds the

7:28:21text and it refreshes now the only thing which is left is we want to first of all remove this

7:28:28and second of all we want to just make sure that the page is not refreshed so i can also

7:28:34remove this enter key function because we no longer need that and all i need to do here is

7:28:40grab the event which react gives us on the summit and just say event dot prevent

7:28:48default now all this is going to do is say to browser that hey we don't want the default

7:28:55behavior which happens when this form is submitted that's it now if i go ahead and

7:29:00write hello and hit enter you can see it works fine world works fine one two three works fine

7:29:08works fine right i can pretty much do anything and everything i want so this is also a neat hack or a

7:29:15not exactly a hack but this is actually a standard practice which you should know about

7:29:20instead of just relying on on key down right because this is also technically speaking a bit

7:29:26performance beneficial right it's a it's performance is better than just having

7:29:33on key down on every keystroke and doing that stuff but yep that's pretty much it that's how

7:29:38you're gonna detect all of the enter and button clicks and everything and create a

7:29:43very basic to-do app in the next video we'll see how you can also remove these items right

7:29:53hey everyone welcome back and in this video what we're gonna do is go ahead

7:29:58and take a look at how you can remove these elements as well on a click or anything right

7:30:04so what i'm gonna do is i'm gonna instead of returning just an ally we could probably

7:30:08return a div or something else maybe a div insider live or allie inside div doesn't matter

7:30:15but what i'm gonna do is do a couple of things the first thing is i'm gonna go ahead and remove them

7:30:23and the second thing i'm gonna do is actually change the structure a little bit so instead of

7:30:30setting the task like this what we will do is we will add a to do as task an id and an id

7:30:38as a unique id right for example in this case it could just be a global counter or a global id

7:30:47and we can start it from zero and why am i doing this i'll let you know in a moment

7:30:52but once we do this now we have an array of objects not just an array

7:30:57of strings right so in order to render this properly what we need to do is to say to do

7:31:04or you know not to do but let's say this is item and then say item dot to do right so now

7:31:10if i go ahead and hit enter you can see it still works fine but we have done a bunch of changes

7:31:17now the second thing we can do is we can say the key of this item is in fact item dot not to do but

7:31:24item dot id right now this item dot id like we saw is a global id counter which basically is unique

7:31:35now right so we don't have to worry about just having an index pretty much like this

7:31:41so we can just have this as global id and we can just keep on working um like we used to do

7:31:49so so once we have done that what we want to do next is add a button right here which just says

7:31:55delete for example and what i want to want this button to do is whenever i click on this

7:32:02it should delete item you know somehow which we will see how we can do that so it's just an

7:32:09empty function for now which will get called but now what i can do is when i enter this

7:32:14well not at the moment but let's just see if i give this a refresh enter this you can see now we

7:32:23have a small delete button with us right so what i want to do is the moment i click on this delete

7:32:31this should just disappear from the screen this should just be deleted

7:32:35so how do i do that well in this case we need to give it a little bit of more context

7:32:41right what we should do is that we should go ahead and instead of calling it like this we should go

7:32:48ahead and call this with the id of the item so i'm gonna say delete item and i'm going to specify you

7:32:56what the id of the item is right in this case it's whatever the id is at the moment now what

7:33:04happens now is i'm receiving the item id right which we increment every single time

7:33:11so dsf dsf has an id of one maybe we can also display it just for the sake of clarity right

7:33:19at the time of frame rank so now you can see the ids of these elements as well

7:33:25which are also the keys and which are also the values which we are passing to this function

7:33:30so all i want to do now is i want to set the to-do's to certain list which does not include

7:33:36that id which i have right and again you can see the new state depends on the previous state so

7:33:43again i'm going to use the functional notation so i'm going to say set to do's old to do's

7:33:49and then what these old to do's would be is old to do's dot filter item and then item dot id is

7:33:58not equal to item id now let's see what i'm doing here first of all i'm using the functional update

7:34:04updation notation so that's what this functional call is second of all i'm trying to return an

7:34:10array here where i'm trying to filter out all the items where the id is not equal to the one which

7:34:17which has been passed right which will result in not copying the only id which i have clicked

7:34:24all right so once that has been done if you click on the delete now you can see it updates and all

7:34:31the other ids stay same so zero two three four now the reason i did not use index as the key and as

7:34:38the id and as the thing which you need to pass is should be clear now right because the index

7:34:44would change the index would become 1 2 3 again right so it is something which is not unique

7:34:52right so we broke our contract with react when we said that hey our key would be unique

7:34:57to the item which we will bind because if this was just index which we used earlier

7:35:03then this element would become index number one let's just go ahead and refresh this and

7:35:09use some real items so i'm going to write apple mango banana pizza and burger right

7:35:19now you can see all of these ids here and if i go ahead and delete banana you can say you can

7:35:24see that pizza still stays at three but if i was using index you could clearly observe that pizza

7:35:31comes at 0 1 2 so it will be 2 right so that's why i told you know let's just go ahead and

7:35:37create an id out of it and whenever possible you should use a globally you should use a

7:35:43locally unique id right not exactly globally but a locally unique id but yep this is pretty much

7:35:50it that's how you can create and add more elements and remove them as well with a click of a button

7:36:00right and yep that completes pretty much more or less your basic version of to do app i mean sure

7:36:07you can have a bunch of functionalities here where you know you have a little bit of layout as well

7:36:16and you can also store this in local storage and stuff you can do that but this is the bare bone

7:36:22structure which you require where you learn a lot of about a lot of react concepts and

7:36:27this is you know pretty much touches on a lot of important react concepts as well

7:36:32so yeah that's pretty much it for this video hopefully you were able to follow because after

7:36:38this video you will probably also have a lab where you have to create this to do application so make

7:36:43sure you do that by yourself it will reinforce all the things which you have learned here

7:36:52hey everyone welcome back and in this video we'll be learning about something known as react router

7:36:58in react and how you can work with it so you can see i have a fresh project with me here

7:37:03um with basically nothing set up apart from react itself so we can start with scratch right so

7:37:12routing is a very common practice right you can see even if you take a look at

7:37:15the url at the moment in the browser it's cooldown.com playground something

7:37:21so what this means is that i'm on a on a route which is having certain parts like the path

7:37:27is playground then inside of playground i'm inside react snowpack v3 and so on

7:37:33so you can do the similar thing in react right and there are pre-built solutions for you to handle

7:37:40that right and one of those is react router so first of all let me just go ahead and clean this

7:37:46up a little bit so it's not as scary as it looks so it's hello world for example right and let's

7:37:54just replace this and what i'm going to do is i'm going to try to set up a react router for us here

7:38:02i'm going to split my terminal and i'm going to start writing by saying um yarn add react router

7:38:11dom now remember i wrote react router dom because that's the name of the package right now what this

7:38:19package does what this package truly does is that it allows you to work with certain browser apis

7:38:26to for the lack of a better work word fake a url into believing into user believing that

7:38:34you are actually on that page and i'll tell you what what i mean by that just stick with me here

7:38:39let's first of all once this installs let's just do a hello world here right so it is

7:38:43done and what we can do now is we can import a bunch of components which allow us to do

7:38:51basically what i'm talking about so i'm going to say import from react router dom and what we need

7:39:01is a couple of things the first thing we need is a browser router the second thing which we need

7:39:07is a route right so what does this mean this means that i have a router component which is which is

7:39:17going to be a top level component which is contain all these routes which we will define right so

7:39:25the first thing i have to do is i have to define this as the top component in my app right

7:39:32now once i have defined this component as the top component in my app i have to define these

7:39:38individual routes which needs to be you know matched so what i'm going to do is i'm going

7:39:46to start with a route and end it with a route and i'm going to say the path what this path should

7:39:52be what the path should match right so this path should match let's say hello world in our case

7:40:02once i do that anything i write here inside of this would be rendered only and only if this

7:40:10matches the hello world route so let's say this is i am on route hello world right and

7:40:20just let's just go ahead and actually wrap this whole thing inside a div as well

7:40:24and i can just say right here i am just a h2 right something like this

7:40:33all right so once we do that if i give this page a refresh what you're going to see is once

7:40:41snowpack is done compiling a bit of dependencies let's see all right so it's done and we can

7:40:47see now that it just spits out i'm just finished too so if i open this in a new tab

7:40:52you can see we still get i'm just an h2 because we have defined hello world on this route so let's

7:41:00just go ahead and visit that hit enter and you can see that we get a 404 and let me tell you why

7:41:06do we get that now the reason we get a 404 when i was at hello world is because snowpack right here

7:41:15is not configured to send our index.html file which we have here on every route right so let me

7:41:24tell you what's happening here exactly when you visit a route like this or you know in general

7:41:30a home page like this what's happening is that snowpack or your backend server in this case

7:41:36which is snowpack since this index.html file right which contains certain scripts which boots

7:41:43up react which boots up this component and this component realizes what what path you are on right

7:41:51so in order for this component to run this needs this index.jsx file this index.jsx file needs this

7:41:58index.html file therefore in the first place your backend server should send this index.html file

7:42:05for pretty much everything but it does not happen in the case of front-end applications

7:42:10or you know you have to configure it somehow so in this case that's why we get a 404 error

7:42:15when we try to visit that url directly but what we can do instead is we can use another component

7:42:21here which can allow us to fake redirect or fake navigate from our application itself so what i can

7:42:28do is right here instead of you know doing i'm nh2 we can define a small navigation and it would be

7:42:37naf like this right you can also put it in div it's fine but i'm just going a little fancy so

7:42:44what you can do is you can say a link to and then hello world so it's like ahref but it's for react

7:42:52routing internal react routing and i can say go to hello world because we only have a single

7:42:59link at the moment we can also define something like link to slash and i can just say go home

7:43:08right so the moment we have something like this you can see the first thing we see is an error

7:43:13that you should not use link outside a router so let's just go ahead and fix this by bringing the

7:43:20router but actually let's just make the router the actual you know the main child of the page so once

7:43:29we have that you can see we have our links coming up and we can actually just throw in a unordered

7:43:35list here for it to just be a little bit prettier right and let's see looks like i have to configure

7:43:44prettier on this editor right it's just it's just a waste of time manually formatting all this code

7:43:50maybe we'll do that probably sometime later but now you can see that it has started looking

7:43:57just like you would want it to look like right so now if i click on go to hello world you can

7:44:03see you get i'm on the route hello world and if i open this in a new tab take a close look at what

7:44:09happens to the url up here when i click on hello world you can see the url actually in fact changes

7:44:15to i am on hello world right i'm on route hello world and if i go back to home you're going to

7:44:21see the url changes back back and forth back and forth right now if i refresh on this page

7:44:28you're going to see we get the similar error and i explained you the reason why because in

7:44:32this case when i click on this if i go to inspect into the networks tab and if i let's say remove

7:44:40this and if i refresh this one more time or you know maybe go back to the home page oops

7:44:46refresh clear this out and if i click on this go to hello world now you're going to see no network

7:44:52request has been made right you can see i'm on all there is no filter and no network request

7:44:57has been made that means react code did not go to server to check if this route existed

7:45:03or not it handled this routing internally with the help of the browser router right

7:45:10so yep that is what is happening when you refresh this it actually goes to the server right and the

7:45:15server says that hey i don't know like what this route is if somehow you were able to go ahead

7:45:22and return pretty much the same index.js file for this route as well you know this route right here

7:45:30as well you would be able to serve the you know the right code even on refreshes which is exactly

7:45:36what you want on production applications but it's fine on development if you want to skip it

7:45:41but yeah you can configure that here as well if you would like but yep that is pretty much it

7:45:47in terms of introduction to the browser router and how you configure it we will pretty much

7:45:51take a look at a bunch of other things in the upcoming videos but yeah that's a solid start

7:46:02hey everyone welcome back and in this video let's just quickly go over and take a look at

7:46:07an exact route match what does that mean

7:46:10so let's say i define a route which is our home page and i just say

7:46:18i am on home page right and if i go ahead and refresh this tab right here

7:46:26what you will be able to see is that we get i am on home page which absolutely is fine but if

7:46:32i go to the hello world route you can see that i get i am on route hello world but i also get

7:46:38i am on home page now why is that well this is because by default the behavior of these routes

7:46:47is to match the route first as a path and then pretty much anything after that as well so do

7:46:54i mean by that it means if you're on home page basically what's happening is that you are pretty

7:47:02much routing the router matches the slash which is at the end of the url but anything after the

7:47:09slash also matches right so this route here would also return you i am home page if you visit this

7:47:15with a link right so it i can just go ahead and for example create a go to

7:47:20go to random link and i can just say this is some weird route and if i refresh this

7:47:26again and if i click on that random link you can see i still get i'm on home page why because it

7:47:32matches anything after this slash which is pretty much anything similarly this route would appear

7:47:39every time i have i'm on hello world or i'm on pretty much any other route as well so i can copy

7:47:46this actually revert back and change this to this and if i refresh this click on the link you would

7:47:55actually see that i still get i'm on hello world even though i'm on some weird route now to order

7:48:01to fix this problem all you have to do is always and always it's a good practice set this exact

7:48:10um attribute on your route component and this basically just means exact true right in jsx

7:48:17you can just omit the the true bit if you like it's just a style so even if you just write exact

7:48:24like this it just means exactly said to true right and the moment you do that you're gonna see that

7:48:31now it's actually much stricter now if i click on the hello world you can see we no longer get i'm

7:48:38on home page i get it here but i don't get it here right and on the random link you can see we pretty

7:48:45much get nothing so this has solved our problems which is you know the weird behavior which we were

7:48:52getting with the routes so this is something more or less what i feel is a common practice

7:48:57which you should anyway do right whenever you're defining routes just put an exact keyword because

7:49:02in most of the cases it will do what you expect it to do right instead of having these edge cases

7:49:13hey everyone welcome back and in this video we're going to be taking a look at dynamic routes in

7:49:19react which is also pretty helpful especially in case when you're building dynamic apps which you

7:49:24probably will be when you're working with react so let's say you are building a social media app

7:49:29or whatever and you go ahead and you want to have a route which basically catches everything after

7:49:36user right so it could be a username mayhole or any other name which you want to capture

7:49:43now if you think about it if you remove the exact keyword that would kind of

7:49:48fill our purpose but this is a bad hack right because now you're not only just catching me

7:49:54but you're also catching me who'll slash this or slash this or slash this right so this is clearly

7:49:59not a solution so we do need exact but what we can do is we can define a dynamic route or a dynamic

7:50:08piece of the path here and the way we do that is we put a column and we write the variable

7:50:14name which we want it to be called right in our case let's just say we just say username

7:50:20as the variable name right and what do i mean by variable name we'll see

7:50:25but what this means is i can just go ahead now and i can just say i want to render a

7:50:30custom user component with me right i can just go ahead and create this function user component and

7:50:37probably in a separate file yeah let's just go ahead and create it on a separate file user.jsx

7:50:44function user like this we can just import react real quick and once we do that we can just say

7:50:53i am a user component right and don't forget to export this and once you do

7:51:01that you will be able to see that if i refresh it let's see but i haven't imported it yet yep

7:51:10also need to import user component from user.jsx right so the moment i do that you're gonna see

7:51:20that if you just go ahead and create a bunch of links here let's say profile one

7:51:27which is user slash mayhew right let's just create this link a couple of times five two three

7:51:39four right mayweather xyz go damn playground whatever right so we have four profile lengths

7:51:49and now whenever i click on one of them you can see we get i am a user component right that is

7:51:56fine i mean that's great progress but how do i capture this part right on which path i am on that

7:52:04is what this variable name is and that is what it could help you with now in order to capture this

7:52:09what you have to do is you have to use a custom hook in react router right and the way you do that

7:52:17is you call this hook but you know what this hook is called rather i should say is use patterns

7:52:26right from react router dom and actually i'm in the wrong file this should be

7:52:33user.jsx so import this and i just go ahead and call this right here now what this use

7:52:41param hook returns this returns us an object of all the all the parameters which we supplied

7:52:49right so if i go ahead and take a look here you can see we only have a username as the variable

7:52:54so this will return us an object the username being the value of the path right

7:53:01so i can say this is username i destructured restructure it like this and i just say the

7:53:07user is something like this right so you can see now i'm on the user component playground

7:53:13if i click on profile three i'm on code damn xyz and mayhol right so this helps us to pretty much

7:53:22set some context right and now you can use this username component for example and use effect

7:53:29or you know react query if you're using the act query for performing fetch request

7:53:34fit some data with user name variable right like their account details or anything and pretty much

7:53:41just use it um to display some dynamic data right here right so that is how it works that is how

7:53:49the routing part works right maybe it's a public profile or anything and that's how you can do that

7:53:55but yeah that's the basic of it how you would grab a dynamic path

7:53:59how you would render a component and how you would use hooks to grab out that information right

7:54:11hey everyone welcome back and in this video i want to go ahead and show you how you can use

7:54:18fetch request to fetch basic data in react.js and mind you that we will be learning about

7:54:24react query in a different course which is an actual library just like we use a react router dom

7:54:30for performing routing we will be using react query for performing all these fetch requests

7:54:36but react query is a big library in itself right so we have a dedicated course on that

7:54:41don't worry that is included in this learning path which you're part of

7:54:45so it's fine you would be able to access it once you complete the react course

7:54:49but anyway just to give you an idea of how you can do it right away even without react query library

7:54:55i gave you a little bit of idea how this would work in the last video when we closed it but

7:55:00let's just take a look at that formally so what i'm going to do is i'm going to go ahead and

7:55:05right here i'm going to create a file inside of this public folder called users.json right and

7:55:11this is just a static file which i'll just make it myself and i'm going to say something like

7:55:19mehul has name mehul and age 22 right pretty much similar things for john and let's say for goddamn

7:55:38as well so we can just change the name of them as you know john as john and this could be 40 right

7:55:48anything so what this does is that this allows us to have a static file in place which we can fetch

7:55:55because remember all the assets in this public folder are available um on the on the main domain

7:56:02so if i go ahead and write users.json right here you're gonna see that we get this user.json file

7:56:07which is pretty awesome right so what we will do is we'll dynamically fetch this and we will

7:56:13try to render the content from it so i'm going to say fetch what do i want to fetch users.json

7:56:21and then when i fetch the data i want to set this data to let's say a state variable uh user data

7:56:31set user data which is pretty much use state of empty object at the moment right and we can just

7:56:38import use date as well so once i fetch this what i want to do with data is i want to get the data

7:56:46of uh username right which is which is what our parameter is and i want to set

7:56:52user data set user data to that right and finally what we can do is we can have a

7:57:01provision where we are trying to do something like um paragraph i just say name is userdata.name

7:57:15right and um the h basically which we also used is userdata.h

7:57:23right so you can see right now we don't get anything because we are not on uh we are on code

7:57:29damn right but if i just give a refresh for this use effect to run and if i visit the profile one

7:57:35you can see i'm a user component which oh because we are doing it the wrong way here it has to be

7:57:42past our json first and then we can use the data right that's a that's a fault but yeah

7:57:52the moment we do that you can see now it for me whole it starts rendering the correct value

7:57:57if i visit xyz it does not render anything for xyz but can you guess why that happens

7:58:02well that happens is because this function does not run once the username changes and a quick fix

7:58:07for this is you just add username as a dependency to this one right now if i click on mehul

7:58:14we get the name now if i click on profile 3 we get the updated data again playground well we don't

7:58:20get it because we don't have that we have john instead so let's just replace it with playground

7:58:26and give it a refresh and let's see if i click on this now you can see we get john now

7:58:33right so we don't have data for xyz that's why but yep that is how in a in a bad way kind of

7:58:42you can perform a fetch request i know that this can be improved a lot we are just using a

7:58:47single file so we don't need to perform multiple fetch requests again and again but think about

7:58:52this in the following way let's say if you had mayhold.json and playground.json and all those

7:58:57files there then you would have to perform these all these multiple fetch requests but yep this

7:59:02is how you would perform a fetch request inside of react store it in state variables and render

7:59:07the data after that we will take a look at a much better way of handling network request

7:59:12in the react query course which is part of this learning path so don't worry about that anyway

7:59:17but yeah that's pretty much it for this one i'm gonna see you in the next one really soon

Tailwind CSS Fundamentals

7:59:27things which i want to discuss in this video is just the basics of what we are doing in

7:59:32this course what tailwind is what we will be doing and how you can practice using code

7:59:37dam's playground interface so tailwind is an interesting framework for css which allows you

7:59:45to pack your ui and your styling of the ui into the html itself right so the traditional way of

7:59:54working with css is something like you give it a class of hello let's say and then you go to your

8:00:02css file let's say you create one oops style.css you create a file and then you say hello and then

8:00:11you give it a background of yellow something like that you go back to the html you link the css

8:00:19like link let's see link real style sheet href style.css and then your styles automatically

8:00:34start reflecting once you put in some content over here as you can see so this way is fine but what

8:00:45tailwind allows you to do is that it restricts your ability in a way to use certain number of

8:00:52styles only now what do i mean by that and this is also not fully true statement but let's say

8:00:58i wanted to create a nice looking button over here which says something like click me now i

8:01:05could have any amount of pixel padding here which is like if i say display inline block i could have

8:01:12any amount of pixel padding for example padding 5 pixel right i could have any amount of margin

8:01:20margin 2 pixel or 20 pixel i could have any sort of color in the whole spectrum of colors of rgb

8:01:29and you know web supported colors which is to be honest you know a huge choice to pick from

8:01:35and i could have any text color now in theory this sounds awesome and this sounds wonderful

8:01:42but in practice when you're doing styling like this it becomes very very tiresome to actually

8:01:51build a a ui system yourself where the margins are pretty much you know standardized the paddings are

8:01:59standardized the colors are standardized the color palette is there and so on so more than anything

8:02:05tailwind does two things for me which i personally like a lot about and you if you go to the source

8:02:10code of goddamn you will pretty much see tailwind being used all the way you know this page is

8:02:17not rendered on server side but if you go to a page like this you're gonna see on code down

8:02:23we pretty much use tailwind in a lot of places flex px2 you can see it still went all the way

8:02:31right so one of the things which i like a lot about tailwind are these two things the most

8:02:35important things the first is that you can cut this ui and paste it in some other project which

8:02:41is also using tailwind or some other page which has tailwind enabled and you don't have to like

8:02:47include style sheets and everything over there because this is like a complete widget in itself

8:02:52and second of all it binds you in certain best practices with css itself that is what

8:02:59should your margin values ideally be what are your colors which you should be using in your

8:03:04project or which you should be using in your site and so on so these abstractions and these

8:03:10value binding plus the ability to get out of these bindings that is also tailwind

8:03:15provides so that's completely fine this is super important stuff and super awesome of tailwind as

8:03:21a framework because i am not a ui person i don't like to work with uis as a developer

8:03:26i can rely on tailwinds measurements and units and you know ability to create nice uis so this is why

8:03:34i believe tailbone is an important library for you to learn only if you like it um because it

8:03:40will boost your productivity a lot that is all for this video in the next one in the next interactive

8:03:46videos and labs which we have in this course we're going to be discussing a lot of new features of

8:03:50tailwind 3 as well as you know the fundamentals of core understanding of tailwind as well

8:04:01hey everyone welcome back and in this video we'll be discussing about how you can get started with

8:04:06tailwind css and this course in general would also be divided into two parts the first part

8:04:12is where we are actually learning about tailwind in html world and the second part will be where we

8:04:17will look at look at the tailwind configuration and we'll also tap into react in that you know

8:04:24section or in that particular video so right now i'm gonna stick with the basic html css

8:04:29javascript playground which we have just to keep things simple i'm gonna include a tailwind css

8:04:36jit compiler which i'll tell you in a moment what that is and we're going to be learning all

8:04:41about tailwind using this interface right and then further down the line in the course we'll actually

8:04:46see how to use stalemate properly with react because react is the technology

8:04:51which we are learning inside of this full stack or front end or whatever learning path you

8:04:56are in enrolled right now so let's go ahead and take a look at how the new tailwind css

8:05:02you can use in your basic html project so in order to do that what you have to do is this all

8:05:09the stuff we'll do when we are working with react but for now we're gonna be going all the way down

8:05:16and i'm gonna be going to this place cdn link i'm gonna be adding this script tag called

8:05:23this script src cdn.tailwindcss.com right and i'm just going to make some space over here

8:05:30and also remove the style sheet because we are not going to need that and let's just get rid

8:05:35of these few meta tags as well because we don't we are not like shipping any website or anything

8:05:41so there we are now tailwind is pretty much available to us right away what this script

8:05:47tag does is if you open this you're gonna see that it redirects you to cdn.tailwindcss.com3

8:05:55now you might be thinking that if tailwind comes with all the pre-built classes and

8:06:00you know the things which i mentioned all the

8:06:03restrictions then why is it loading a javascript bundle instead of css well up till tailwind 2

8:06:12there was nothing known as jit compiler and what a jet compiler is it stands for just in

8:06:22time compiler this just in time means that tailwind is actually generating your styles

8:06:30just in time that means as you are writing it tailwind is generating those styles in memory now

8:06:38this is important because with css obviously even if you restrict it i mean even if i restrict it to

8:06:4510 margin classes let's say if i have margin 1 to margin 10 right and then if i have something like

8:06:52padding 1 to padding 10 so you can see over right here i have padding at x axis padding at y-axis i

8:07:01would have padding at you know maybe both axes and so on so this would pretty much start to get a lot

8:07:08heavy very soon and this is one of the problems which tailwind two faced as well which led to the

8:07:15just-in-time compiler mode that is the bundle size of tailwind in the developer environment

8:07:22was so huge was probably in megabytes that it was no longer a viable option

8:07:28to you know just keep on loading the whole bundle every single whole css bundle every single time

8:07:35i mean in some cases it was also approaching the browser limits of how much css the browser can

8:07:40handle so something else needed to be done so what the smart people at tailwind did is they come up

8:07:46with a just-in-time compiler which pretty much allows you to write all the css which you want

8:07:53of tailwind but it will parse that on the runtime and it will just create styles for those

8:08:01particular classes which you are using instead of just loading all the bundles so this is why this

8:08:06is a script tag and not a js and not a css bundle okay so how do we verify if this is working or not

8:08:14so let's verify it with a very simple let's say h1 tag i'm going to say my name is

8:08:21mehul and you are watching this on go damn or rather i should say watching plus practicing

8:08:28right because you know why so if i go ahead and give it a class of bg gray 800 you're going to

8:08:39see something nice happened automatically the background is very dark and it is a shade of a

8:08:45gray but the text is not visible so i'm going to give it a text of white as well so you see

8:08:51it's almost like intuitive if you read it it says like background gray of 800 800 is the intensity

8:08:59of the color so if you can guess a less intense color would probably be like something like 400

8:09:05or 300 what you have to realize is that when we talk about intensity of the stuff and tailwind

8:09:13it's always in the multiple of 100 except for 50. so there is a shade available of bg gray 50 which

8:09:21is a very very light gray i'm not even sure if that is visible in the video but if it is i mean

8:09:27i'm saying the truth there is a color of bgg50 there would not be a color of bgk 49 or anything

8:09:34this will just probably not render anything at all because you know it's just css not found

8:09:40but 50 is there 100 is there then 200 is there 300 is there and so on so as you move above this

8:09:49color gets better a bit stronger and stronger right so it just keeps getting stronger at a

8:09:54point because you have text white over here it's advisable to give it something like 700 or 800

8:10:01right so these are the classes and the the good thing about this is if i give it a padding of

8:10:07let's say two and i'm going to come to these units as well and margin of let's say four

8:10:13now the block which we have created over here and let's say if i also give it a shadow

8:10:18and bear with me over here it'll just become a little bit easier in no time

8:10:23now the good thing about this h1 tag or a nice thing about this h1 tag is that this tag

8:10:30would always render this particular layout and all i have to do is cut and paste this in any place in

8:10:36any environment where tailwind is running right so this is the awesome thing about tailwind that

8:10:42you pretty much have uh you know an independence from importing all the css styles and stuff like

8:10:50that so this is one one of the aspects which i like a lot so yep let's keep this video to

8:10:55this because we have done enough we have imported tailwind's jit compiler we have understood widget

8:11:01is needed we have done a bit of hello world kind of stuff with tailwind as well and we have done

8:11:09the hello world thing so yeah that's that's the most important part of starting something new

8:11:18hey everyone welcome back and in this video let's just go ahead and try to understand what exactly

8:11:24is this two and four and all this stuff which is going on i'm gonna head back to the tailwind

8:11:29documentation and this is like one one place where you should be spending a lot of time

8:11:34as a developer uh not just in tailwind rather i think in pretty much anything which is like the

8:11:40official docs and especially with a library like tailwind which has a very nice interface and a

8:11:46lot of things documented it's always a good idea but anyway if we go to something like let's see

8:11:52if we search for padding over here you're gonna see we have all these units over here

8:12:00now you can see that tailwind has does not has a continuous limit a continuous euro as in you

8:12:09can create a 0.75 ram in tailwind utility but you cannot create a 0.76 ramp right so when i say that

8:12:19tailwind restricts you in a way where it would not give you pretty much all the things to do

8:12:24this is what i mean right you cannot just blow up your design by having a left and right with a

8:12:30padding of 0.75 and then top and bottom of a weird 0.76 you know something like that which does not

8:12:38seem normal but you can see all of these units these these are like class names on the left all

8:12:44of these class names actually have a corresponding ram unit not a pixel one there were a couple of

8:12:50pixel units at the top if you took a look that is padding right pixel padding top pixel padding

8:12:58y pixel and so on but all the other things are not in pixel similarly for margin you will find

8:13:06similar units and you know for space between and all the other utilities which involve any sort of

8:13:12padding or margin or any sort of unit you're going to see that they do not include pixel instead

8:13:18they include them now there's an important reason for that let's say if i start with

8:13:23this example itself if you if i want if i tell you to read this example how would you read it

8:13:28background of gray text of white padding of 2 this means padding 2 pretty much everywhere on the side

8:13:36let's say if i wanted to have a padding of 10 only on the x-axis and nothing on the y-axis

8:13:41you can see it reflects and then on the y-axis let's say if i wanted to have a 24 which is like

8:13:46a huge padding but sometimes you will see that 25 would not work right why because 25 is not a class

8:13:54so for that you would have to check either in the documentation or if you are working locally on vs

8:13:59code your ide should also give you hints we are in the process of adding the autocompletion and ide

8:14:06part of tailwind in the playground so if for some reason you think that your style is not working

8:14:12make sure to double check whether that style even exists in tailwind or not

8:14:16so you can see over here after 24 you're gonna see there's a direct jump to 28

8:14:22right so the values are also continuous initially one two three four and then they also have gaps

8:14:29right so this is something you have to remember when you're using tail weight

8:14:33that sometimes if the glass is not reflecting it is possible that you have written the wrong style

8:14:37so i'm gonna go back to 24 and you can see we have a nice little tip and this margin over here also

8:14:44follows the similar format of margin x and then margin y of let's say 10 and you're gonna see it

8:14:52gives me 10 units of margin on the y part and four units of margin on the x part that is the x axis

8:14:59or if i have a similar value i could just drop x and y and directly use this all right that

8:15:04is fine but the question still remains why do we have rams in tailwind and not pixel

8:15:13now the reason for this is because rams are more customizable than pixel one ram essentially one

8:15:22unit over here if this is one then that is 16 pixels by default in pretty much every screen

8:15:31so you see when you have a padding of one rim you actually are doing 16 pixels of padding

8:15:37so if i go ahead and actually take a look at this h1 over here and if i shift to computed

8:15:44which actually shows us what the real css is being applied real real css right not the

8:15:50fancy stuff which tailbone is doing this is the real css which is being applied to the element

8:15:56you can see we gave it a padding x of 10 which means padding left and right of 10 units 10 units

8:16:02according to the documentation over here means that the padding is 2.5 frames and 2.5 frames

8:16:12should technically be equal to 40 pixels of padding if i go back and if i check out padding

8:16:18left and right you can see it's 40 pixel it's in the computer tab that means this is what is

8:16:24being applied now here's the fun part with rams the fun part is if i go to the html tag at top

8:16:32and if i change the font size of html tag from 16 pixel to let's say 18 pixel you can see

8:16:41every single thing every single thing on the page which was using a ramp automatically got adjusted

8:16:46if i go back to this computer you're gonna see the padding left and right became 14 pixel

8:16:52why because the calculation now is not happening on 16 it's happening on 18 which is the base size

8:17:00of the page now let me tell you that most most most systems always have 16 pixels as the default

8:17:08value so you don't have to worry about it but you remember or if you have ever seen that you can go

8:17:13to the browser settings and you know toggle that area where it says you know i don't uh i'm not

8:17:21able to read uh you know font at 16 pixels so let me just increase it a little bit so you have those

8:17:27sliders for people who want to see things a little bit bigger on their phones or on their screens

8:17:33that is where the browser would start injecting this particular thing and this is you know if

8:17:40for example somebody wants to have a 24 pixel kind of thing it'll automatically adjust according

8:17:46to their preference in their you know whatever setting they have chosen again let me remind you

8:17:51that like probably 95 percent of the world does not keep it at 24 they will keep it at 16 only

8:17:58but for some people who want to do that still your website would look awesome

8:18:03on the other hand if you were using pixels then you know padding or not font size actually

8:18:09if you were using padding of adding left and right

8:18:17of 16 and padding right of 16 as well this would actually not reflect properly

8:18:24right this will actually break in a way where you know it'll it'll

8:18:31uh i think in this case it would not really matter as much because h1 is a block element but still in

8:18:38case of margin you will see the difference but if i change this margin left and right

8:18:44two different values you're going to see that the margin and padding everything would remain

8:18:48same and your site would not scale properly so this is why tailwind uses ram as a choice

8:18:55and this is why you don't really have to worry a lot about the ram and pixel and to be honest

8:19:00i did this video i wanted to convey this concept because sometimes you might be confused what is

8:19:06the significance of this unit and everything so the significance of this unit in itself is that

8:19:13four of these units is actually one ram right so it's four is one ramp so it's basically

8:19:20like saying every one increment is an increase of 0.25 frame which in itself is something like 0.25

8:19:31times 16 which is 4 pixels right so kind of if you want to think about this in an intuitive

8:19:38way when you go from one to two you're actually increasing four pixels then three

8:19:42four pixels then four four pixels and so on right if you wanted to think about that in that way

8:19:53hey everyone welcome back and in this video before we get into all the tailwind css styling

8:19:59and shadows and this and that what i want to discuss about is a fundamental way tailwind

8:20:04works with responsive design and with devices of different words and that is using these classes

8:20:11now in tailwind what you have to understand is that a lot of metadata to the existing classes

8:20:18is attached using column right so let's take a look at these set of classes this set of class say

8:20:27that smd large extra large and two times extra large have these particular break points as the

8:20:35you know a minimum width which is important and what this means is that if i am in this in this

8:20:41particular class and if i say that hey this sm should be bg grade 700 which means anything above

8:20:51640 pixel should have this style applied right if the screen size is above 640 pixels then only the

8:20:58style should be applied and this could be visually seen as i drag this and if i make this above 640

8:21:04you can see the moment my screen goes above 640 pixel we get the gray and the moment it goes down

8:21:10640 pixel we pretty much lose the gray because it is lost right i mean this becomes white if i give

8:21:17this a background of let's say vg yellow 900 like this you can see this is yellow right now

8:21:25as as long as it is you know under 640 pixel width and the moment i cross that you can see

8:21:32it becomes grey now this is like a media query and this is in fact the media query

8:21:37under the hood which says that anything which is minimum width of 640 should have this that

8:21:44this particular style right and in this case it doesn't matter the order in which you put you can

8:21:50put it above as well because media queries have a higher specificity than a single style so you can

8:21:56see this would still work but this is important because using these selectors using these sm

8:22:04md lg xl2xl you can customize the behavior of your website right so you don't have to write explicit

8:22:11media queries in css you can just write it write the behavior over here and be done with it

8:22:17for example one quick example i can also show you is something like sm and then you can say

8:22:23text to excel right so you can see that if i increase the size of this div the text

8:22:30automatically increases because the text is set to 2xl if i change this to 4xl for example you're

8:22:35going to see it becomes much larger the moment we cross that small boundary right so you can

8:22:41see you can play around with a lot of styles in tailwind using these selectors and the good thing

8:22:47about them is that there is no limit pretty much to whatever you enter here so for example if you

8:22:54enter a background as a normal class you can also enter that as a background in sm or md

8:23:02or excel or extra large or anything right so you can pretty much apply all the styles

8:23:08whatever you want with these responsive selectors and as well and that will just

8:23:13work out of the box and this is like most most common with layouts and sometimes with font sizes

8:23:20as well and you know with paddings as well a lot of times less common with colors and stuff because

8:23:25ideally you would not switch colors based on the layout but yeah i mean that's something you can do

8:23:35hey everyone welcome back and in this video let's just go ahead and take out some time to discuss

8:23:40about all the colors which are available in tailwind and how you can set them as background

8:23:45or text colors right so i'm gonna get rid of the responsive styles for now so that we can focus

8:23:50more on the colors part so if i go ahead and take a look at this colors section in the let's see

8:24:01there should be a dedicated section for colors i think inside theme inside colors there we go so

8:24:08you can see that tailwind by default and because we are using jet we get this complete color

8:24:16palette right out of the box right so you can see we have slate color we have grazing neutral

8:24:22all these colors and we have like i mentioned earlier in the i think in the introduction video

8:24:28we have very light shade in terms of 50 then after that it just increments from 100 in terms of 100

8:24:36right 100 200 300 all the way up to 900 900 so one of the best things about tailwind is that it

8:24:43also gives you a nice color palette which which are carefully chosen colors with nice you know

8:24:51color theme and nice background contrast with the text colors as well

8:24:57obviously you can add custom colors we're going to learn about tailwind configuration later down

8:25:02the line but for now what the way this works is that you pick up whatever the color you want

8:25:08for example in this case let's pick up this keyword which i don't know how to pronounce

8:25:13but looks awesome so i'm gonna paste this over here lowercase and i'm gonna add an intensity

8:25:19of that particular color right in this case i just chose 900 you could have pretty much chosen

8:25:25800 700 and it will work out of the box similarly for text you can see that white works out of the

8:25:32box because tailwind just provides that although you can see that white isn't like really written

8:25:37anywhere but that still works but in general you can play with the gray or the slate variants as

8:25:43well text gray wouldn't work what you have to do is text gray and then an intensity of that as well

8:25:50in this case this is just just a little bit gray so that's why it appears almost like white this

8:25:56is like even more closer to white but this over here is pretty much a solid dark gray

8:26:02right so you can play with these colors um in terms of background and text colors you can

8:26:08also give background gradients as a color which is like a really cool and interesting thing you

8:26:13can do with tailwind although i would admit it's not like completely customizable and controllable

8:26:19if you want anything which is more customizable you would have to go into css files but here's

8:26:25how the background gradient part works so for the gradient color what we can do is say vg gradient

8:26:32to right which means it should start the gradient from left and to right and that is also clear in

8:26:38what we're about to write and then you have to say from the color and the intensity whatever you know

8:26:45whatever that color is so you can see that already the gradient is working just fine it fades into

8:26:51the transparent color but that's usually not what we want if we are creating a gradient it should

8:26:57probably go all the way so i can say something like 2 blue 600 right so blue and

8:27:04sienna's basically you know a little bit on the similar sites it forms a nice gradient over here

8:27:11similarly you can have gradients not only just between different colors but between

8:27:17same colors as well so if you do something like this this also creates a gradient in terms of just

8:27:22increasing the intensity so that is also awesome and what you can do i mean this is pretty much all

8:27:28you can get in terms of the gradient stops this is like a 50 percent kind of 50 percent in between

8:27:35transition you can also specify via and then see on let's say 400 so what you have the option

8:27:44over here in terms of customizing the gradient is specifying either two stops or three stops and the

8:27:51colors which is from the tailwind color palette right so this is pretty much it in terms of

8:27:57what you can achieve with gradients which is also pretty awesome right if you just want to create a

8:28:02nice looking gradient in fact if you go to core dam's website you're going to see at home page

8:28:07this gradient this is actually a gradient which we have in the background right this particular thing

8:28:18hey everyone welcome back and in this video let's look at hover classes in tailwind as well because

8:28:25over is also one of uh you know a common action especially on desktops where you have a mouse

8:28:31pointer so tailwind makes it easier to customize your styles based on hovering as well so instead

8:28:38of writing css for this we have inbuilt support for tailwind and just like you would

8:28:44do it with a responsive breakdown you would do the similar thing in tailwind with a hover and then

8:28:50a column and then whatever style you write over here would reflect whenever you are hovering so

8:28:55if i have text gray 900 and a bg over remember that you have to write over multiple times

8:29:03bg gray 200 if i do something like this then when i hover over this you can see the text turns

8:29:11the text turns grey but the background does not turn gray because you can see we have a gradient

8:29:16so that might be taking a bit of more specificity so i can

8:29:20probably give it vgc 900 something like that so now if i hover over this you can see the

8:29:26text turns black and the background turns gray right so this is how you would work with hover

8:29:33in general nothing fancy nothing complicated you just specify the styles which you want

8:29:39and they will start working the moment you pretty much hover on any other element

8:29:49hey everyone welcome back and in this video we'll be discussing about how to build

8:29:54flexbox layouts in tailwind and this goes without saying that we would not be discussing

8:30:00flexbox in general but only about using flexbox because we have already done that in the css

8:30:05course so if you're not following the full stack or the front-end loading path on code amp it is

8:30:10high time that you do because that is a path that is a structure in which you

8:30:15will be following you know or becoming a whole stack or a front end developer

8:30:20but anyway let's start with the flex box in css and just like other classes it's pretty

8:30:26simple to use flexbox with tailwind because they provide out-of-the-box classes and out-of-the-box

8:30:31utilities for most common things let's just go ahead and start developing a very simple layout

8:30:37so i'm going to say something like let's say this is a div and i have another

8:30:44three divs inside this right what i can do is at the same time i can give them all a width or

8:30:50let's say a height of 10 something like that with a background color of gray 800 this could be blue

8:30:59this could be red something like that right and on the top i could start giving this

8:31:06some flex input right so right away you can see that the moment i give it flex everything

8:31:14just disappears because these do not have weights with them now with flakes what happens

8:31:20is that if i go ahead and let me just refresh this if i go ahead and open this you're gonna

8:31:25see that this flex class actually just says display flakes and nothing more so what we want

8:31:31is that every single one of them to be equal width by saying flex one now what does this mean in real

8:31:38world css is if you go ahead and take a look at flex one it gives you a flex grow flex string

8:31:45and flicks basis of zero so just a quick revision with flexbox flex growth one and flex shrink one

8:31:51means that you know you should try to take as much space as you can and flex basis is basically you

8:31:58know a kind of like a width equivalent in flexbox and giving it a zero percent just means that you

8:32:03fall back to flex grow and shrink so this gives you a nice little layout you can see i can also

8:32:09go ahead and increase this let's say a little bit only if this is available yep or maybe we can

8:32:17use the highest one which i think is 96 and you can see now that we have a nice little layout

8:32:23now a nice thing which we can do in order to combine this with a responsive base layout

8:32:29is i can say that hey whenever this is by default this is flicks column

8:32:35but nope not flex column actually flex row that is the default flex behavior but whenever i am on the

8:32:46on a larger screen for anything which is smaller it should be flex call and in this case you can

8:32:53see because we don't have a definitive width i can also go ahead and do something like

8:32:59on you know sm this is flex 1 but otherwise it just takes the full width as a block element

8:33:06all right so what's happening over here you can see the moment i cross that small barrier

8:33:13the moment across that all of them get this class removed or not exactly removed but the effect of

8:33:19this class gone so this is why you get a flicks call i mean this is basically you know in a in a

8:33:26stack in a vertical stack the moment we grow over this this class takes over and then this renders

8:33:34in a row right so if you know how flexbox operates you know this would be useful for triggering

8:33:40uh mobile based layouts right whenever size goes below 640 pixels so yep this is like

8:33:47pretty much how you can work with flexbox there are a bunch of utilities flex nand flex auto

8:33:53flex one on over you can also kind of like modify the style and the and the

8:33:59you know a bit of functionality but for the most part you probably would see yourself working with

8:34:07this flex property flex call flex row property and the modifiers associated with them flex one

8:34:14something like you know you can also do something like if we go to this area and get rid of

8:34:22this then i can say something like flex grow and then i can say to this for example something like

8:34:30width 24 and then this could be width 24 as well right so now you can see that this one

8:34:38takes all the available width and these ones are 24 units of width in this case right so you can

8:34:46play around with this and it's easy to build such layouts you can see this works just fine but yeah

8:34:52that's pretty much it how you can get started with flexbox and with flex in general with tailwind all

8:34:58you have to do is understand which class is doing what sort of trigger so flex triggers display flex

8:35:04flex calls trigger the direction then with responsiveness combined you can change the

8:35:09direction then flick scroll flex shrink flex 1 all sorts of things can help you trigger

8:35:16various kinds of layout in your file without even changing any sort of external css or anything

8:35:28hey everyone welcome back and in this video let's just go ahead and take a look at

8:35:33grid as well with tailwind how you can work with grids and grid is also a great way to build uis

8:35:39especially two dimensional uis where you want you know a lot of customization and control over

8:35:45a grid sort of formation instead of just the flex box which allows you to either work horizontally

8:35:50or vertically so in this case we're going to start off with a very simple example

8:35:54where we could probably create something like this only so i'm going to start off

8:35:58with the same thing but let's say if i give this each of them a dimension of 20

8:36:0520 as well get rid of effects growing so we can go ahead and do something like this

8:36:13and over here instead of flicks i'm going to change this to grid this allows us to use all the

8:36:20properties which we have right so in this case you can see i can use grid columns four which means

8:36:26that this should be organized in columns of four so if we have like a bunch of more such elements

8:36:35right i can say grid calls four or three in this case and you can see

8:36:41they equally line up in three different grids right and i could just probably say this as

8:36:50w full instead of restricting the width and you're going to see that it combines them of course this

8:36:56is not visible right now so what we can say is gap of one which is like a grid property which allows

8:37:03you to give a little bit of gap between all these elements similarly you can play around with other

8:37:10properties of column start template start row start and row end so for example in case of call

8:37:16start or call span i can go to a particular grid and give it a property of let's say

8:37:25this one right here has called span of two and get rid of this one over here so you can see

8:37:32that the second one now spans two columns so you can play around with more properties of

8:37:37grid by looking at the documentation and whatever your layouts demand you to do but it's basically

8:37:43css right you can see the equivalent css as well over here sometimes the css might be a little bit

8:37:50more complex in a way because stalemate might be using variables and all sorts of stuff in the css

8:37:56but if you understand the premise of what tailwind is doing it's easier to

8:38:00build complex layouts over here as well you see it has pretty much support for all the

8:38:07grid properties which we have learned in the css module in the css section

8:38:12and it also has property support for flexbox which we also looked at in a couple of videos before

8:38:18but i think we skipped over the justify contained items and this sort of stuff which is also like

8:38:24pretty basic and and one of the few things which we discussed like almost immediately once we

8:38:30start working with flexbox so i hope that you remember the justify content and left and right

8:38:36and center and all that stuff from the css module if you do not then go back into your full stack

8:38:42learning path or front-end learning path and take a look and these properties basically just

8:38:48plug and play and allows you to write those particular styles so yep that's pretty much

8:38:52it for grid as well in tailwind in the coming videos when we'll build some apps or something

8:38:58with the tailwind css we're gonna be using a lot of this stuff so make sure you keep an eye out

8:39:04on not only just this course but in other courses ahead where we would use tailwind to build stuff

8:39:14hey everyone welcome back and in this video we're going to be taking a look at how to build a simple

8:39:19sort of carousel in css with tailwind which is not exactly a carousel because it'll lack controls and

8:39:26stuff because we need js for that but mostly a nice widget which will snap itself in place just

8:39:34like this particular widget does when i release the scroll right and this is because of the new

8:39:39addition of scroll snapping feature in tailwind not in css it has been available for css for a

8:39:45while but this scroll snap align which is possible now inside of tailwind is available in version 3.

8:39:54let's take a look at how we can build this particular app right here you can see when i leave

8:39:59my mouse it snaps itself to the center uh not exactly center to the start because that's what

8:40:05the snap says but let's see how we can build it with a couple of divs over here i'm going to get

8:40:10rid of this code right here we're going to start a little bit fresh i'm going to start off with

8:40:16something like for example let's build up a few divs i'm going to say something like width of 100

8:40:23hopefully that is available height of let's say 48 then a bg crate

8:40:31800 something like that right and it looks like it's just way too big so probably

8:40:36something like or maybe it's not available that's that's a more plausible explanation yep

8:40:42all right so we have the first div we're gonna do a bunch of tips with different colors green

8:40:49blue yellow right and i'm going to give this upper div a class of flex so what this means

8:40:58is that this is now a flexbox and you can see that obviously it does not follow our width

8:41:05set in flexbox right so what i can say is something like uh overflow

8:41:13x auto which just means that hey you are allowed to scroll out of the

8:41:20original width of your container and finally to allow this element to actually

8:41:27use its own width instead of just shrinking to fit what i can say is flex shrink shrink zero right so

8:41:39the moment i say that you can see now this area is scrollable instead of you know just getting shrink

8:41:46down to the individual words awesome so now right now you can see in terms of scrollable this does

8:41:52not does much except for scrolling so in order to add those snap possibilities what we can do

8:42:01is give it a direction first of all so i'm going to snap this into x direction by saying that

8:42:07right so this sets certain properties which are required for enabling the scroll snap in css but

8:42:14you can see that it still does not work because you have to give where that particular element

8:42:20should snap on an individual level in this case let's say if i give it a snap of center

8:42:26you can see now if i go ahead and try to scroll this green over here snaps at center right when

8:42:33i scroll and i leave my mouse similarly this red over here snaps at center as well

8:42:38similarly for blue and similarly for the last one yellow if i change the direction from snap

8:42:45center to snap start you're gonna see it starts to snap at the start similarly for green you can see

8:42:54it snaps at start and so on so if you give it something like space x of 4 for example

8:43:01you can see now it is like much nicer in terms of visibility and even if you give it a nice scroll

8:43:08thing you're gonna see it always lands in the the starting part of the particular div right

8:43:15so that's awesome you can also add a margin a scroll margin to it so you can see the scroll

8:43:21ml6 creates a left margin of six units so if i go ahead and give this to all of the divs over

8:43:28here you're gonna see that now they pretty much have a six units of snap margin to themselves

8:43:36and if i match this with the spacex that is the padding this would pretty much mean that you know

8:43:43it'll just keep that area to itself it'll snap to the white area instead of the actual boundary of

8:43:50the element so yep that's pretty much it for scrolling in css with tailwind scrolling and

8:43:55snapping the scroll so pretty exciting pretty pretty neat feature of tailwind version 3.

8:44:06hey everyone welcome back and on this video let's just go ahead and discuss about

8:44:10the css typography where the tailwind which is also an important thing because a lot of

8:44:17most of the part of our website is actually text so let's start with the regular h1 tag over here

8:44:23and if you have not observed it yet when you include tailwind you're going to see that you

8:44:29automatically lose the ability of nice font sizes which the browser provides which is not exactly

8:44:35very nice but you can see here h1 h2 h3 all are of same font size and same font font weight and so on

8:44:43so the reason for this is because tailwind wants you to explicitly style them according

8:44:47to your layouts or whatever your need is and it provides you with a rich set of classes to do that

8:44:54so font family starting with font family i'm just going to cover a few important ones

8:44:59you can see that you can specify a particular font directly whatever is available inside of

8:45:06tailwind and of course you can add more fonts later down the line as well with configuration

8:45:11which we'll talk about a bit later in the advanced section but mostly you would not

8:45:17be setting or hovering changing fonts on hovering right wants one set for a website is usually set

8:45:24so we're going to be moving on to font size which is super important and this is what you will be

8:45:28using all the time so you can see that tail one gives you the variance from extra small all the

8:45:34way up to 9xl which is eight ramps 0.75 ramps to 8 rims right which is the default system so usually

8:45:43you would obviously have something like text for excel for a heading then maybe x3 xl for an h2 and

8:45:52so on right but it's up to you so let's start with a single h1 let's say the quick brown fox sentence

8:46:01whatever that is because it includes all the alpha bits but i don't know the exact sentence so

8:46:09specifying a text font size actually increases the size of the thing which is awesome right you need

8:46:16that the font style is something like you can set it to italic or not italic depending on what you

8:46:23want again just you have to write a single keyword font weight allows you to set a weight that means

8:46:30how thick the font should be so you can see the eq balance of this is actually in the font weight

8:46:36of css and this would only work well if you have imported the correct fonts with the

8:46:42correct weights most of the fonts sometimes don't have all the variants so the browser somehow just

8:46:49tries to make up for that so make sure yeah if you are looking at custom fonts make sure you have

8:46:54imported the correct weights of the font so for example take a look here if i do font extra light

8:47:02over here you're gonna see that this is much more thin compared to what the default was

8:47:09right and if i say font extra bold this becomes much more thicker than what it was right so

8:47:17depending on what kind of heading you have you might want extra bold at some places and extra

8:47:23light at other places so again this is something you can pick up with the help of tailwind then of

8:47:29course you have basic utilities like text aligning as a center so if you give a text center to this

8:47:36it will center your text instead of just writing another part of css manually so that all sorts of

8:47:42alignments and stuff is there but text color you can see that it specifies text white and

8:47:49all the colors which you have already seen in the color color palette so that is awesome so you can

8:47:54just pick up any sort of style and you're going to see the moment you apply it it turns the style

8:47:59into that color similarly if we move over to text decoration you're gonna see this kind of is a new

8:48:06feature how you customize the text decoration color in tailwind css3 so if i just copy let's

8:48:14say this one over here and paste it right here you see it will underline it and let me just

8:48:21give this a gray of 800. it will underline it and it'll underline it nicely right you can see

8:48:28the cues in the sentence don't get cut off so that's that looks good

8:48:36and on top of this you can also specify the style of the decoration so you can see you have a bunch

8:48:42of styles you can have a double double decoration you can have a solid decoration decoration

8:48:48which is the default style if you opt into double you can see you get something like this

8:48:53you can also have a wavy style which is you know something like if you want to show a grammatical

8:48:59mistake or a sentence something like that you can do that that's also pretty awesome

8:49:05um you can have a dashed decoration dotted decoration and so on so it's almost like

8:49:11whatever you can do with a border kind of thing you can do over here and similarly like

8:49:17you know this can be applied on over so that's pretty awesome as well so if i hover over this

8:49:23you can see it changes its style that's awesome so those these utilities over here is pretty much

8:49:29a lot of what you would need along the way the font size the type the decoration the colors

8:49:37the alignment the thickness and you know basically how you want it to present can be done with all

8:49:43of these utilities entailment css i'm going to keep this video short and until this point only

8:49:54hey everyone welcome back and in this video let's talk about shadows in tailwind which was being

8:50:00awaited for a long time and finally the support for shadows is here and the color shadows i should

8:50:06mean because the regular shadow which was just that black shadow was already there but now you

8:50:12can have colored shadows with tailwind and this is awesome so let's try to create a button like this

8:50:18in our coded playground over here so i'm going to go ahead and click on write something like this

8:50:25is the best programming website you should get a pro account right and it seems like it's just too

8:50:35much text but that's fine so i'm going to go ahead and now create a button which would say subscribe

8:50:42via stripe something like that and this would be our subscription button but right now you can

8:50:47see that it does not look very fancy so we're going to start building this button over here

8:50:53so i'm going to walk you through with the example of how it is done on the main

8:50:57site on the on the tailwind side so it's going to need a little bit of padding on the x-axis

8:51:04and on the y-axis so you can see we have given it you know roughly like 12 pixel assuming that

8:51:11my device is working perfectly fine so it's 12 pixel padding on the x direction

8:51:17and 8 pixel on the y direction or rather we should just say three units and two units

8:51:22then we have to give it a background color as well let's give it a indigo as the color and vg indigo

8:51:29500 that's the opacity we need the text to be white and we need a little bit of border around

8:51:37this as well border radius right which is what we call in uh css in tailwind it is just called

8:51:43rounded right and rounded can give your borders a little bit of rounded but you can also increase

8:51:49the intensity of rounded by having a dash and then you know lg or md or you know sm these these sort

8:51:59of modifiers which you also see the responsiveness view right then we would do something like

8:52:06shadow so when i say shadow it will automatically create a shadow which might not be just

8:52:12visible just yet so i can just give it a shadow of large you can see now the shadow appears a bit

8:52:19but that was it earlier in the tailwind earlier versions that was the only thing you could do

8:52:25but now let me just center this first but now you can let's just give it a margin top of

8:52:328 or 12 so that we have a little bit of cap but now you can in tailwind css3

8:52:40also give color of the shadow so the way you do that is you just say shadow

8:52:46then the color in this case indigo and then the intensity of that color right so you can see it's

8:52:54500 right now but it appears like it's too thick of a color so in order to control the opacity

8:53:01you have to give it a slash and then the percentage of opacity so let's say i just want 90

8:53:06opacity right so this is like 90 of the original shadow if i give it 10 then this is like 10

8:53:12percent of the original shadow which is pretty much like non-existent so let's just give it a

8:53:18close to like 50 percent and this will give a nice shadow effect what you can also do is on hover

8:53:26let's say you want the shadow to become a bit more intense at 80 percent opacity so when i hover over

8:53:33this you can see the shadow increases which is pretty awesome now just to complete the demo you

8:53:39can also play around with the font size and font semi bold just to give it a little bit of bold

8:53:47area uh bold text and you have got a nice stripe button subscriber stripe and obviously this is

8:53:56something which you can copy paste anywhere on your website and this button would render exactly

8:54:01like this as long as you're using tailwind so this is the magic of shadows and tailwind in general

8:54:08pretty awesome if you ask me and now you know this shadow could look pretty amazing on different sort

8:54:14of backgrounds as well so if you have a dark background on the body you can see that you

8:54:21can have a nice little text gray of 100 as a text color and a nice stripe button over here

8:54:31right so yep that's pretty much it how you can create shadows in tailwind css and how you work

8:54:40with a lot of this stuff a lot of buttons and a lot of classes i think we have done this for the

8:54:46first time in having so many classes on a single element but that's you get used to that stuff

8:54:56hey everyone welcome back and in this video let's just go ahead and discuss about functionality

8:55:02in tailwind css which was only possible because of just-in-time compiler introduced in the last

8:55:08version and now it seems like a no-brainer a lot of times when you want to opt out of

8:55:13the default styling mechanisms so what dynamic styling would tailwind means is that instead of

8:55:22sometimes okay sometimes what happens is that your default styles which tailwind provides

8:55:28are not enough right whether that's maybe a one pixel margin which you wanted to give or a custom

8:55:34font size or a custom color or something which you wanted to give which is not available and

8:55:40you don't want to go into your css files or mess around with that what you can do is instead use

8:55:48these placeholders with properties that is like one way to go about so if i give something like

8:55:54200 pixels and remember that i'm doing this inside these square brackets what tailwind would do is

8:56:01that it will try to infer what the property did earlier for example this property did margin top

8:56:08and there used to be the value for this particular property right so instead of the value it found

8:56:14that hey i have this weird square syntax so this means that this is a dynamic property

8:56:21this means whatever the value is inside this is actually the style which should be generated

8:56:27so if you open this in a new tab and if you take a look under the hood you're going to

8:56:31see the style which is generated the class name which is generated over here is a dynamic class

8:56:39of dot margin top of 200 pixel the same class which you use but the style is pretty much

8:56:46the same thing which you would expect it to be right similarly you can have 3 em for example

8:56:52it doesn't matter what you want and refresh you're going to see it's going to generate the same class

8:56:59as your class name but it's going to dynamically populate that particular style

8:57:04so this is pretty awesome why because it allows you to opt out of tailwind's default boundaries

8:57:11although it should not be used pretty much with every single style because then what's the point

8:57:15of using tailwind but sometimes it's a great escape hatch right for example i want to give

8:57:21a custom color to body so instead of going all the way you know to config files or to css to

8:57:27add it what i can do is something like something like this where i just specify or you know i think

8:57:36i don't know a black color i think fd was the one yeah not sure so for example let's just have a

8:57:43background of black or something like which is a little bit nicer or a little bit less black

8:57:513e so i can have a 3e 3e3e as a dynamic background color and this will just work out of the box so i

8:58:01don't have to like add it as a new color or you know mess around with my css and so on

8:58:06similarly for text i can have a 72 pixel as a size and it'll just work out of the box

8:58:13but like i say it's more of a like a replacement of a existing value and tailwind would understand

8:58:20it out of the box so this is pretty awesome and pretty amazing which escape hatch which allows

8:58:28you to work with all sorts of values within your tailwind so this is one way of having a property

8:58:35which taylormade already knows and assigning it a custom value in tailwind css3 there is another way

8:58:41of having completely dynamic property and value assigned to your div element or whatever element

8:58:48so you can see in the dynamic section of the tailwind docs it actually says that you can pretty

8:58:54much throw in a full utility uh the full property and the value pair and it will just make it work

8:59:02right so if you want to try it out what we can do is something like background and then

8:59:10the same color just like that and it should still work and yep it does work so this is pretty

8:59:17awesome right you can have a black background over here so at this point you are literally just

8:59:23writing css but in a way which is combined with tailwind right so you can have background black

8:59:31and then display flex something like that and it will just work out of the box so

8:59:37not display fix i think that won't be visible very much opacity 0.5 and then what i can say on hover

8:59:46opacity is one so again this is like an escape hatch which works pretty awesome but you should

8:59:52probably not use it because tailwind also already has support for opacity and opacity 100 like this

9:00:00so try to not use the escape patches if they are not required bg 3 900 it'd be a good option as

9:00:07well so yup i mean but but in case you wanted to do that just just letting you know that this

9:00:14is completely fair completely possible and completely valid in tailwind css version 3.

9:00:24hey everyone welcome back and in this video i want to show you how you can use tailwind css with

9:00:31react and that that is pretty much what you would be doing in this learning path all along because

9:00:36we have chosen react as a technology so in order to use tailwind with react you have to set it up

9:00:42according to what your environment is for example if i have react playground on code damp at least

9:00:50for now we use something known as snowpack as a bundler instead of create react app because it's

9:00:56a bit faster if you are running it in a create react app locally then you have to follow it a bit

9:01:02differently if you are running it on nexus there is a little bit of different procedure and so on

9:01:08so if you go to tailwind css installation section under docs path you're gonna see you have multiple

9:01:14options we have been doing so far with the play cdn which is not optimal for production

9:01:20and fine for just you know having a little bit of experimentation what you want is go into this

9:01:28frameworks guide and pick up whatever framework you are using in this case we are using react not

9:01:34on server side but on client side and that also with snowpack so i'm just going to follow this

9:01:41quick slow pack guide which in essence is pretty much uh similar to what your create react app

9:01:48guide would be i'm going to fire up a second terminal and start writing these commands if

9:01:52you want to follow along you can do the same thing in the code down playground at least if

9:02:00we are still using the snowpack bundler you can see that we are using snowpack because of

9:02:05the snowpack keyword so i'm gonna install this the next thing which we need from the snowpack bundler

9:02:13is the configuration part so we can do something like yarn tailwind in it i believe and you can see

9:02:25it has created a tailwind config for us but not a snow pack not a post css config.js

9:02:33let's go ahead and create that ourselves four css config.js and over here in this file i'm just

9:02:40going to keep it like this and in the tailwind config we have to specify the content part this

9:02:47is a little bit older configuration algorithm version 2 in tailwind version 3 you just have

9:02:52to specify the content part of all you want to have so let me just go ahead and copy that instead

9:02:59so right here we need what we want to say is that look inside the src folder

9:03:06and anything you find with js or jsx just try to extract out tailwind styles from that and

9:03:12apply that right that's that's what we are saying and yup that is pretty much it in the

9:03:19setup and finally it says us in the snowpack configuration we have to add this as the dev

9:03:26options so let's go to snowpack and over here you can see inside dev options we have to add this

9:03:34tailwind config and inside the plugins we have to add the snowpack plugin over here there we go

9:03:45finally we have to go to the public global.css in this case and if that is not a file then we'll

9:03:53create that global.css import the tailwind utilities which are the base utilities

9:04:00and then finally add this as a global css file inside our index dot html

9:04:10okay once we have done all of this hopefully when we restart our server for snowpack it should

9:04:20pick up our tailwind so for this what i'm going to do is i'm going to say inside src folder i'm going

9:04:28to remove all the css files right including this global.css i'm going to just close this

9:04:36inside app i'm going to remove this refresh this even inside index.js let's remove this file

9:04:46and refresh this and for global.css saves us not found there we go

9:04:55okay so now you can see that global.css is pretty much empty at the moment so looks like

9:05:04it did not propagate the changes so let's just go ahead and copy these utilities one more time

9:05:12to see if it is not being overwritten and okay now if i go back to app.jsx

9:05:21remove this app class and try to write bgray of 800. okay so did a quick change in the setup move

9:05:29the global.css file in the src folder and this index file now includes the global file so now

9:05:35what we can do is do all sorts of tailwind css stuff which we did back in the

9:05:42html and css tutorials and whatever we do it will automatically start reflecting it in a

9:05:49react playground so yep that's pretty much it that's how you would set up your tailwind css

9:05:55thing in a react based playground and the fun part of this you don't have to reload so that's awesome

9:06:01but it will automatically minify and take out all the things all the required things from your react

9:06:10jsx files thanks to the configure the content property which you have specified over here

9:06:22hey everyone welcome back and in this video let's just quickly discuss about dark mode configuration

9:06:27option in tailwind and what does that do so in tailwind.config.js you would see that there is

9:06:33nothing over here but what you can do is add an option known as dark mode of class so the moment

9:06:40you do this what's going to happen is that now wherever you specify dark mode styles in tailwind

9:06:49you can make them toggle just with a click of a button and let me show you how that is done

9:06:55we have this page over here which has a couple of dark mode classes you can see i have a dark

9:07:02selector and then i'm specifying a background and i have a dark selector and i'm specifying a text

9:07:07color by default if i did not have the start mode class it would automatically show me dark mode why

9:07:15because my system is in dark mode so what tailwind does is that it prefers the scheme of the system

9:07:23so if i did not have this class dark mode over here and if i just wrote these couple of styles

9:07:32and just started my server i would have the dark background over here but because i wrote class

9:07:38that means whenever i add a dark class at the top of all of these where the dark class is applied

9:07:45dark selector is applied then only it gets triggered right if i remove that it goes away

9:07:52so in order to create a simple uh you know toggle button all you have to do is import

9:07:59your state from here you can say x set x for a lack of a better word i cannot think right

9:08:08now and you can say that if x is true then dark otherwise no class and by default you can see

9:08:18we start with a false and i can say on click on this div itself i just toggle the x right

9:08:28so whenever i click on this div you can see it turns from light mode to dark mode and vice versa

9:08:34and the fun part about this is you can pretty much apply any sort of styles so you can say

9:08:39b class dot x to excel and this will just start working automatically so

9:08:46just give it a second for the styles to propagate and make sure you have the correct name

9:08:52over here as the attribute name and as you can see when i click on this now it increases the font

9:08:59size so you can pretty much customize your website as you like in the dark mode and whenever you

9:09:05toggle it on a click of a button it will operate just fine so yep that's pretty much it

9:09:09for this video hopefully you were able to learn something new something interesting about dark

9:09:14mode and this one that is all for this one and i'm gonna see you in the next video really soon

React Query for network requests

9:09:24so what is going on everybody welcome to the very first video of react query course now this course

9:09:32is super important for all of you react developers out there who have experience

9:09:36with react but also want to standardize how they perform network requests in a react application

9:09:44because what you will see is talking to back-ends and apis is one of the most common thing you will

9:09:50do when you're developing a web application so we're going to be taking up this course this

9:09:55is not a static video only based course you are going to watch this course on codedam codedown.com

9:10:01and you will have practice sessions in between so make sure you are practicing completing all

9:10:07the labs which you get along the way those are super important and relate to what has been taught

9:10:12in the previous video and yeah just make sure you are also working in a real playground environment

9:10:19even with the videos so you can launch a codename playground by going to codem.com playgrounds and

9:10:25you can see the react playground there or if you want you can just set up a quick react.js

9:10:30project locally on your system as well and follow along with the videos and of course complete the

9:10:35hands-on challenges along the way but for the most part this terminal this environment is pretty much

9:10:40how a typical react setup would look like on your system as well so i don't think you necessarily

9:10:46need to work on your local environment just spin it up on your browser and once you're done just

9:10:51you know spin it down so you don't really have to do any sort of cleaning and everything but

9:10:55yeah that's pretty much it for the introduction part in the next video onwards we're going to

9:10:59be seeing some basics why we need react query what exactly it is how to install it and all that stuff

9:11:11hey everyone welcome back and in this video let's just quickly take a look at

9:11:14why would you even need react query in the first place

9:11:18so if you have spent a little bit of time with react.js and some multi-component

9:11:25architectures and multi-component file systems in in your react query in your react project

9:11:31and you also have used some sort of network-based logic where you are performing fetch requests and

9:11:36everything you know a very common pattern for react developers is using a use effect like this

9:11:42and you know just having a fetch request here right so you would probably have something

9:11:48like fetch this api not then you know data and then you just set data to data and you have a

9:11:57state variable here so you have data set data something like this you know so you have this

9:12:05stuff going on now this is completely fine i mean this is not technically wrong it's just

9:12:12inefficient if you try to consider some other factors right for example what if i want

9:12:19to cache this api right so let's say if this is a this is some sort of different page

9:12:26on which this api is being you know made call and when i navigate away from it and then come back to

9:12:32this page i want to have the cached response because i know this api although is slow but

9:12:37the data won't change that much so caching is difficult you have to implement it on your own

9:12:42how about something like polling for example let's say i have this api but i want to ping it every

9:12:49couple of seconds or you know up every couple of minutes or anything like that so how do i do that

9:12:55right so that is also a problem re-fetching is also like one of the problems which can be there

9:13:01for example you know if you just want to refresh this you probably would copy

9:13:05paste this in a function and then call it again but these are some of the high level problems

9:13:11some of the problems like caching and polling will require might require a lot of code for you

9:13:16and some refitting might require a bunch of hacks right so the problem here is that react

9:13:23actually does not provide any standardized way of making fetch requests or you know making

9:13:28network requests as a matter of fact that means you can might as well use axios here

9:13:33you might as well use you know xml http object that primitive way of making requests so you could

9:13:40use pretty much everything here right there's no right or wrong answer but in order to keep things

9:13:46sane and in order to keep things relevant what you can do is you can make use of react query react

9:13:53query comes with certain practices and certain things and certain hooks which you have to follow

9:13:59it makes your code more declarative that means you're just telling what needs to be done

9:14:05instead of imperative where you actually define how it needs to be done right so this is this is

9:14:11sort of an example of you know imperative request where you are telling how it needs to be done

9:14:16you might also specify a method post and all that stuff if you implement caching on top of it

9:14:21that will be imperative again but react query abstract all of that away from you

9:14:26so with that being done let's just quickly take a look at react query we're going to be installing

9:14:31it inside the code and playground interface as well in it only um by actually you know just

9:14:38going ahead and closing this terminal and doing that so we'll be doing that in the next video

9:14:48all right so let's just go ahead and set up react query now and the way we're going to be doing that

9:14:53is first of all installing it so i'm going to go ahead and say yarn add react query in my terminal

9:15:00you have to do the same thing in your terminal and i'm using yarn because we are using yarn.log file

9:15:05if you are using npm that means you're seeing a package lock.json file then you would have written

9:15:10npm install react query but depending on whatever it is for you right so once that is done we can

9:15:16go ahead and start our server again so that you know if i refresh this it will just load our react

9:15:23application once that is done as well what we're going to do is start making some changes here in

9:15:29our index.jsx file which is the top file and i'm going to import a couple of things here called as

9:15:35query client and query client provider from react query right so these two things basically the

9:15:44first one we can just get rid of the strict mode query client provider in checks a query client

9:15:51inside of our full application right and what this query client is this query client simply gives

9:15:58your application the access to modify the cache the query cache in react query right so this is a

9:16:06mandatory step in react version three so you have to do that but once you have done that you'll see

9:16:11there's no major difference right here so what i also want to do is import react query def tools so

9:16:18i'm going to say react query def tools from react query and def tools right and once you do that

9:16:28and just write it right here you're going to see you might see this error no query client set use

9:16:34query client provided to set one and this is actually a false error so just go ahead and

9:16:38restart your server if you see this right i'm not sure why this happens on the snowpack build

9:16:44but if you refresh it restart it it'll just work fine all right so once that is done we

9:16:50can just switch to the browser only mode so that it's cleaner now you could see that if

9:16:54you open this you will also have little react query dev tools by your side which

9:17:00will actually help you debug any sort of network request you make with react query right so we're

9:17:06going to be making tons of them in the further videos but that's how you're going to do that

9:17:16alrighty everyone welcome back and in this video let's just go ahead and write our first react

9:17:21query make sure your setup is on the point and it is on the point if you're seeing this

9:17:25little react query logo at the bottom and we will be using this to debug or you know just to see

9:17:32what our queries are looking like so first things first what do we do in order to write a query

9:17:39now we will not be writing fetch or anything just yet but instead we will be importing a new hook

9:17:45called as use query from react query right and you can pretty much use this uh whatever we will

9:17:52be doing now in any single component because we have our root setup done correct right so you

9:17:58can probably have a nested component as well where you would just import it and start using it so how

9:18:03does use query work well at its very fundamental level what you have to understand is react query

9:18:10is doing two things with a hook the first thing it says is that hey developer go ahead and specify a

9:18:17key to me you know something like hello world for example this is a valid example of a key

9:18:23right and you can see some activity happening over here which we'll discuss later on but yeah let's

9:18:29just skip this for now so we see that hey use query this is the first argument which i'm going

9:18:36to give you it's a string hello world but it's not useful so what is it exactly this is a key

9:18:42to a request which you will make now what what does this key mean this key is basically used

9:18:49every time you want to for example invalidate this request or use this request again as a cache

9:18:56or you know fetch this request again do any sort of stuff so basically whatever request you will

9:19:01be making here whatever request you make as a second argument it is cached and it is you know

9:19:08basically pointed with the help of this key right here now what this request is this request or the

9:19:15second argument is a function it is basically a function which should return a promise right which

9:19:23should return a promise that's the only condition of this function so you can say return promise

9:19:29dot resolve let's say five for example right and if you do that that's it that's actually a valid

9:19:36thing that's actually a valid condition you have right so you can have a hello world two here and

9:19:42this key actually points to a resolved promise which has a value of five

9:19:47right now most likely you will not be using obviously promise.resolve like this but you

9:19:54will be using some fetch request or anything like that but what you have to understand is

9:19:59before getting into fetch what i want to show you is what happens if we use promise.resolve right

9:20:06use query is a hook which returns you multiple values and multiple things which are super

9:20:12important what these are these are some of the loading states right so i'm going to start off

9:20:17with data because that is interesting and what i'm going to do is i'm just going to say console.log

9:20:24data right here all along and let me just jump into terminal browser and move on move on to

9:20:30the browser preview right so if i refresh this page now what you will be able to see is that

9:20:37inside our console you can see we are getting this five repeatedly right if i do a console log data

9:20:44is the data just to distinguish it right so you see five is the data five is the data

9:20:49a bunch of times right so what's happening is that react query

9:20:56returns you whatever this promise resolves right that's one thing let's say this promise rejects

9:21:03something so instead of resolving it is actually rejecting you whatever you're writing now right so

9:21:10what this will do now is that this will actually also have an error parameter right and i would say

9:21:19error for example error comma data is the data and let's just go ahead and refresh this again

9:21:25and you would now see that we first of all get null undefined null and find is the data because

9:21:32it's in the fetching state and then we start getting this 5 as the error right so you can see

9:21:39we are actually logging this five react queries also doing it it on its own and then the first

9:21:44argument which is an error we get five and the data is undefined now right or maybe like you know

9:21:51you can just do error data like this like cool people do right and you'll get stuff like this

9:21:58there's also a couple of you know there there are also a lot of states as per say which you can use

9:22:05and i'm not exactly going to get into all of them because for the most part you won't

9:22:12necessarily need to know them right away you can know them you know slowly as you are building

9:22:18your application but these states are for example is loading is error is success is idle all that

9:22:27stuff so these four states right here what they mean is obviously this is loading will be true

9:22:34whenever the request is being in progress right so if i have something like return new promise

9:22:42resolve set timeout resolve one second basically this just means resolve this promise in one second

9:22:49don't really stress about this if you don't understand the syntax you can check out the

9:22:53advanced practical javascript we discuss stuff like this there as well but anyway yeah so

9:22:59let's just go ahead and refresh this and take a look at the console what happens so you can see

9:23:05the very first time we get data as undefined error as null is loading as true is error as false

9:23:10success as false and idle as false as well so what does this mean that means that our request is in

9:23:16loading state right now the promise is there but it has not resolved or rejected right now right

9:23:23finally once one second is over you can see 145 30 we get this message and after one second we

9:23:29get data as undefined error as null undefined is because we are not calling resolve with anything

9:23:35um is loading is false is error is false his success is true because the promise resolved

9:23:41it did not crash or anything and his idle is also false right we'll be discussing more

9:23:46on these states later later down the line as well as we progress but that's the crux of it

9:23:52right so it gives you full uh picture of where your request exactly is so the first thing which

9:23:59will fire is is loading then you know if data is available then his success will be true as well

9:24:05if error is available is error will be true as a boolean and so on and so forth right we will be

9:24:10discussing is idle it's a special case where your query is disabled so we'll discuss that

9:24:16um but that's how it works at the moment right so yeah for the most part what we could just

9:24:22keep it to is data and error and you know whatever we do we will be able to do it

9:24:29just right here with data and error for the most part but you can bring in additional

9:24:33flags as well if you want right all right so yeah that's pretty much it i think we have written our

9:24:39very first react query which is technically not making any network request but you get the idea

9:24:45that anything which is a promise widget returns react query internally you

9:24:49caches it uses all sorts of logic behind it but the underlying assumption of react query is that

9:24:56it just requires you to return a promise as a second function as as the query function

9:25:06hey everyone welcome back and in this video let's just discuss a little bit about

9:25:11states of react query itself you know these fresh fetching stale and inactive and what these means

9:25:18and how react query you know assumes your data to be as well because just getting into syntax right

9:25:24away won't be as much beneficial as it would be if you know about the core functionality of it first

9:25:32so what i'm gonna do is first of all let's just go ahead and create a very simple button

9:25:36component right here which just has this i'm just going to return you know button i am a button

9:25:45nothing fancy here just want to separate um this component from the actual app file right

9:25:56and if you do something like this you can see you get an imo button like this so there's that

9:26:01but what i want to do is i also want to have another button which just says toggle

9:26:08the button component right so i'm gonna say button on click hide button or you know toggle button

9:26:17so the idea is that i also want to unmount and remount this component so i'll say just

9:26:22set visible visible and not visible right so this is just a convention which says

9:26:28just set it to the state which it is not and i'm gonna have a visible and set visible as a state

9:26:36variable which will just start with true let's say and finally let's just import the u state hook

9:26:46so what's happening here is that when i click on this toggle oops we also need to use this when i

9:26:52click on this toggle it will toggle the visibility of the button right so if you toggle you know

9:27:00that's how it works now the very first thing you could see right away is that if i toggle this

9:27:07the button is no longer on the screen you can see the inactive query right here is one

9:27:13that means react def tools and react query in general will move your query as inactive as

9:27:20status inactive whenever you know it the component is not mounted right and it makes sense that your

9:27:27query is inactive at that point once the query is active you can see it immediately fetches the

9:27:34query right and this is the default behavior you can see it toggles off and it toggles on and it

9:27:39fetches if you increase this duration from one to two seconds you'll see that now if i toggle it on

9:27:45it takes a couple of seconds and then immediately once it's fetching once it's done fetching that

9:27:52means you know you get the response and everything instead of moving it to fresh it moves it to stale

9:27:57and you might be seeing that hey why this is happening again and again

9:28:00i mean why is react very fetching everything again and again so let me just clarify what's happening

9:28:06here is that i'm bringing this window this you know this embedded browser on code dam into focus

9:28:12and then out of focus into focus out of focus so whenever you move from out of focus window

9:28:20whether it's a tab whether it's anything and you focus it back on it react query would internally

9:28:27update that uh query which you know has been marked as stale right so any any particular query

9:28:35which is stale will be updated that means it will be fetched in the background and you know it will

9:28:42just it will just do that it will just show you that thing what we can do also is that instead of

9:28:48let's say just 1337 i also want to resolve a math.random number and we're going to do

9:28:55i'm a button with a data right here right so you can see right now in the sense that it starts with

9:29:02a random number now if i move out of the browser and into the browser you will see that the number

9:29:08of dates out of the browser into the browser you will see the number updates again in a couple of

9:29:13seconds but if i'm just sitting here you will see it will not update if i toggle it again it will

9:29:19start with the cached value but it'll update again right so it starts with the cached value initially

9:29:25and then as soon as it has the new data it will just show that otherwise if you're

9:29:30just starting off for the very first time for example if you're doing a page reload

9:29:34it'll not have the data with it so the data is empty that's why you don't really see anything

9:29:39and you will have an is loading flag set to true right at the initial point as well

9:29:46so how is happening how this is happening again is couple of things first of all react query will

9:29:52attempt to fetch everything which is stale when it moves from foreground to background

9:29:59background to foreground right and second of all the default behavior of react query

9:30:05is that whenever a request is completed it's fetched it moves it to stale and why is that

9:30:11because there's a parameter called stale timeout or stale timer or whatever it is time to stale

9:30:19which is zero in react query by default that means as soon as a query is fetched just move

9:30:24it to stale right that means the data is still and it needs to be updated so you can increase

9:30:30that and if you do it will move to fresh for that particular time duration and then move to stale

9:30:35um yeah i mean right now it's an aggressive data mode that means it always want to keep showing

9:30:42the user the most up-to-date data which i think is the same default right um and yeah one thing

9:30:50you might have observed that while it's fetching the data it actually doesn't clear out the older

9:30:54data which is fine because it just keeps showing the user a cached version of what was available

9:31:02earlier right so that's that's cool so that means once you have loaded data with react query you

9:31:08won't really see any loading indicator if it needs to be updated it will just update it automatically

9:31:14now the other thing which i wanted to discuss is about the react query dev tools itself

9:31:19which probably we will do it in the next video because in this video we have just

9:31:23focused on these four states and i hope you understood how all of them are working

9:31:32hey everyone welcome back and in this video let's just go ahead and take a look at this react query

9:31:37tiff tools and what how we can make use of it you know more than just seeing this hello world

9:31:43so if i toggle it back again once it fetches and if i click on this you will be able to see

9:31:49a lot of more details which react query internally stores right so this is like the internal state of

9:31:55react query library itself which is pretty cool so what's happening here is that you can see inside

9:32:00query details we have the query name first of all and the state at which it is right now which is

9:32:06stale observers 1 basically means that we have just a single component using this query you can

9:32:12have us multiple components using the same query and have all that caching advantage and everything

9:32:19and just a single request so this is like a super cool feature as well which is very very hard to

9:32:24do manually i mean you have to pollute your global scope or something like that if you want to do it

9:32:29and it's usually not required if you have solutions like react query and yeah so you

9:32:35can use the same query in multiple components and not exactly worry about storing the data somewhere

9:32:41in global right react query is doing that for you internally so you know you can basically

9:32:47make request for user profile data in your header component as well as in your footer component as

9:32:53well as in your sidebar component and react query will make sure that you know the request only

9:32:58goes once to the server but all the caching and revalidation and invalidation is delivered to all

9:33:05all the components right which have subscribed to it so that's what this observers is for

9:33:11last updated again is just a time stamp of when it was updated last so that that should make sense

9:33:16then actions is basically you know something you can play around with it internally right so if

9:33:22you click on refresh you can see you know you can trigger that behavior invalidate reset remove all

9:33:28that stuff you can see the data we should get is the new data which you get every time the query

9:33:35fetches and in our case it's just math.random nothing fancy here query explorer is basically

9:33:41consisting of uh you know some options which react query is using right so

9:33:48let's see if we can find something interesting here you know options is basically query key

9:33:54query hash we'll discuss query hash what it is and why is this as an array in an array form

9:33:59we also have observers which is you know again the same thing more or less that how many

9:34:05components are using it we have the cache which could be used for you know cache revalidation

9:34:12invalidation and then fetching the stuff again um queries map is also there so this is this is

9:34:20sort of you know if you want to dig a lot into internals of react query what all data is storing

9:34:26then you can do it from this particular point right and inside state you will get again all

9:34:32sorts of stuff what is the data currently how many times it has been updated i mean

9:34:37you usually won't really need so many details but it is there if you want it ever right so that's

9:34:43that's a good thing to have right so yeah i mean more or less what's important here is that

9:34:50you have a lot of information inside of react query within the dev tools and it is accessible

9:34:57in simple terms right so these are simple words is paused is resolved you can understand it

9:35:02on your own as well that date updated count stuff like this time stamps etc

9:35:07so yeah that's pretty much it for react query dev tools tool and once we start writing more queries

9:35:14you will see more lines here and you can you know just play along with them around them as well

9:35:24hey everyone welcome back and in this video let's just take a look at the query key before we

9:35:31actually get into query functions and in detail of building a project with react query so we already

9:35:37have taken a look at what query key is and how it works but let's just go and formally look

9:35:41at it once in this video so you can see once you have set up just two device once you have set up

9:35:46the query client provider you have created a new client and you have imported the use query hook

9:35:52you can simply go ahead and create any query with like key one something like this just write this

9:35:58hook as it is and if you open the reactive tools you're gonna see that key one now exists right

9:36:04although it's saying fetching and all that stuff but you can you can leave that for the moment

9:36:10but you can see key one is how it re how it is represented in the dev tools is in the form of an

9:36:16array not as a string and this is important because react query internally uses

9:36:24arrays for storing the keys to the query right and why it does that because it helps you to

9:36:31just forget about you know you know forget about just concatenating the key in a you know in a way

9:36:38if it depends on props and something like that and just focus on uh passing dependencies to the query

9:36:46so what i want you to think of this is in the following way you can have like key one

9:36:51you can have key two and so on but how you should think about this is that these are kind

9:36:59of like use effect dependencies not exactly but you can think on the similar lines that

9:37:05the way you specify dependencies and use effect that whenever those dependencies change

9:37:09your keys your use effect function runs similarly your use query

9:37:16result the final result is dependent on whatever keys are here right and if these keys are changing

9:37:24then your query will can be refreshed your query can be uh you know invalidated the data can be

9:37:31brought again from the server and so on so for example if i had a to-do list right as a to-do

9:37:36list application and this was just a single item so i would probably have a prop which was like

9:37:42prop dot item id and let's say i had a rest api which got that so i will probably specify an item

9:37:50id like this right and you can see it's null right now but you know if you populate it then

9:37:54it'll automatically be um you know relevant so in this case you would have something like to do

9:38:02single item as the first key because you know it just marks the name space as such because you

9:38:08would be using use query later down the line right in other components as well but let's say if the

9:38:13item id is just one or two or just a single number then of course you don't really want that to be

9:38:18just a single key because that's just too common right and some other component might overwrite

9:38:24that so you just specify what the category is and then the number so it's more of a convention also

9:38:31what you should follow and what you could follow is that the first thing could be you know you're

9:38:36defining name space of what is happening what is going to happen with this query what you are

9:38:41exactly fetching and the next few um keys could be just dependencies of what you want to bring in

9:38:47right and yeah that's pretty much it you can also throw in objects if you want here

9:38:52status data errors stuff like this if you have like you know depends on your use case but you

9:38:58can't throw in objects although i would recommend try to stick to primitives no no specific reasons

9:39:06i just see like you know because just like with usefix it's kind of a bummer or you know not a

9:39:11good practice to throw in objects because they might get recreated on um every single render

9:39:18but this is not the case here you can safely use objects but my suggestion is just if you

9:39:23could try to stick to primitives just keeps the things clean and concise so yep that's pretty much

9:39:29it for this video hopefully you understood what keys are we're going to be taking a look at that

9:39:34in the practice labs and the practice projects hopefully which you are completing along the way

9:39:44hey everyone welcome back and in this video let's just go ahead and take a look at how you can make

9:39:50use of dependent queries in react query and what exactly does that mean so first things first what

9:39:58exactly is a dependent query a dependent query is a query which you can control by passing in uh

9:40:06enabled you know let's let's first of all define a feature function and then pass in an enabled enab

9:40:13led as false right so this feature function is gonna be very simple we're just gonna have a uh

9:40:21you know promise dot resolve let's say 100 right whatever so just a function which returns your

9:40:29promise and if i refresh this now let's see so we have got our query right here in the dev tools

9:40:36and what you could see is that if i go ahead and open this query right here um what you will see

9:40:43is that right here inside of the state you will see the statuses idle so what this means is that

9:40:52whenever you have the enabled as false this this option present as the third argument whenever that

9:40:59is happening your query would be in status idle and you can actually get out this value by saying

9:41:06you know is idle which we talked about as well and i think in the beginning videos i can say is idle

9:41:14and then just throw in right here and inside the browser logs you will see that is idle

9:41:18is true in fact true for us so what does that mean that means that is idle flag is enabled

9:41:25when the query is enabled false that's something you can make use of and second thing what this

9:41:30enable actually do is that it allows you to conditionally render the hook right because

9:41:36you know you cannot technically use if else right here because react then complains that you should

9:41:42have equal amount of hooks so this enable is kind of like you know let's say if this enabled was

9:41:48um item id let's say right from the props so it's kind of like saying that if item id then i want to

9:41:56run this query otherwise i don't want to run this query so because you cannot do it with a with a

9:42:01hook you cannot use if else with a hook that's why you have this uh nice little syntax with you which

9:42:07just says enable item id and you're done for the day now we can go ahead and create a very simple

9:42:13uh you know very small application out there so just to test it out and i do recommend you guys

9:42:18are also testing it out as you are playing around even with the real apis if you want

9:42:23or if you can i'm just going to have grab the use state from react and what i want

9:42:30to do is instead of all this let's just go ahead and have a button one click which just

9:42:39this and sets this to you know whatever it is not right so this and just say this is state

9:42:47and what you're gonna see is if i get remove if i remove this we have a click me button and

9:42:54you can see it's it's in the stale state right now it started from the stale state and it was

9:42:58in the stale state all along right but if i click on this you could see that well you didn't see

9:43:05anything because you know the moment i click on this we got the data because promise.resolve

9:43:09resolves very fast so instead what we can do is we can make use of our nice little hack

9:43:16return new promise resolve which just returns set timeout resolve after a second right or after a

9:43:24couple of seconds now if i refresh this and if i click on this you can see it goes into fetching

9:43:30and then goes to stale again right so you can see now because the query is enabled we get all the

9:43:34behaviors which you also talked about earlier that react query will start fetching whenever you bring

9:43:39the window into focus but if i click on this again to disable the query so this enabled is false now

9:43:45now you can see we again lose out on that thing and if you pay close attention to the

9:43:52state here of success we have a state of success right here but if i refresh this you're going to

9:43:58see that it starts with the state of idle right and if i click on this button it goes to loading

9:44:05success and then it stays at success you know and then it's fetching true false it's just it's just

9:44:11the variable which gets uh triggered now if you click on this to disable it again you're going to

9:44:18see that it stops working and because you already have the data well it can re it can use that data

9:44:25right so it does not need to fetch again to use that data so yeah that's pretty much it on how

9:44:31you're gonna use the enabled property in the use query hook i hope you understood how this works

9:44:41hey everyone welcome back and in this video what i want to do is create a very simple

9:44:45application using react query so that we could understand how it is exactly working

9:44:51right by actually making requests to the backend server now the way we're going to do that is first

9:44:57of all we're going to define a fetcher function right so it'll take in a name of the repository

9:45:03right and i'm going to come to that while this what this means and we're just going to return

9:45:08a fetch request we're going to make a fetch request to api.github slash repos and then this

9:45:16repo right and i'm going to tell you what this means we're just trying to get some metadata about

9:45:21any github repo and this just passes it and then once we have that i want to convert the result

9:45:29to json and i hope you understand the syntax that how you make fetch request in javascript

9:45:34you just write fetch if if you just want to make get request you write the fetch the url dot then

9:45:40and then whatever response body you get you process it into dot json.json in fact also

9:45:47returns a promise so this whole line is a promise right so you have got a fetcher as a promise

9:45:55now what you want to do is right here we just want to give this as a function and now i want to say

9:46:03let's say facebook slash react right so once we do that and let's say we change this to github data

9:46:14and let's say for now facebook slash react because that's that's our query right and let's just get

9:46:19off enabled as well because we want it to be enabled like forever all right so let's see i

9:46:28think we are missing some semicolons no not really all right so once we have done that let me just

9:46:34refresh this real quick and what you're going to see that we have this and instead inside of this

9:46:41inside the data you see we get all this nice urls and all this data and what this data is exactly

9:46:47you can go ahead and take a look at you know you can just open this in a new window if you want

9:46:53facebook oops facebook react and you're gonna see this is what github returns you right um on

9:47:00this on their public api so we can extract away some information out of this what exactly um

9:47:07what exactly whatever we want in the ui so what i can say is i can say something like you know name

9:47:15of the repo for example is the name which we get from here right and we know that we have the data

9:47:24from here so i'm going to say data.name and i'm going to immediately see that if i refresh this

9:47:30you're going to see that we get a crash because obviously the first time when it loads the

9:47:36fetch request has not completed the data is not available so this data is in fact null right but

9:47:42fortunately we also have an is loading flag here which is available to us so we can just say that

9:47:48hey if this is loading then i just want to return h2 loading right something like this so now if i

9:47:56refresh you can see for a split second we get the loading on the screen and then once it's ready we

9:48:01get name as react right we can do much more than that we have more data so we have a description

9:48:07we can do data on description something like this which is the description which will be available

9:48:13a declarative efficient and flexible blah blah blah right and you can do you know the repo stars

9:48:22as well so if you want stars that is basically data dot star gazers underscore count this is how

9:48:30the property is available you can take a look at json it's not a it's not something you won't find

9:48:37but you know you get the idea so now what i want to do once we have this

9:48:42is we can have an input type text and then i could have you know value as repo repo name or whatever

9:48:55so what we're going to do is we're going to create a state variable repo name and set repo name

9:49:01and this state variable is going to hold our this information which was actually which we hard coded

9:49:07right so instead of this i'm going to go ahead and actually do repo name

9:49:14and set repo name like this right and of course close this out and i can say on change you know

9:49:23just set repo name to either target.value and you can see repo we can get the event right here and

9:49:32you can see right now we get blank information because well we don't really have any data

9:49:38at all or you know we do have the data but it does not contain any name or description or

9:49:44anything like that so that's why it just does not render anything at all so now if i start writing

9:49:51you can see if a c e and you can see obviously it's not very helpful because on every single uh

9:49:59you know keystroke we are also getting that so instead of that what we can do is

9:50:03probably just you know move it here also diff class name app you know there are better ways to

9:50:11do that but i'm just going to stick it right now so that we just have to write it once

9:50:18um and of course here as well so if i write now f-s-e-b-o-o-k slash re-act you can see

9:50:26that's how it looks like in terms of network request so it will start making

9:50:30all these network requests and once we get to facebook slash react we have it right um

9:50:37another thing another repo which we could do let's see api.github.com

9:50:43slash you know if we just do let's say github.com

9:50:51i can do code down because those are private repos and it will not be available

9:50:55so we can do read x which is something new i have not really heard about it so if i do r e d e

9:51:02x you can see a bytecode optimizer for android apps and it just got a 5 000 stars right

9:51:08but the funny thing here is now that if i do r e a c t again you can see that it immediately appears

9:51:16right it immediately appears on the screen because we already had data for this request

9:51:21and you can see if i do r e d e x it immediately appears right because we already had data for this

9:51:28and it can just fetch again in the background so this is where you know react query really

9:51:33shines in it's not about just making the first request but it's more about subsequent request in

9:51:40your application right and if you have a single page application you will realize that people

9:51:45you know if anyone is staying for you know more than a couple of minutes they're not just you

9:51:51know taking a look at the first page but actually interacting with your application there will be a

9:51:55lot of events where they would be actually just interacting with your app and your apis and they

9:52:02will be hitting the back end and a lot of your apis would be hitting the back end multiple times

9:52:07for the same thing like user data or you know whatever it is user settings something like that

9:52:13so react query can cache it for you automatically and you can see that what happened here was

9:52:19it's it displayed all the data i'm not sure if you caught it if you did not just rewind the video a

9:52:23little i'm pretty sure you would be able to see it but it started with one six eight nine seven one

9:52:29nine seven one nine seven one and then it updated to two and the reason it happened is because you

9:52:35know it displayed the older data first it fetched it in the background it updated it with the newer

9:52:40data it's very smooth it's something which you would almost always prefer out of the box

9:52:46and which is something of a headache to maintain if you're doing it yourself right i mean

9:52:51why would you even want to do it when a solution like this already exist and it is very well

9:52:56maintained as well so this is the place where react query and things like these really shine up

9:53:02so yep i mean that's that's why you would use it right so this was a very simple application

9:53:09which you can of course improve maybe you can have a button here which when clicked

9:53:14then makes the request but for the most part you know you will have this um working right so yeah

9:53:23that's pretty much it for this video i hope you learned something from this probably in

9:53:27the next video or something you might be required to build this yourself using the uh react query

9:53:33and all these hooks so make sure you are doing this because i can't enforce you're doing that

9:53:38or not if you're not passing the challenges and passing the labs and passing the tests

9:53:43and all that stuff so make sure you're practicing along the way and yeah that's all for this video

9:53:54hey everyone welcome back and in this video we're going to be starting off by creating a small

9:54:01blog for you which would be powered by react query and by powered by i

9:54:06just mean you know just having those links and caching and all that good stuff enabled

9:54:11so we're going to be using a placeholder api but feel free to create a small back-end for yourself

9:54:16and use it right and if you want to do it on code damn you can do it by splitting the terminal

9:54:21you know just creating a server.js file here and by running node server.js you know second terminal

9:54:26if you want to do that that's possible but anyway what i want to do is i want to say

9:54:33that um let's let's first of all take a look at what json placeholder

9:54:41is right so it's a it's a sort of a api available for you to just try it out right you can just

9:54:50basically get dummy.json response and if you do like post for example right here you're going to

9:54:55see we get a bunch of posts right which looks like you know for our use case these are just

9:55:01random posts with random text so we can go ahead and play with that so what i'm going

9:55:05to do is i'm going to first of all try to get these posts and try to display the data so i'm

9:55:10going to say use query um post and i'm going to just have a fetcher function again so feature

9:55:17but this time this would be just url and this would be like just fetching url and then result

9:55:23is resolved.json right that's it very simple so we have this then we have something like feature of

9:55:34this and then finally what we have is that's it yeah i don't think we need any options here

9:55:43what you're going to be seeing now is that if i refresh this we will have data eventually

9:55:49right once this once the loading is complete so i can say something like is loading and you know

9:55:56if it is loading then i just want to return h1 loading otherwise we have our request is complete

9:56:06right all right so technically we should do a little bit more than just checking for is loading

9:56:13because apis also fail back ends fail networks fail a lot of things can fail in the way but we

9:56:20can add error handling data down the line right what i want to do right now is i want to say data

9:56:27whatever we got we can just rename it to post if you want so we can say post not map a single post

9:56:34and then if you take a look inside the api you're going to see we get two three fields like user id

9:56:40id title and body right so what we can say is that hey i just want to have a post dot title right

9:56:51and the the key which you can give it is probably post.id because it seems like it's unique

9:56:58so you can say post.id and there you go so now you have all these posts and all these titles and you

9:57:04can also have you know a post or id right here just so that we have a small number or something

9:57:12like that in front of every single post right so that's that's done so we have our post on the page

9:57:22but we also want to link them right so what i can say is that instead of a paragraph tag or

9:57:27you know maybe we can keep a paragraph tag we can also give it an ahref so that we link it to some

9:57:33place on our um you know on our screen so either you can go ahead and create a different route

9:57:41a different component which will require us to install you know react router and stuff like that

9:57:46which i would probably not do because this is a tutorial focused on react query but

9:57:51you can do that so either you can just go ahead and redirect the person to a post id

9:57:56or what we can do is just stick with the official documentation example which is available right now

9:58:01and just do it in place so although we are doing it in place that means whenever somebody clicks

9:58:08we're just replacing the post into the same component but it is like i said it is completely

9:58:13possible to do it in a different route as well you just have to redirect that person to a different

9:58:18route and get the post id from the url instead of the state which we'll define here

9:58:23so what i'm going to do is i'm going to call a state or you know post id set post id and

9:58:29i'm going to say it equal to you state null for example we're going to start with null right and

9:58:36what i'm going to say is that whenever i click on this a anchor tag we set the post id to post or id

9:58:45right so now whenever i click on let's say this or this or whatever if i just go ahead and say

9:58:54you know if i just go ahead and say if post id is not equal to null

9:59:02then i just want to return h1 active post is post id right so what's happening here is now if

9:59:12i click on five you can see we get active post as five refresh we have to refresh because we can't

9:59:17really go back because we are making changes in the same component active process nine and so on

9:59:24all right so once we have done that how do we display the active post now

9:59:30so to display the active post what we can do is we can create another component so we can say

9:59:36post and then you know post id as post id right and that's it now we can go ahead and create a

9:59:44new file that will just make things a little bit easier to see so we can say post.js6 and

9:59:51this right here we're just gonna have import react from react i'm going to say const post is equal to

9:59:58we're going to have a post id sent to us and i'm just going to say export default post as well

10:00:04right so now if we just close this and if we import our post from

10:00:12you know post i hope that will work yup and i just say return h1 post id is post id

10:00:24you would be able to see that now if i click on four we get post ids4 so fantastic that's working

10:00:32now what we want to do is we also want to say a reset post right or maybe like go back

10:00:39something like that so what this go back just does is that it sets the post id to null again

10:00:45so that we have all our post visible right so what i can say is that hey this is a div

10:00:52which we return and i can just say hey this is fine but whenever somebody wants to go back

10:00:59we can just say on click go back which is again something which we get from the props

10:01:07right all right so now if i click on this if i click on go back perfect so it's working we have a

10:01:14dynamic post id available in a component and it's also working now the question is how do we get

10:01:21more data about this post itself right what we can do is we can make use of use query again inside of

10:01:29this component because you know that's that's where the true power will lie that we can use

10:01:35use query multiple times in different places so what we can do is we can define another use

10:01:42query hook i'm going to say use query and what i'm going to do is i'm going to say this is basically

10:01:50you know we wrote posts here i'm just going to go with single post and i'm going to specify

10:01:56the post id now this is important because here like i said in the previous videos as well here

10:02:02the post id is actually dependent uh the queries result is actually dependent on the post id right

10:02:07so i'm going to use the same fetcher because it will just work

10:02:11we get the fetcher right here and that's it we don't really need a third

10:02:15solution or anything so we extract the data we extract there is loading as well and we just say

10:02:22if is loading we have a return loading or you know just loading post something like that

10:02:32now what we want to do is we want to say that once we have actually first of all let's see

10:02:39how the fetcher would work because this is the wrong implementation the way we want to say is

10:02:46that it should fetch this url which we have with us of posts so if i go ahead and open this you see

10:02:55we get a single you know long list of array of all the posts but if i go to post slash let's say 22

10:03:03so this is the post id right so now we get just that single post with us now technically does

10:03:10not really make a lot of sense because you know we already have title and body but just imagine that

10:03:16if you had some more information or some more metadata which you could display in the post

10:03:20because most likely you will if you're creating your own personal blog you will have some more

10:03:24data right here now what we can do is we can make use of this inside of the feature so i can say

10:03:31something like jsonplaceholder post and then the post id now this is important that you're using

10:03:38this in the url obviously for obvious reasons that you want to fetch that data but that is also

10:03:44important because you know as a dependency in the use query hook because when it changes we want it

10:03:49to change as well so now what we can do is we can finally say uh data dot you know whatever we get

10:03:57title and then we can also say p data dot body right so now if i click on this one which has this

10:04:08title use query is not defined very well import use query from react query

10:04:18click loading post boom right we have the title we have the body go back click loading post boom

10:04:24title body go back click loading post boom title body go back now if i click on this one again

10:04:33you're gonna see boom we have that already loaded in although it was stale i agree although it was

10:04:40still and it faced it again under the hood but you did not see that happening because you already had

10:04:46some form of cache available um anyway right so that's that's that's awesome 33 boom again done

10:04:55so yeah i mean this is this could be pretty much you know a regular different page as well right

10:05:00now we have just hacked it into a single component but you could just very well be redirecting it to

10:05:05you know some slash post or something like that and then this post id would be getting

10:05:10from the url not from the prop inside of this uh component but you get the idea right

10:05:22hey everyone welcome back and in this video and actually in a few videos now we're going to be

10:05:26discussing about how you can interact with the react query cache right so as a developer you

10:05:32know i know that when i have clicked on three and i go back and when i click on this three again we

10:05:36will not make the request i mean we will but not immediately and won't show any loading but

10:05:42how do i for example modify the cache or you know just get ahead of time what it is maybe

10:05:48i want to get it for some reasons so the way you do that is by accessing this little thing which we

10:05:56created earlier right so this query client right here is the thing so what we can do is we can

10:06:04just go ahead and create a react query client dot js something like that and what i can say

10:06:12is that hey this little guy or uh you know this statement right here is this and i can just

10:06:21say export default client right and we can just have import query client from react query right

10:06:30so not now what we are doing is the purpose of this is to have a single ton representation of

10:06:35this client so that we are working with the same client when we import it other places

10:06:39so what i can do is i can go ahead and say client like this but i need to import

10:06:47the client from react query client right and once we do that you would see that it's basically the

10:06:58same thing in the browser preview nothing has really changed but you can now also access

10:07:05the query client inside your app.jsx for example i'm going to tell you why this matters so we have

10:07:13client from react query client right and remember this is the same client which is being used

10:07:21by the react query client provider that means whenever you are using use query whatever data

10:07:27it is fetching it's actually linking that somehow to this caching uh this query client provider

10:07:35so what you can do one interesting thing you can do with this query client provider is you

10:07:40can fetch and see what is available inside of the cache right inside of the cache system right

10:07:49now all right so the way you would do that is you will say let's say cached post is equal to client

10:07:58dot get query data now this that quit query data is something which will give you a sneak preview

10:08:06inside of what's happening and the first argument is just like use query it's a key so for this one

10:08:14i'm going to give it a post because you know we obviously know post is there because of this

10:08:18thing but post and then the id of um whatever it is that's that's what we want to get right

10:08:27that is is that post cached right so we can have like let's say just five as the id at the moment

10:08:35right so if we have this if i do something like console.log cached post and then

10:08:42cache post something like this if i do like this and if i refresh this page right here you're gonna

10:08:49see in the browser logs we have the cache posts and us as undefined which makes sense because

10:08:55you know we have not really fetched this number five yet but if i click on this now right and

10:09:00if i go back now you're gonna see that we get the cash post so this means that get query data would

10:09:08actually return you undefined if it is not present in the cache but it will give you something back

10:09:14if it is right and obviously it will just give you back what is present in the client

10:09:19this is useful this is helpful because now you can get ahead of time uh you know you can not

10:09:25only just fetch data into the cache which we'll see soon but you can also get the data out of the

10:09:31cache as well so what you can do one thing i can think of is you can go inside this render function

10:09:38and you can say something like you know if the cash post is there then i can just say visited

10:09:48otherwise i just say nothing right so this just means that hey if the cash post is already there

10:09:55that means this value is not undefined we will get a visited otherwise we get nothing

10:10:01and you could see this is actually not working because we are getting all the visitors because

10:10:06well we have visited five so we want to replace this with post.id and now it works like clockwork

10:10:12we get visited only on the post 5 maybe you can you know if you want you can just take it out

10:10:19so that it it does not appear as a hyperlink or something

10:10:22but it's your wish so there we go so now if you have this you can see you get a visited in bold

10:10:33and then a link otherwise you get nothing so if i click on three go back boom right four

10:10:42go back boom and it knows that we have visited because it is present in the cache 19 go back

10:10:49and boom right so you'll also have that on 19. so yeah that's how you get something from the cache

10:10:57and you can pretty much do anything you want i mean if you just import this

10:11:00um right here and try to do a cache uh check it wouldn't really make a lot of sense because you

10:11:08know you would be running the hook eventually so why would you want to extract it but you know if

10:11:14the use case is there that then you know that it's possible right and programming

10:11:19most of the things you know we are watching these videos you are watching these tutorials most of

10:11:23the things are not for you to just go ahead and implement immediately but they're mostly for you

10:11:28to just know that they exist so that when you need them you at least know that these things

10:11:34exist and you can take a look at documentation or these videos or any other text later down the line

10:11:40so yeah that's pretty much it for this video i hope you understood how

10:11:43this get query data is working from the client how you can abstract it away

10:11:49and yeah that's that's super helpful in a lot of cases

10:11:57hey everyone welcome back and this is a good time to discuss about a parameter called cash time

10:12:04so cash time in react query is used to determine how long your query result will be available

10:12:11in the cache and this means that whenever let's say somebody you know in in this case you visit

10:12:18a page or you visit a component you get a split second loading and then this loads but you don't

10:12:24get that again right so for how long will you not get that loading again that means for how

10:12:30long will it keep it inside its cache that's what the cache time parameter determines right

10:12:36that when something becomes inactive that means you know when this component is not mounted

10:12:41this use query hook is inactive then how much time will it keep the cash will it keep the results

10:12:48in the memory right because obviously it does not make sense to keep it forever because

10:12:53well you know you probably want to free up memory a little but you can customize that by using a

10:13:00cache time parameter right so what i'm going to do is i'm going to set this parameter cache time

10:13:07to let's say 0 right and when i do that and if i refresh this you're going to see what we have done

10:13:13is we have set the cache time of this every single post to zero that means when i click on this

10:13:19i get that loading for a split second i go back and if i click on this again you see we still

10:13:24get that loading right so what you were able to see was that it was no longer present in the

10:13:29cache although it says visited here because when i click back for a splits again it is present in the

10:13:36in the ui but it let's if i click on this number two and go back you can see it's gone the it is

10:13:41gone from number one right because the cash time is zero and it is immediately destroyed as soon as

10:13:46this post is unmounted right and you will always get that uh split second loading which you see

10:13:54right you might not be seeing that that much if uh that is an issue what we can do is i can

10:14:02just go ahead and throttle my request to slow 3g and now if i click on this you can see we

10:14:07get the loading post i go back and if i click on this again you see we get loading post again

10:14:13so this is what happens right i hope that helped you understand how the cache parameter is working

10:14:24hey everyone welcome back and in this video let's quickly take a look at query data selector in

10:14:30react query which is a relatively new feature so you won't find it like in in previous versions

10:14:36of react query and what this essentially means is that you know it's nothing fancy as such but

10:14:42the ability to modify the response of the query or transform it somehow what do i mean by that

10:14:50let's go to the app.jsx and right here inside of the third argument which is like you know

10:14:54the options argument for us what i can say is i can pass in a select here and what this will do

10:15:01is that it will allow me to transform the result of the query so what do i mean by that you know

10:15:06we are we are getting post right initially so all we get all the posts so what i can do is i can say

10:15:12post or do you know result whatever you want to say it it's just a anonymous function and i just

10:15:17say result dot slice 0 to 5 for example and you can see immediately what we saw is that we just

10:15:26get first five results here and if you console log it in fact if you try to console log it if you

10:15:32console log the post here you're gonna see that in the browser you know not really post post.length

10:15:39you're gonna see in the browser you always get five post right now if i changed it this two to

10:15:45six you're gonna see we start getting six posts right now what does this mean is that you know

10:15:50you can surely write dot slice here if you want but react very just gives you the ability to pass

10:15:56in a function which can transform your results somehow before your component actually consumes it

10:16:02it might be super useful if you want to just keep your component level thing clear and if there is

10:16:08a transformation required but if not well you can just bounce it off but like i say for all

10:16:13the things i say that you should know that this exists right so you have result dot slice maybe

10:16:18you can just do a result dot slice zero two one just get a single post right you can do probably

10:16:27you know one two two whatever you know you can just play around with this

10:16:32and get a single post so this basically gives you the ability the superpowers you know you can just

10:16:38return the first post as well in this case it will crash because you know we are trying

10:16:43to map over this but now this is just a regular post so your call whatever you want to do right

10:16:50this will fix it but you know you get the idea this is similar to like how the slice would work

10:16:56but yeah that's pretty much it for this video i hope you understood how the selector thing works

10:17:06hey everyone welcome back and in this video let us just go ahead and take a look

10:17:10at what set query data does now if you remember a couple of videos back we looked at what get query

10:17:17data does and you know that's how we implemented this visitor thing you can see right here now just

10:17:24like get query data allows you to query the cache of the react query and extract it out

10:17:30set query data actually allows you to do something but opposite right it allows you to overwrite this

10:17:36cache or update this cache if you want to say that so what we can do is right here with this

10:17:43anchor tag being done what i can say is button and i can say mutate the title for example right and

10:17:52i'm just going to say that you can see we got this muted the title button with every single thing now

10:17:56and what i'm going to do is i'm going to say on clicking this i just say hey mutate title

10:18:04and post.id right let's just take it out of this function it's already getting too messy i'm going

10:18:09to say function mutate title and right here i'm just going to receive an id right so what i'm

10:18:15going to do is first of all let's just alert this so that we are sure that we have the right id 1

10:18:215 awesome so we have the correct id now the next thing i want to do is i want to make use of

10:18:27the same client which we had and i want to say client dot set query data right instead of get

10:18:36get query data and what this does is that it takes the first key as the query key like you know the

10:18:42first argument as the query key so we know that this is post and then post id right and the next

10:18:48thing it does is that it takes either new data as the thing or just like you know use state

10:18:55works you know that you states handler can either take the new data or it can take a function which

10:19:01has the old data as the first argument right so it can do that so we have the old data first right so

10:19:07i'm just going to go ahead and first of all try to just console.log yeah maybe this console log

10:19:13if all data exists right something like this so let's just go ahead and keep it a little small

10:19:21give it a refresh because you know all that cash is already present there so if i click on this

10:19:25muted the title we get post is not defined and that is because you know we just have to write id

10:19:31here not everything so if i click on this you can see that we are getting undefined in the console

10:19:37right like right here keep your focus here if i click on this we keep on getting undefined so

10:19:43this means that hey this is you know the post is not present in our cache right so that's that's

10:19:49that's all it means that it is the source is not present so if i click on this okay you cannot read

10:19:57property title of undefined let us see what went wrong so we have is loading data.title

10:20:10looks like we are missing something said post id hmm looks like a network request error most likely

10:20:20let's try this one more time click on this yup looks like some some network error or something we

10:20:26should be handling you know network errors as well i'll go through that how we can do that but anyway

10:20:32now you can see that i've got the title i've got the body if i go back now and if i click on

10:20:38this mutate the title you can see now we have the post as the console logged right so there's that

10:20:44so what i can do is right here i can say if all data is in fact available i just want to return

10:20:50um you know old data and i just want to say title is

10:20:58boom boom mutated i have no idea why i went with that this is completely random but uh yeah let's

10:21:06do that so i'm gonna click on this and looks like this is something different probably um

10:21:18not exactly sure if this is some this is a cache problem from react query or you know

10:21:25something related to that but let's see if that happens again i'll just pause the video and see

10:21:30it for once and get back to you but anyway if i click on this now we get this go back i can mutate

10:21:36the title so hopefully has done it hopefully has set the title as boom boom title and if i click

10:21:43on this again we get that go back mutate click on this again you see for a split second we do

10:21:50get boom boom title right but it gets replaced after that so what i can say in order to not

10:21:56make it replace is i can say this tale time is infinite infinite infinity right and what scale

10:22:06time means is just like we have cash time which keeps it in cash the stale time just means hey i'm

10:22:11not going to refetch it um considering it's not stale that is you know considering it's out of the

10:22:17screen or you know uh by default the scale time is zero we're going to discuss that in the next

10:22:22video pretty much but for this video if i take the stale time as infinity and if i click on this now

10:22:29go back mutate the title click on this again you can see we get boom boom mutated right this time

10:22:34because tail time is infinity let me just actually discuss tail time in the next video in depth real

10:22:39quick so that you guys are not lost but anyway you can go back you can start seeing stuff now

10:22:44if i click on this you're gonna see we get this go back and you know if i mutate this click on this

10:22:51again we get boom boom mutated and bonus points to you if you can guess why the title here is

10:22:58not changed title here is not changed it's changed inside this but it's not changed on the out front

10:23:05can you guess why well of course you should be able to guess that that is because

10:23:10posts is a different key than post and then the post id right hopefully you were able to get that

10:23:18although the titles are same in both the cases when of course they are same

10:23:22but in this case we are modifying the post id as the key right using set query data

10:23:29this is being i traded on post which is this key right here in use query so if you modify the post

10:23:35key right here then it will make some differences right so yep that's pretty much it for this video

10:23:43let me quickly jump to stale time as well in the next one so that we are on the same page

10:23:52hey everyone welcome back and in this video let's just go ahead and take a look at what is stale

10:23:59time and what are the differences between stale time and cash time so first things first let's

10:24:07let's understand the fact that react query starts with a stale time of 0 as a default

10:24:13value and a cache time of i believe 60 seconds no not 60 seconds actually 300 seconds that is

10:24:215 minutes so these are the default values react query uses for you but what do they mean exactly

10:24:27so let's see that so first of all about stale time what stale time means is that whenever react query

10:24:36fetches a request whenever react very completes a request that is the data is available and you know

10:24:41it's done and dusted what it will do is it will start a counter inside it and it will count it

10:24:48to steal time right so if your scale time is 1000 that is thousand milliseconds it will start the

10:24:54counter 2000 that is you know for for one second and then it will mark the query as stale so what's

10:25:01going to happen is once your query is fetching it it is into the fetching state it moves to the

10:25:08fresh state and then once that stale timer hits it moves into the stale state let me tell you

10:25:14how this works let's say i have a scale time of 10 seconds on every single post request let me just

10:25:18give it a refresh real quick um we have the cache time as default so don't worry about that let me

10:25:24click on this and you can see it fetched it for a brief amount of second and it is in the fresh

10:25:31state for 10 seconds right it's going to stay there for 10 seconds and you can see once it

10:25:37110 seconds are over it moves to stale and you can you know even take a look again if i refresh this

10:25:43if i click on this you see this post one is green for 10 seconds and once these 10 seconds are

10:25:50over it will move to the stale state right yep there we go so what's happening here is for 10

10:26:01seconds it will not go ahead and refresh the query in any case now what are the cases the

10:26:10cases could be if i click on this the mount the second one is refocus you know like we used to do

10:26:17and the blue uh request which you see is of the post request right it's not the post one because

10:26:22it still is fresh right that's why now you can see if i refocus it again both of them would

10:26:28be served and this one again gets fresh so you can see refocusing uh you know unmounting and mounting

10:26:34that will not happen so if i change it to for example 20 seconds and if i go ahead and you know

10:26:41just go ahead and activate that mutate function which is already activated and now if i refresh

10:26:47what's going to happen is that if i click on the title you know quickly go back mutate the title

10:26:54and click here also before getting into that one bug which i discovered is the cache time that's

10:26:59actually 300 milliseconds not 300 seconds so let me just go ahead and remove that

10:27:03and what i'm going to do if i go back here refresh this

10:27:08and if we click on this quickly go back mutate the title and go to the again this post again you

10:27:15can see we get boom boom mutated but as soon as 10 seconds are over and the query is marked as stale

10:27:22let's see what's gonna happen so nothing is going to happen as such you know once 10 seconds are

10:27:27over so you can see let's see the query is still fresh i think it's 20 probably yeah it's 20. so

10:27:35you can see now the seconds have passed and now if i click on you know for refocusing you could see

10:27:40that react query saw that hey the query was stale so i'm going to re-fetch it right so this is how

10:27:47stale time works if i go back mutate this click on this and now if i go back and you know just

10:27:53visit this again and again over the time until and unless this query has been marked as stale it's

10:27:59not gonna be re-fetched right you can see nothing is happening to this but the moment it switches

10:28:05to stale it's gonna be re-fetched by the browser this is super important this is super critical to

10:28:10understand you can see now it will be refished that's that's you know that's that seems like a

10:28:15good choice if you think about it now what about the cash time so the cash time is pretty much what

10:28:24for how long it should even keep the stale data in memory that is that is cache time right all right

10:28:31so now try with let's try this with a cache time and still time both of zero right so if i click on

10:28:37this now you can see it loads for a split second and then um you know it's just available for you

10:28:44then you can go back and click on this again and you can see it still loads back again for you

10:28:49you get that split second loader so this is what cache time did if you had a cache time of you know

10:28:54fairly large number like infinity or you know even five minutes which is like the default you will

10:28:59see that if i click on this go back if i mutate the title and if i click on this now you get that

10:29:05boom boom thing you know that that cached value but you know you did not get the loading indicator

10:29:12that's what the cache time is that will keep this keep displaying you the stale value refresh it in

10:29:17the background and replace it once it's ready but if your cache is expired well then you know your

10:29:23query is just as as fresh as a new query right so yeah that's how the cache time and still time

10:29:32work together i hope this gave you more clarity on what stale time is super useful parameter um and

10:29:39you know the use case really depends on your use case or what you're trying to do but yeah for the

10:29:45most part you can push a little bit of higher value on still time right you don't want to be

10:29:50too aggressive on on data which is available on your front end but yeah like i said again depends

10:29:56on your use case so yeah that's pretty much it for this video i hope you understood something

10:30:01let me know what you think about this in the discussions below on the codename website

10:30:11hey everyone welcome back and in this video let's just quickly take a look at how you can

10:30:15modify the stale time cache time and any other parameter value which we have seen and we'll see

10:30:21at a global level as well right because let's say if you don't want to do it on a per query level

10:30:26but actually for every single query how do you do that well the best way to do that is actually go

10:30:31to your app.jsx or you know whatever not exactly app.jsx but where you have defined the query

10:30:37client provider right and right here you will see the client which you are passing and we are

10:30:42using an external file so what i wanted to do is i want to create a an object which i pass here with

10:30:50the first key as default options right and this default options is basically just gonna be you

10:30:56know just being merged with the all the options which are available and they will act as a default

10:31:03base for you to start so you can say like stale time as infinity you know and basically get the

10:31:10same behavior which you were getting earlier that will not re-fetch it again so if i go back click

10:31:16on this again you know um oops and made a mistake this should also have a query right here and we

10:31:24also have something known as mutations in react query so i'll come to that but now you're defining

10:31:29the default options for queries only queries right so if i refresh this again click on this go back

10:31:36and can you believe that i made us made the same mistake two times in a row this should be queries

10:31:42not query so if i refresh this now you can see uh the queries are now always green right once they

10:31:48are fetched if i click on this you can see these are always fresh and they'll never go to stale so

10:31:53pretty much you are locked into an application which is never gonna be updating itself again

10:31:58um you know unless the cash expires of course um but yeah they will not refit to the back end

10:32:05unless and until the cash expires so that's it and if you want if you want to go like total insane

10:32:11mode you can also set cache time as infinity and now you have got a truly truly weird application

10:32:17which will never really contact server ever again once it has you know visited once which might seem

10:32:23like something you might want to do but not really i mean why would you want to do that um i wouldn't

10:32:30i wouldn't recommend that right so you should keep saying values i mean still time infinity

10:32:36still might make some sense i don't know but cash time should be a finite value according to me

10:32:45alrighty so that is pretty much it how you can customize default options

10:32:50i'm gonna see you in the next video where we will discuss more stuff about

10:32:53react query building projects doing something more interesting with it

10:33:02hey everyone welcome back and in this video i want to discuss about mutations in react query and what

10:33:09they mean so we have so far just seen how you know use query hook works but there's a there's a

10:33:17there's a important thing which we have not discussed yet this architecture assumes that

10:33:24we want only the data from server number one and number two is that we want only the data

10:33:29whenever you know the component mounts but this is usually not the case right if you have a form

10:33:35or if you have some sort of interactivity where the user clicks on a button and then the data

10:33:39is fetched i mean in case of this we are just you know just changing the link uh changing the whole

10:33:45component but if you have something like that then what happens so in that case what we can do is we

10:33:52can make use of mutations in react query and i'm just going to get rid of all the code which we had

10:33:58just to keep things a little bit cleaner and what i'm gonna do is i'm gonna throw in a p

10:34:03tag here as well just because i feel like it and i'm gonna start with a new mutation

10:34:10and i'm gonna say this is use mutation and we're gonna get this hook from um you know from the same

10:34:20library obviously right react query and what you want to do is inside this used mutation you want

10:34:28to pass in a function which returns you a promise again right so i'm going to pass in this fetcher

10:34:36and i'm going to say you know whatever it is you can say a fetcher or i can just say you know

10:34:41a timer so i can say you know duration and new uh promise resolve which just sets time out and

10:34:53don't be afraid if you don't understand anything but this is just you know just a fancy way of

10:34:59making a timer await right so this is a promise which just results after set duration that's it so

10:35:05i can say this timer and after one seconds right so expected identify with function what the hell

10:35:16anyway so you can you see that you know we have a mutation now with us but if you take a look

10:35:20at inside the dev tools what you will not see is that you know there are no queries at search

10:35:26and also this mutation has not run and how do we know that we can just you know just see that um

10:35:34if we have console log for example i was run something like this right and if you go to

10:35:40browser you can see that we do not get that we do not we do not have a i was run console log here

10:35:46that means the mutation is not run when it is defined and it makes sense why because the idea

10:35:55of a mutation is that it mutates the state on servo right it mutates either some database

10:36:02it mutates something right at the end of the day you know this is just a convention this is

10:36:07again calling just an api endpoint in this case we just have a promise which resolves after a couple

10:36:12of seconds but this would ideally call something like you know slash api create post something like

10:36:19this for example right and then you know whenever you have a summit button here you would say p on

10:36:25click um run this mutation somehow and that's it that's that's how you get event paste requests now

10:36:33so how do you run this well what you can do is you can just create a function called mutation

10:36:39and right here we can just say on click call mutation and i can just you know tease you a

10:36:46little bit more by saying console.log about to call mutation mutation right and if i click on

10:36:55this you can see in the console we are getting about to call mutation wrong right now how do we

10:37:00call the mutation exactly is we say mutation dot mutate async and we're going to start with async

10:37:09right here right and there are a couple of methods but that's that's one way to go about

10:37:14so what i can do is i can refresh this i can click on summit and you can see that we get

10:37:21i was run right here and actually let me just go ahead and move this i was run inside of

10:37:27the promise which is resolved right so that we get that um actually not even here we want to

10:37:38add it right here once it resolves right kind of so if i refresh it now

10:37:44you're gonna see that now if i have you know console.log mutate async

10:37:52called if i have something like this and if i click on this you're gonna see we get about to

10:37:56call mutation mutated async called and then i was run after a couple of seconds right

10:38:02now the good thing about mutate async is that you can await on this that's that's why async is there

10:38:08right so if i create an async function out of this and if i call await on this what you're gonna see

10:38:14is now if i click on summit we get about to call we get mutation oops looks like we need to give it

10:38:20a refresh again oh i think we are not returning this promise that's why all right let's do that

10:38:28and now click on the summit you can see about to call mutation i was run gets called from here

10:38:34and then we call this mutate a6 so it could be something like you know you are updating the post

10:38:40so you can have updating post as a notification and then you can say post updated something like

10:38:46this right assuming that you know your request is your request is successful but there are a couple

10:38:53of more things we have with mutation not just muted async you can have a mutate only function

10:39:00which we'll discuss in the next video but yeah that's how you can do some event based trig ring

10:39:06and you can see pretty much nothing appears in the react dev tools because of the reason that

10:39:12you obviously don't want to cache mutations why because like i said mutations is an idea

10:39:20that something is changing on the server and you don't want to cache that result you don't want to

10:39:25you know just rebroadcast it again at some interval sometime because these are like

10:39:30you know these are actual systems which will be affected think about somebody who just you know um

10:39:37tried to log out sometime and then somehow that that cache was invalidated and your application

10:39:44automatically logged them out right in case of fetching that mutate muted async endpoint

10:39:49so that that should not happen right so that's why um mutations do not cache they do not

10:39:55you know they do not work like typical queries work and they are usually driven with events

10:40:01from users endpoints like on click and stuff like that or form summit or anything like that

10:40:11hey everyone welcome back and in this video let's just go ahead and take a look at

10:40:15side effects from mutation and side effects is just a you know a fancy way of saying

10:40:20some sort of callbacks from mutation so what is it and how does this work well the first thing

10:40:27is that you can pass in an object like this which is inside of use your use mutation hook now you

10:40:34can start defining some good stuff but that what i mean is you can say something like on success

10:40:40as a callback and this could be a function which will just be called when request is complete for

10:40:48example right now if i click on this submit you can see we get update post request is completed

10:40:54and then post updated so basically what react query internally is doing is that once the request

10:41:01once the mutation is successful it internally also calls these on success this on success handler

10:41:07right and not only just this this actually gets a bunch of things so it gets not error actually

10:41:13it gets data and it gets you know variables and context as well which we'll discuss later down

10:41:20the line but most importantly it gets data so what we can say is if i do data console.log like

10:41:26this and if i click on summit now you're going to see we get updating post request is complete

10:41:30we get data as undefinable because we are not passing anything in the resolve but let's say

10:41:35yo is what we passed right and give it a refresh because probably this is outside the function so

10:41:41might not get hot reloaded click on summit updating post request is complete data is yo

10:41:48and you can you know access it here as well if you want and you know move ahead with your life so

10:41:53you can pretty much drop this at all if you just want to keep your side effects at a single place

10:41:58but that's how it would work then of course you also have on error with this which will

10:42:03accept first argument as error and if there is any error then this is what's going to happen

10:42:09right so it will just say error with the request and we can just throw an error what we can do

10:42:16is to simulate that i'm just going to have a reject here as well and i'm going to reject it

10:42:21with yo again right so now if i can click on this updating post we get i was run we get the error as

10:42:28you you know this this was this error is actually thrown by javascript because you know we are not

10:42:35using try catch but what the console.log says us in the on error we get error with the request

10:42:41and we get the error as yo right so you also get error you can also get error handling but

10:42:48unsettled which is another one is something which will run every single time so it will just say

10:42:55you know request either errored or successful i don't know but it has happened right

10:43:03and of course you can know because onset will also receive state and error as uh a couple of

10:43:09arguments if you want to do that right so this data is basically if on success was there error

10:43:14is basically if one error was there and so on so this is how you can maintain your side effects

10:43:21like this inside of your mutation hook itself sometimes it might make

10:43:26sense to do this sometimes it might not right um depending again how your component is laid down

10:43:33your component is structured you might want to do that but one thing which i know is that uh

10:43:40when you combine like on success mutation with something like you know query dot query client.set

10:43:47query data stuff like this this becomes a very useful thing because now your ui can automatically

10:43:53update refetch new data after a mutation is done which is pretty sweet uh we'll discuss

10:43:59on that what i mentioned by that in more practical examples stated down the line but yes for now that

10:44:04is pretty much it i think that is all for this video i hope you understood something out of it

10:44:14hey everyone welcome back and in this video i'm gonna discuss you discuss with you the syntax of

10:44:19dot mutate so earlier you remember that it was mutate async but we also have a just a mutate

10:44:26as a function available on your mutation and this one is not asynchronous in the sense that it does

10:44:33not return you a promise well it is asynchronous because it has got callbacks but that's that's how

10:44:38it works so when you call this for example if i refresh this and click on the submit what you will

10:44:45see is if i click on summit you get post updating post post updated because you know this is not

10:44:52awaited so it does not wait for that and you know you get all sorts of logs and errors but

10:44:58what you can do is you can also pass in um a bunch of options just like how you pass in

10:45:04in the used mutation hook and i have passed null here i'll explain why because we don't really need

10:45:12the data right here but i'll explain it why we have passenger layer and what could we have passed

10:45:17but for now if i have the same thing as above what you're gonna see request is completed from mutate

10:45:26you know error with a request from mutate and from mutate right just to make a distinction

10:45:33and now if i click on summit you will see we get you know the same things request either error or

10:45:39successful this is basically from the original hook and we get error with the request mutate

10:45:46so that's it and error with the successful mutate right so one thing you can understand is that the

10:45:52react first of all internally calls these before calling the actual ones right on on the mutation

10:45:58itself and that is important if you care about order or something but for the most part you

10:46:04should not have a code that relies on that thing but yep that's that's how you have to work with it

10:46:11the next thing i wanted to discuss is why do we pass null here well this argument could be

10:46:15anything right you can have 22 here that's that's completely fine whatever you pass in here is

10:46:21actually available as a param right here so if you have you know like a second argument which passes

10:46:28some data and you get a second argument like pattern like this and if you can say you know

10:46:35yo and then whatever the pattern was you will just see that if i click on summit now we get

10:46:41um you know this outer function does not update on hot reloading so we have to give it a refresh

10:46:49submit now and you will see error oops i think it is not updating anyway oh we are using reject

10:46:57not console.log oops so this should be right here and maybe it does update let's see summit

10:47:04um i was run whereas i was running yeah it gets updated so you can see the pattern was past 22. if

10:47:11i change it to like you know something else click on summit you're gonna see that in the i was run

10:47:17we get the pattern as updated so this mutation is just a you know this argument is just one way of

10:47:23transferring some data to your actual handler which is something you would obviously do right

10:47:28you won't just run a mutation without any state you would probably have some sort of form data or

10:47:34some sort of new post some sort of json which gets passed here which gets passed again here and then

10:47:40you know in your fetcher or whatever you're using you just json dot stringify it and so

10:47:45on and so forth so that's how it will work right and similarly it will also work with muted async

10:47:53you know this not this exactly but this part which where you have to pass the

10:47:58data so even if you have something like this right here and give it a refresh

10:48:04and you know just click on summit you're gonna see that you still get the patterns as correctly

10:48:10right so yeah that's pretty much it for this video i hope you understood how mutations are working

10:48:16how muted async work how you can pass some data how mutate only works how these side effects work

10:48:22super important stuff super practical stuff which you will obviously use when you're building some

10:48:27new applications some new projects um and yeah very very very standard stuff and very

10:48:34high quality things as well these are like you know standard practices for calling mutations uh

10:48:40some calling something as mutations for updating data queries as different things and so on and

10:48:45so forth so you will you can use this all of this knowledge in production level applications

10:48:55hey everyone welcome back and in this video i want to give you a real

10:48:59real use case of using mutations with the help of queries but for that we have to write a

10:49:05very simple node.js server and i'm going to do that all in the code down playground itself so

10:49:09feel free to follow along with me or you would probably have an exercise like that in in some

10:49:14one way or another so what we're gonna do is i'm gonna have a mutation right here which has

10:49:21all of these handlers and you know we can just get rid of unsettled for the most part and what

10:49:29i'm gonna do is first of all define a fetcher function like this which gets a url and then

10:49:36doesn't fetch of the url with a method of post right and probably like url and body because this

10:49:46will be used with the use mutation we're gonna say headers is content type this is something you have

10:49:52to do with you know fetch request application json then you do a body of json.stringify of the body

10:50:01right and that's it that should get you started now once you have this fetcher i can define this

10:50:06feature and i can say this is like body and i can say um you know the url is something like api dot

10:50:15create record something like this and the body is of course the body right on success we have

10:50:24you know got response from back end and the data and on error we pretty much have the same thing

10:50:34got response from back end but the error got error from back in right just to distinguish it

10:50:42now what we can do is pretty much you know get rid of this even get rid of the async

10:50:49away thing we can just say mutation.mutate and with some body whatever we want to pass

10:50:54in but before that what i want to do is i want to say some are you know some favorite languages

10:51:03right let's say that is it now what i want to do is i want to say let's see

10:51:10first of all let's just close this up let's refresh this guy and let's say that hey

10:51:19here are my favorite languages and i'm going to have favorite langs dot map language and you know

10:51:26just returning an li or flank right with a with probably a key of lang as well

10:51:36and this should probably be lank not lan and one the only error now we get is that favorite

10:51:42language is undefined so let's create a query as well so i'm going to extract out the data

10:51:48as favorite lang i'm going to say use query right here and what i'm going to do is i'm going to use

10:51:55the query as you know the key as favorite langs and the fetcher we could either define the fetcher

10:52:02or you know i can just return fetch here because it's just a single query api get records and

10:52:11dot then t d json to convert it into json and that's it that's pretty much it right

10:52:17because now we just have to define this very simple server and we'll be up and running so

10:52:22what i'm going to do is i'm going to split this terminal real quick um i'm gonna create a very

10:52:28simple server.js file right here right and i'm gonna just open this install express real quick

10:52:37and i'm gonna start importing stuff right so i'm going to just say const app is required express

10:52:44and this is we this is going to be just a very simple server so don't really worry a lot about

10:52:49this so app.listen here we have to do a little bit of hacking in this playground interface for now

10:52:56i'm going to tell you why that is so i'm going to just give it a refresh app.listen1337 because this

10:53:03is the only publicly available port you should probably not face this issue on your local setup

10:53:09because you would have multiple ports available but because this interface is just connected to

10:53:14a single port right here that's why we have to use just one three three seven and i can

10:53:19just say console.log so so started on one three three seven right and i'm just gonna say app.get

10:53:29um you know right here what we had api slash get records app.get this

10:53:41i'm just gonna respond with request response i'm just gonna say response.json

10:53:47favorite langs and i'm going to say app.post right here with api dot you know add record i think

10:53:56that was it i'm going to first of all get the record from request.body.record

10:54:04and then i'm just going to say rest.json status okay

10:54:09but before that i'm also going to add it favorite langs dot push record right and

10:54:15i can just say my favorite lens is an array which is like html css javascript and react

10:54:25right so what you can say is like you know langs here as favorite lens something like that

10:54:34already looks like we are all good to go so what i'm gonna do is first of all

10:54:41you know um let's see first of all fix our front end so that we don't exactly need a

10:54:47back end because we can we cannot use this port and the server together so what i'm going to do

10:54:53is right here make a bunch of more changes so i'm going to say

10:54:59right here i'm gonna say if is loading or if is error i'm just gonna say if is loading return

10:55:11loading dot or dot right or if there is an error is error return you know error with request

10:55:24simple enough right now if i go ahead and close the server and if i start the server of server dot

10:55:31js what you're going to see is that we still get well we still get favorite langs dot map is not

10:55:37a function and that is pretty not pretty awesome because what we would have in this favorite length

10:55:45is actually the response like this lang and then favorite line so what we can do is we can actually

10:55:53go ahead and close this and this is this is a little inconvenient at cooldown playground but

10:56:00you know right now it just supports a single port forwarding that's why you can only get access to

10:56:041337 uh on a single port but what we can do is we can go ahead and write here just write you know as

10:56:14a third argument select remember we discussed this data and i'm just going to say data dot

10:56:22lags right because that's what we are returning from the server i guess lang not langs

10:56:29okay let's go ahead give it a refresh close this down once we have got the data start the server

10:56:41and what you're going to see is that we get our some favorite langs ready for us right so

10:56:46we have got four five languages right here from the backend server what i want to do next is once

10:56:52we have that in place what i want to do next is right here i'm going to have an input type text

10:57:00you know with a value of at add lank whatever you know or maybe like

10:57:08templar or whatever and on change i'm just saying e set temp lang as e dot target not lang

10:57:19either target dot value not lang right and the set temp lang is just a state variable template

10:57:26set template is used of empty string and finally what we want to do is when i call this i just say

10:57:36record is this template right because at the server side we get the record like this and use it

10:57:43one more thing we want to do here at the server side is actually split this down

10:57:48into express and app and just before that we want to also say app.use express.json so that we are

10:57:57able to send and receive json post bodies right alrighty so there's that now once we have that

10:58:06in place what i want also want to do is whenever i click on summit we should also um you know fetch

10:58:15the data again so how do we revalidate that query how do we get that data again but for now you know

10:58:21if i just go ahead and close this and start the server not really close this basically start this

10:58:27give it a refresh real quick and you know then close the server and start the server

10:58:34close this start the server then you will see that we have all the languages available from

10:58:39the server but now if i click on summit you know although we do make requests but nothing

10:58:44really happens and the reason for that is that we are not refreshing this so how do we do that

10:58:51that is something which we'll explore in the next video because that's all for this one

10:59:00alrighty welcome back and in this video what i want to do is actually invalidate our query our

10:59:06data so that it re-fetches it again from the back end once it's you know once it's

10:59:11once a mutation has been done so what does that mean that means that whenever we have a success

10:59:18i want to say that whatever our query client was that is this client right here i want to say

10:59:24that hey bro just invalidate my queries and my queries are for example in this case it's just

10:59:34this favorite language right so the moment i do that what's react query gonna do is that

10:59:40it says that okay i think you know you told me to invalidate this query so i'm just gonna invalidate

10:59:44this and because this is already mounted it will try to get that refresh the data and

10:59:49show it on the screen also what i can do is also set templating as empty once we have got success

10:59:56or you know just press the button as well depending on whatever you want to do

11:00:00and that is pretty much it that is all we need to do if i close the server right here start this

11:00:05again just so that we propagate the react changes at least and once we have the react changes with

11:00:11us close this again start the server again you can see that we get our application up and running so

11:00:17our backend is now running and if i try to add one two one two here hit summit what you're gonna see

11:00:23is that well it goes out and um the query is also fetched but our data right here does not contain

11:00:32one two one two or you know anything like that so that is probably some issue with our um

11:00:40you know our end on the back end so let's just see what the record

11:00:45is that we get here so if i submit it now maybe give it a refresh summit

11:00:54well actually looks like we are not um we are not actually

11:01:03making any request at all so let's just quickly see if we can debug it real quick

11:01:09so i'm just going to go to the networks tab if it just allows me to

11:01:15and there we go so summit create record okay so we are hitting the wrong endpoint this should be

11:01:22create there we go one two one two summit there we go now it works perfectly fine so you can see

11:01:29we also got the record on the back end and what's exactly happening here is that we write something

11:01:35hit summit it goes to the back end once it is resolved we get the you know we set the input

11:01:41field as empty and we also invalidate the query so that means it will just refresh it again because

11:01:47you know it sees that it is mounted so it's going to refresh that query again and it's going to

11:01:51populate it with an updated view super convenient super easy to build a to-do application like this

11:01:57now you know just have to use a query you have to use a mutation and you're good to go right so see

11:02:04how how convenient it gets and what i'm going to do is i'm going to probably take another

11:02:10video and do some good practices on what we have here right because we can definitely improve this

11:02:17so yeah that's pretty much it for this video and i'm gonna see you in the next one really soon

CI/CD and GitHub Actions

11:02:27hey everyone welcome back and in this brand new course we'll be talking a bit about github

11:02:33actions continuous integration and continuous deployment why that is important and how you

11:02:38can set up these basic pipelines for your project on github actions now by the end of this course

11:02:44you would not just be able to understand what github actions is and what ci cd is but also

11:02:49would have built your few small build pipelines where your project is being built is tested

11:02:56and then deployed automatically wherever you want so let's just go ahead and get started

11:03:00with this mini course which we have on code dam and this is part of your full stack and backend

11:03:06learning paths on code dam so make sure you are subscribed to code them if you are not yet

11:03:11because we'll have a lot more things to follow up after the cicd course let's go

11:03:23all right so in this course i'll be following up with a simple react playground i'm just going to

11:03:27say ci cd with github as the name and you can pretty much follow along on your local system

11:03:35or on code down playgrounds on codedam.com playgrounds and once you get started with the

11:03:40project what we'll be doing is not focus on the project that much but focus on something known

11:03:47as yaml files in this little series and github actions eventually let's talk a little bit about

11:03:53github actions as well so github actions is basically a service which allows you to do

11:03:59continuous integration and continuous deployment now let's actually understand what this exactly

11:04:04is and why do we need this these kind of things well you see when you're building a project like

11:04:09on condom playgrounds or you know on your local systems what you are essentially doing is working

11:04:16in the best possible and the best comfortable way you can as a developer right so you are working

11:04:21on all of this code and folders and everything as as a nice experience for yourself but a lot

11:04:28of times your project actually needs a build step and sometimes even a compilation step

11:04:33to become production ready that means trimming off unrequired code compressing the code making

11:04:38the code more performant and so on and all of this build step and compilation step takes

11:04:44time to run so what these ci cd services do is in a in a nutshell basically they allow everything

11:04:52which you have coded or written or any member of your team has coded or written build and deploy on

11:04:59staging production or preview environment whatever environment you have automatically once you push

11:05:04on a repository like github now this is again important because you don't want as a developer

11:05:10you don't want to spend a lot of time just building and testing all the things by yourself

11:05:16on your local system why because it wastes your time and it wastes the capacity of compute you

11:05:22have on your system so you want to make sure that your deployment and testing part is as much

11:05:28automated as possible so that you as a developer spend most of the time working on logic and

11:05:34building new features instead of actually building the project itself and testing it yourself

11:05:38github provides this as one of the services but github is not the only place where you can run ci

11:05:45cd there are basically countless tools out there which can do that but we prefer github i prefer

11:05:51github in this one because github actions actually sits right right across your source code right so

11:05:57when we will take a look at how we push this project to github and so on i'll actually show

11:06:02you that basically like you know github is uh just very convenient to push your source code to

11:06:14hey everyone welcome back and in this video let's just go ahead and set up a git repository in this

11:06:21in this source code first because that is what will allow us to also then set up a github action

11:06:29so i'm going to go ahead and open a second terminal over here and i'm going to start writing

11:06:34get in it right you know all of this from your from basically your github course on code dam

11:06:42and i'm gonna just initialize i'm just gonna say git remote add origin get

11:06:48or you know i'm just gonna go ahead and create a repository first so new repository

11:06:54i'm going to say let's say this is test github actions or you know maybe like github actions

11:07:02code damn course something like that i can make it public and i'm just going to create this now once

11:07:09i create this i'm going to just use the https version i'm going to say git remote add origin

11:07:15and paste this thing now when i do get remote wii you're going to see that that particular origin is

11:07:21added now one thing we are still missing is the get ignore file over here so that we can

11:07:29just add node modules and everything and uh yep that should be it and if i say initial comment

11:07:39okay we need to also set up git here real quick all right so once that is done we can say get

11:07:47comment initial comment over here and i can now just say get push origin master and apparently

11:07:56git has removed github has removed the support for password-based authentication so what we can do is

11:08:03go back and create in the github settings apps create a personal access token just for this use

11:08:09case and i'm gonna of course remove this just tomorrow so that it's not misused obviously

11:08:17i'm just going to say this is github actions token right make sure you select the repo access so that

11:08:24it is able to access your all your repositories copy this token right here and remove mode remove

11:08:33origin because we need to add it back so i'm going to say git remote add origin

11:08:42my token at the rate github.com mayholdmpt github actions code damn course and hit enter now i can

11:08:52go ahead and push it to the github right now the moment i do that you're gonna see that if i copy

11:08:59this repository url and paste it over here you're going to see that it pushes our code to github

11:09:08which is awesome but now we need to set up certain github actions right now the way github works

11:09:16is that it needs a folder called.github it's not get you can see the git folder is already here

11:09:24we created a dot github folder right now this particular folder whenever this is present

11:09:32github would try to see what kind of workflows this folder contains right so i'm just going to

11:09:39go ahead and create another folder inside this called workflows right and when we create that

11:09:48folder any yaml file which is present inside this particular folder would automatically

11:09:55be marked as a github action now what do i mean by that let's say i create a yaml file

11:10:02test dot yaml right it could be test.yml and if i go ahead and open this you can see that we get

11:10:10a yaml file over here and i can just go ahead and write some crap

11:10:14right here let's not worry about this for now but what this essentially means is that this

11:10:21particular file is now a github action and now let me go back a couple of directories

11:10:27and just push it again with the test yaml added and i'm going to say get push origin master okay

11:10:38so we do not have a workflow scope in the access token so this might not be a problem if you

11:10:45actually go ahead and you know just use ssh based authentication in my case it is a problem because

11:10:54i am using an access token but you know how to set up an ssh based authentication as well i would not

11:11:00recommend doing that on the code damn playground until unless we secure all your credentials not

11:11:05just the source code so maybe when you create a new token let's say this is github actions token2

11:11:12you also give it the access of the workflow over here so once you create this token copy this again

11:11:19git remote remove origin hit remote basically do the same thing and then i'm gonna attempt to push

11:11:27on master branch again and this time this works because now it is able to create that workflow for

11:11:33us if i go ahead inside this take a look you're gonna see this dot github workflows is now created

11:11:41and if i go to this actions tab over here in my repository you're gonna see we see something test

11:11:48yaml added with the cross because obviously we did not write anything meaningful inside inside this

11:11:54particular file but you can see something happened right now this is what the workflow is all about

11:12:00you create a workflow with a file a yaml file inside github workflows folder

11:12:05and it just gets picked up by github automatically right no configuration nothing needing nothing

11:12:11needed no toggles anything like that so a lot of work which we'll be doing would be

11:12:16in this yaml file from this point onwards and i hope you understood so far what we did we just

11:12:22created a repository we pushed it on github we created this folder structure and github

11:12:28automatically picks it right this is all magic of github it's not the magic of git as per say

11:12:40hey everyone welcome back and in this video i want to talk a bit about yaml or yml like i wrote here

11:12:46and what this exactly is so yaml stands for yaml is not a markup language or sometimes

11:12:56some people say yet another markup language as well but the point you have to remember is yaml

11:13:02is pretty much what json is right so you have seen stuff like package.json right so when you

11:13:09take a look inside package.json you see there are these objects which can contain keys and

11:13:14values keys and values right yaml is pretty much the same thing the only difference is how

11:13:20yaml is written json is used as a thing to communicate between different kind of languages

11:13:27and build systems and you know environments right so package.json can be read by javascript as well

11:13:33package.js on this file technically could also be read by a java program or a python program right

11:13:39so let's say if your node.js script wanted to spit out some data which your python backend would read

11:13:46then one way to do that is to spit out that data into a json format similarly

11:13:52yaml is also a similar format for which you would have uh you know you would require a

11:13:57few libraries for example there is no native support for yaml in node.js but it's more like

11:14:03a data exchange format among different uh you know different languages or different systems

11:14:10now what yaml does better over json is readability right so we're gonna see eventually like this is

11:14:18this is also quite treatable but yaml is even more cleaner why because it uses very less special

11:14:24characters like usually there is no need of these codes these brackets these commas nothing is

11:14:30required right there is very very minimal language syntax which you need and a lot of information

11:14:36which needs to be go you know needs to go in the file is just basically what your logic is

11:14:42for the data so in this little section or in this collection of videos we're gonna learn about yaml

11:14:49a bit because it is really important to understand yaml first before you actually start writing

11:14:53workflow files because this is almost like a new kind of data format which you're seeing right

11:15:03hey everyone welcome back and in this video let's start with yaml basics right so we're going to

11:15:09cover a few important things in yaml the first thing is how you generate keys and value pairs

11:15:15right so in yaml what you do is you say keyname and then a column and then the value whatever that

11:15:23value is right so this is like a completely valid yaml file similarly let's say if i have a service

11:15:31my goddamn project then i could have you know tests or script as script 1 then test 2 as script

11:15:402 and so on so what essentially we are doing here is if you want to compare it with a javascript

11:15:45based rendering something equivalent in javascript let me just go ahead and actually create a

11:15:51basic.json file because i don't want to destroy our package.json so i'm going to go ahead and

11:15:56open this basic.json i'm going to try to convert whatever we have written into the

11:16:01json part right and the json equivalent of this would be something like service then a quote

11:16:09then test then these codes and then test two then the codes and then closing and of course

11:16:14these keys should also be in codes right so this is a json file and this right here is a yaml file

11:16:24and you can already see that yaml has much more condensed information compared to json right and

11:16:30it just gets more condensed as we nest objects and as we go ahead and start working with that so

11:16:37you can see right now that we just created some top level keys and value pairs now it is possible

11:16:43in yaml to also go ahead and create nested objects right and the way you do that is pretty much with

11:16:50indentation so you can say my app as the key of a of a you know a parent object and for these

11:16:59three keys you have to indent them now this is very important in yaml just like in python that

11:17:05these indentations are actually consistent with each other right whether they are spaces or tabs

11:17:11doesn't matter but they have to be consistent with each other that if you're using one thing

11:17:16then it has to be one thing all across your file the similar thing the similar logic

11:17:20in json would look something like this my app and then an object something like this

11:17:26and yep there we go so these two files over here are technically equivalent in terms of the data

11:17:33which they contain right so this is important because now you can see that it's much cleaner

11:17:39and much more human readable compared to json so that's pretty much it for this video i'm going to

11:17:44keep it short because i want you to understand how this yaml file looks like and works and in

11:17:50the next video we're going to be taking a look at how you can work with more data types in yaml

11:18:00hey everyone welcome back and in this video let's just quickly take a look at comments in yaml

11:18:05now one of the best things i like about yaml is the support of its native commands

11:18:10so you can say this is my comment

11:18:13and right here this would pretty much be ignored by any file which is reading this particular

11:18:17piece of data right this is impossible in json i mean json does have some variants where it allows

11:18:23these commands over here but you'll start seeing that comments are not permitted in json is is

11:18:28something you will pretty much see every single language or library which does not have some

11:18:34additional functionalities would be complaining about right json cannot have commands and this

11:18:39is one of the nice things about yaml is that you can start it with a hash symbol and start leaving

11:18:44comments all the way across right you can leave comment over here hello you can leave comment

11:18:50you know somewhere here it doesn't matter it just has to start with the hash symbol and it has to

11:18:56be like a single line right whatever you write in front of that hash symbol would get commented

11:19:00out there is no multi-line comment as far as i know in yaml so most of the stuff you do can be

11:19:06done just with single line commands which is i think is fine given that it's mostly organizing

11:19:12data and configuration and not actual code so as far as that is concerned that should be good

11:19:22hey everyone welcome back and in this video let's just go ahead and take a look at lists in yaml and

11:19:29how that works out now lists in yaml is basically a way of organizing elements in an array right

11:19:38so for example you're going to have something like my array like this and jake in json and you can

11:19:45add something like this right this is like a valid json over here the similar thing can be done in

11:19:53yaml as well basically in the same format right so you can copy this and you can paste it right here

11:19:59you just have to remove the extra stuff and this is like completely valid uh yaml syntax over here

11:20:08now the good thing about this yaml part is that there is another way to create

11:20:14an array of objects and i'm going to tell you what that is so let's say if you have this array

11:20:21as an array of objects then you have something like key 1 value one and then let's say

11:20:28key two value two right let's say we have this particular json object and we want to create a

11:20:35array representation of this particular thing in the yaml world right so how would we do that

11:20:43now the way we would do this particular conversion to this over here is as follows

11:20:50whenever you want to start a list of things in yaml you press enter

11:20:56give it a tab or in this case it would work without even a tab and i'll tell you why

11:21:01but the general rule is press enter give it a tab and put a dash now this dash over here signifies

11:21:08that hey this is a single element in this array right and when you do a structure like this

11:21:16and when you start mentioning key value pairs then yaml automatically knows that this is an object

11:21:22right if we wanted to replicate the earlier example of this into this newer format what

11:21:28we will do is something like 1 then 2 then 3 then 4 then 5 then 6 right this particular thing which

11:21:38i have written is pretty much equivalent to this thing but the reason we use this syntax earlier

11:21:45is because it's much more cleaner and concise this syntax would not work with array of objects

11:21:50because well you need multiple properties over there right so what we do is we start it with

11:21:56a single dash and then we'll start mentioning the key value pairs so i'm going to go ahead and take

11:22:02a look at here and it says that key one value one so i'm going to say key one value one right and

11:22:09actually let me just go ahead and add a couple of more keys here key random and value random

11:22:17right now in order to create this i'm just going to give an enter and do this

11:22:24you can see that i did not put a dash over here why because this is a single object right the

11:22:30moment i put a dash over here this means that the new object has started in this case right

11:22:37so i can now go ahead and put key 2 value 2 and i can go ahead and say key random 2 value random 2

11:22:44and this would actually represent the following

11:22:50data over here inside of json right so i'm taking i'm just giving you a json and yaml comparison

11:22:57just because it's easier and most people have worked with json in the past so it's easier

11:23:02to bring those learnings into the ammo world than actually just understanding everything from start

11:23:07right so you can see that it's much cleaner the syntax already looks much cleaner to ice

11:23:12compared to this one and it gets even better as you have more and more things

11:23:17going on right but that's the essence of yaml in a nutshell you can have numbers over here that's

11:23:24completely possible you can have booleans you can have you know strings which we have already

11:23:28discussed if you want you can put them in codes that's also completely fine this is also fine

11:23:35and if you want if you can just remove the codes as well that's also completely possible

11:23:40so yep that's pretty much it for this video in the next one we're going to discuss some

11:23:43more concepts on yaml and take a look at how you know maybe things like multi-line strings or those

11:23:51those sort of things would work out in yamalan the good thing is there is support for that

11:23:59hey everyone welcome back and i just wanted to make this quick little video i just googled yaml

11:24:05validator on google and wanted to show you that yaml needs to be proper in order to be parsed

11:24:11right because the score damn editor although it does provide syntax highlighting currently

11:24:16we don't tell you if the yaml is valid or not so whatever yaml stuff you are writing here you can

11:24:21go ahead and paste it inside this yaml lint click on go over here and you'll see that it gives you

11:24:27a valid yaml message right now if i go ahead and mess around with the spacing a bit you're gonna

11:24:33start seeing stuff where it says you know some some sort of errors and something and it also

11:24:38highlights the line number i mean i don't really have any clue about whether this website is the

11:24:44best one out there or not but if you google yaml validator you should be able to find some nice

11:24:50little online website for the time being which can help you with the you know just validating

11:24:56yamalan you can see it already says valid yaml but if i give it a couple of spaces back

11:25:01you can see that it starts messing around right so that's that's one thing i wanted to tell you that

11:25:07yaml needs to be validated it's not like you can mess around with spaces and padding all the time

11:25:13so make sure whenever you are you know just executing this configuration file whether

11:25:17that's on github actions whether that's on pretty much any other thing and if i haven't told you

11:25:22yet yaml is a very very popular way of writing configuration files and a lot of devops and in

11:25:28a lot of uh infrastructure as a code stuff as well so if you did not know that then congratulations

11:25:35you have been learning a markup language which would be very very convenient for you when you

11:25:41are getting into that space but yeah i mean that's that's the whole point of this particular video

11:25:53hey everyone welcome back and in this video let's just go ahead and take a look at what

11:25:58yaml multi-line string is and how you can work with that and this is also one of the interesting

11:26:03things about yaml that is you can represent multi-line strings that is not possible in the

11:26:08native json format again second feature which we discovered and which we are talking about

11:26:13the first one was commands the second one is this multi-line feature okay so let's say this

11:26:18value over here needed to be multi-line right or let me just get rid of this because we already

11:26:24have discussed how the nested objects and array of objects work so let's keep it a bit clean

11:26:28even this top level would work fine so let's say if i wanted to have a similar thing over here in

11:26:34my json representation now the only way i can represent multi lines in json is by actually

11:26:40physically typing the new line character so i can say something like my name is mehul i am 23

11:26:47years old i am the founder of goddamn like these three strings three's lines right but in order to

11:26:55represent this new line i have to write this new line character right i cannot give this a render

11:27:01key this would not work json would complain but this is pretty much possible in yaml world right

11:27:09why because you can go ahead and start writing my name is mehul hit enter and you know give us give

11:27:17it a tab i am 23 years old hit enter and you know i am the founder of code down now this is fine but

11:27:27when you copy paste or you know create a second key hello world let's say and if you copy paste

11:27:33this in the yaml value data now what happens if i bring the first line also in the next line right

11:27:39now you can see that it starts saying me unable to parse now in order to tell this service key that

11:27:45hey you're going to find a lot of multi-line content in the next line you have to give it

11:27:50a pipe symbol over here now the moment you do that you tell the yaml syntax that hey whatever you are

11:27:57writing over here is actually multi-lines right so until and unless you encounter another key

11:28:04or the end of the file that is a string so in order to make this valid all we have to do is

11:28:10something like this and this is now a multi-line string in yaml which is the equivalent of what we

11:28:16have written here now you can see the application of yaml in the human readable stuff right so yep

11:28:22that's pretty much it for this video hopefully you understood the basics the fundamentals of yaml

11:28:28this is probably more or less all we would need in order to understand and work with the github

11:28:33actions part so let's get started with that now and deploy some pipelines on the github actions

11:28:44hey everyone welcome back and in this video let's just go ahead and write our very first

11:28:49valid action in github actions and this is kind of a hello world tutorial for github actions so let's

11:28:55go ahead and take a look at how we can do that so i'm going to go ahead and actually make some space

11:29:00over here because we don't need the terminals just yet so what i'm going to go ahead and do is

11:29:07remove this and let's just also remove the basic we don't need it anymore and we can start working

11:29:13with test.yml format itself it's it does not really matter the very first thing with a what a

11:29:19github action needs is a name right a name as the key and let's say this is something like my first

11:29:26github github action right the second thing a github action needs is when this particular action

11:29:34should run right which is specified with this on keyword right and the reason you need to specify

11:29:41this particular thing is because there are many times you want to run a workflow file on sometimes

11:29:48like a push on a comment push or sometimes on a pull request when somebody creates a pull request

11:29:54on your repository or you know something like on a deployment status this action is basically you

11:30:01can think about this in a way that let's say you have a bot like a versal bot which deploys your

11:30:06project online and then sends you the url of that particular project right which is deployed so you

11:30:11want this action to then run and maybe do whatever end-to-end testing it wants to do but the most

11:30:16common and the most simple one is on push because this says that hey whenever you push a comment

11:30:22run this action which is precisely what we want in this case the next thing github action needs

11:30:27to know is the jobs which is which it is supposed to do right the jobs which it is supposed to run

11:30:34in the single workflow now one important thing about this jobs is that there could be multiple

11:30:39jobs you know i'm specifying this as jobs not a job and i just can start working in a you know a

11:30:47fashion where i specify all the jobs over here so let's say one of the jobs is to print hello

11:30:53world right this is a single job and i'm you can see that i'm trying to create an object within an

11:31:00object over here it's not a list so this means they are not running in sequential this is very

11:31:04important that i have not put a dash over here that means this is not a list this is not an array

11:31:10this is actually an object that means there is no guarantee that this would run in sequence you know

11:31:14if i have a second sec o nd job sec s e c o nd job if i have a second job then also it is it is not

11:31:24possible it is not compulsory that these two jobs would run one after another right but let's stick

11:31:29to only a single job for now let me just go ahead and specify a couple of more keys i'm going to say

11:31:35runs on ubuntu latest which is basically what the underlying image you want on the runner and we'll

11:31:40discuss about that don't worry that much and then finally in a single job you want to have multiple

11:31:46steps right because in an ideal world scenario your this job would be something like uh you know

11:31:53build my project then another job would be check linting right another another job could be unit

11:32:02testing something like this right so what this would be let's just rename it back to print

11:32:08hello world because that's what we will be doing is we want to specify an array of uh you know

11:32:17steps again because these steps should be executed in order so i'm going to start creating an array

11:32:23over here and i'm going to start saying run and this run pretty much is the bash command over here

11:32:29which you specify so i can say something like echo something like hello world like this right so what

11:32:36essentially we have created is a very small github action job which runs the sprint hello world shop

11:32:43on ubuntu latest docker image and there's only one step in this case that is to run hello world i can

11:32:50specify another step and i can say this is step number two and this is guaranteed and don't worry

11:32:58about the syntax highlighting which is breaking but this should work technically um let's let's

11:33:04not keep number two so that it does not break the tutorial but this is step number two and it

11:33:09is guaranteed that these two steps would execute one after another right it is not guaranteed or in

11:33:16fact not even guaranteed it does not even happen that if i have a second job over here that these

11:33:22jobs would run in sequence right like i mentioned earlier so anyway we have a working job right now

11:33:27with us let's just go ahead and try to push it so i'm going to say added a new job hit enter

11:33:34and i'm going to push this to the master repo alright so once that is pushed i can go ahead and

11:33:40copy this repo over here and open this in a new tab and what we'll see the first thing you will

11:33:45see is now you have this nice little yellow dot over here in your repositories which on clicking

11:33:51shows that hey github is running your action now you go to actions tab and you can see that

11:33:56there is another added a new job workflow which is running over here and which has already ran

11:34:02and completed so the way you debug this and know more about this is when you click on this but

11:34:09that is something i want to discuss in the next video i want to keep this video short and crisp

11:34:13so hopefully you were able to build your first github action with me over here if yes then that's

11:34:19a great thing you have just started your journey on the ci cd and just you know removing a lot of

11:34:26headaches of testing and building and everything just transferred it to github so congrats on that

11:34:37hey everyone welcome back and in this video let's just take a look at what this github action did

11:34:43when it ran and how you can actually work with this page as well because a lot of times you will

11:34:48be working with this page as well so when you click on this page and this layout might change

11:34:52maybe in future when github updates their ui but the fundamental concepts remain same you can see

11:34:57that github provides you with a bunch of options the first thing is you can rerun these jobs which

11:35:02are over here when you click on this button github would run this action again and this

11:35:07is helpful when sometimes your job fails this this whole workflow file fails because of some external

11:35:13reasons which are now fixed for example let's say docker is down or aws is down or something is down

11:35:19which led to your workflow failing so you don't want to push another comment to trigger that

11:35:23workflow or do any sort of other action you can just go ahead and click on the serene on all jobs

11:35:28button the second thing over here is this these three dots you can see that over here they provide

11:35:33you with some very minimal information you can view the work flow file which was executed in

11:35:38this case this is our yaml file which was executed you can see the workflow runs which this has done

11:35:43which brings us back to our actions tab kind of more or less because we only have a single action

11:35:49over here and the first the third thing which you can see is that you can create those status badges

11:35:54which people you know often you might have seen often this is embedded on repositories that build

11:36:00passing and you know test running and all that kind of stuff so you can build those badges like

11:36:05this over here just copy this and paste it in your github readme files and you're good to go so this

11:36:10is pretty awesome these set of features are very handy sometimes when you need them but the way you

11:36:16actually get into what has happened is you click on this step or click on this job not the step so

11:36:23what github does is that it will organize all the jobs which you execute in this section over left

11:36:30so you can see that if i specify another job let's say this is print hello world 2 and if i add this

11:36:37and if i commit this job 2 and if i push this just get push origin master you're going to see

11:36:45the second action which gets run over here this job two over here has these couple of jobs running

11:36:52right now again they kind of appear in order but they are not really executing sequentially right

11:36:58you can see that they started executing parallely so this is very very important because this is an

11:37:03object this is not a list so github follows that particular thing but what you can see over here

11:37:09is that you can jump into a singular job by clicking on them so now what this page over

11:37:15here does it shows you the steps in all the jobs now you might be thinking that hey i did

11:37:20not specify the setup job and complete job steps then why are they here well you see that github

11:37:26obviously when you specify this runs on thing obviously needs to set up that particular

11:37:32environment for you right in this case you can see that because we specified ubuntu latest

11:37:36it gave me ubuntu 20.04.3 you could you could have technically just hard coded your ubuntu version

11:37:42here as well and then github would always give you that same environment right and you can go ahead

11:37:46and take a look at all these environment variables as well right github token also gives you a

11:37:53glimpse into what is possible with your within your workflow over here right we're going to

11:37:58discuss a little bit about github token later then once your job once your environment is

11:38:03set up your next steps start running in sequence again this is in sequence this is not happening

11:38:09parallelly right these two commands are not running parallely they are running in sequence

11:38:13so hello world is executed first and this is step number two is executed second and then finally the

11:38:19job gets completed github does some cleanup of processes and this and that you don't have to

11:38:24worry a lot about this but this is in general what your job looks like then there was a similar but

11:38:29separate job running parallelly to this one jobs run parallely steps don't run parallely

11:38:36and this particular thing pretty much executed the same

11:38:39stuff which was happening right in the top one so there's nothing really to explain here

11:38:44but yep that's pretty much it for this video in the next one i'll actually tell you how you

11:38:49can execute jobs in sequence as well because that is also like an important part but this

11:38:54should get you started with at least writing your first few bash scripts in github actions

11:39:04hey everyone welcome back and in this video let's just go ahead and actually instead of

11:39:08you know just jumping directly on how to make interdependent jobs let's actually first of

11:39:13all try to build this project which we have been trying to do since the very starting so i'm gonna

11:39:17go ahead and say this job as build app and i'm going to keep this runs on ubuntu latest tip as

11:39:23you know as intact because this is something which we need we're going to be going ahead

11:39:26and removing this particular thing and we're going to be messing up with steps a bit now the reason

11:39:32for this is that if you take a look over here github actions at the end of the day although

11:39:37it is integrated with github closely i mean it's just a tab away but still the environment which

11:39:42it prepares is completely isolated with your repository right this is a docker container

11:39:47this is a temporary environment running somewhere on the cloud where you which you don't know about

11:39:52so obviously it does not has access to your repository right away but github has created some

11:39:58interesting and some handy actions default action steps which allow you to work with your repository

11:40:06easily right and we're going to be taking a look at all of them most of them and i'm going to show

11:40:11you how to you can find them as well but there is this one action which you can use called actions

11:40:17check out version two right now if you google the string up you're gonna land up on a page like this

11:40:24now if you pay close attention to the url over here it is github.com action slash checkout this

11:40:30actions is actually an organization account from github which includes a lot of interesting and

11:40:36default runners right or step as you can say so this checkout action over here the only thing it

11:40:44is supposed to do is you know clone the repository in which it's currently running and of course you

11:40:49can have customize it with all sorts of options and all sorts of customizations but the moment you

11:40:56specify this action what it will do without any customization is that it will clone the currently

11:41:01running directory right so if i go ahead go back and right here in the next step i do something

11:41:07like run and i say uh let's say something like ls for example or not ls let's run tree right

11:41:15because tree would show you pretty much all the output which a particular directory has this is

11:41:20a bash command right nothing get about nothing fancy like that so if i go ahead and run this now

11:41:27new action and if i push this to master you're gonna see that when this action gets deployed

11:41:34and when this action starts running if i go inside this build step you can see sometimes it takes a

11:41:40couple of seconds to start the build process but if you come here on time you can also see uh how

11:41:49or what it is doing to initialize that particular action sometimes it gets lagged a little but yeah

11:41:55right here you can see in the second step it ran actions checkout version two and it had these

11:42:00bunch of steps you can see it initialized it with a bunch of default values this repository over

11:42:06here is of course the default repository because it was able to you know compute that particular

11:42:12thing where it is executing and when we ran this tree command over here you can see the

11:42:16output which we got was this this means that our repository was successfully cloned right because

11:42:22this is our repository over here you can see the file structure we have the src folder we have the

11:42:27public folder and this is exactly what we see in the runner so at this point over here we have the

11:42:32repository cloned that means we can start building stuff right so yep that's that's basically it in

11:42:41terms of setting up your repository on the github runner the only next thing you need

11:42:45to do is set up node.js on this repository and start working on it start working on building

11:42:52your project i'm going to go ahead and tell you how to do that particular thing in the next video

11:43:01hey everyone welcome back and in this one let's just go ahead and take a look at what should be

11:43:08done to set up node.js on this repository right now and start building stuff so of

11:43:15course thankfully there is another action which you can specify from github itself

11:43:20that is actions and then setup oops not the at the rate setup node version 2. again if you google up

11:43:28this string you're going to land up on this action over here which the version 2 is a newer version

11:43:36which allows you to set up a node with any sort of version you like right you can specify this with

11:43:41property over here let me just copy this or you know let's just write it so i'm going to specify

11:43:46this so with property over here i'm going to say that hey this right here over is node version

11:43:53and then let's say 14 right so let's see there we go so what this means is that hey i want

11:44:00node 14 cloned into my repository right or if you wanted a specific version over here let's

11:44:06say if you wanted 14.17.0 cloned right then this 14.17.0 would be available in your environment

11:44:14now in the next step you can just have something like node v and you can just node setup

11:44:21once you push it you're gonna see the moment github action starts running it it's gonna set

11:44:26up that particular node environment for you all right you can see if i expand this run node v

11:44:32section you can see it ran the node we command and it gave us version 14.17.0 right which is exactly

11:44:39what we specified in our setup node area so that's all fun and games but how do we do anything

11:44:45from this well when you install node version it automatically comes with npm and yarn installed

11:44:51so the next thing you can do is start working on building your project now the good thing about

11:44:55github actions is that you can also specify or you know you can also change the name which appears

11:45:00here right now it just says run and then whatever command you are saying but i can also specify

11:45:05that by saying name as the property instead of run directly as uh you know build the project and then

11:45:12i can specify the second property in this array of object that is the run thing and now i can say if

11:45:19i have a package.json and if i let's say specify a build command i can say snowpack build and just

11:45:27to see if this is working we can just run it here as well and you can see snowpack build is in fact

11:45:33a command and i'm just gonna remove that for now but this should get us started right i have a yarn

11:45:39build command now and i just have to say yarn build over here right and maybe the next step

11:45:45could be set up finish and i can just say run echo hooray right so if i say multiple steps over here

11:45:57and push this to github what you're going to see is now when you go to the actions tab

11:46:04it starts with the multiple steps commit it we can go into the build app job and right here we should

11:46:11see that it should build your project in the ci cd runner for the first time right and of course this

11:46:19fails because you can see that it is not able to find snowpack so can you guess what you have to do

11:46:25over here what we did wrong well we missed a step which is that you have to install node modules

11:46:34right and to do that all you have to do is just write yarn that should be more than enough and we

11:46:41can add a commit missing installing node modules step right get push origin master hit enter go

11:46:51to github go to actions go to the build area and you should be able to see that github now should

11:47:01be able to build your project successfully as you can see now it's starting to install node modules

11:47:05and this is like a great place to be if you want to just take a look at how everything is working

11:47:12out because github gives you real-time logs of whatever is happening and you can see now if i

11:47:16expand this node modules area we see the logs which were coming in it built the project that

11:47:22means it created this build directory over here right and the setup got finished and we got a

11:47:29hooray from github actions right so yep this is this is pretty much it for this particular video

11:47:36we have built a project we have pushed our project to github and this just works out of the box right

11:47:45hey everyone welcome back and in this video i'm gonna go ahead and show you how you can deploy the

11:47:49simple react project on warsaw from github actions as the ci right now warsaw does provide its own ci

11:47:57and the way the ability to do that but sometimes it's not just enough that means you might have

11:48:02to install a bunch of different things or you might have to do a bunch of different testing

11:48:07for example so you might want to just say to yourself that hey i want to run my own action

11:48:14as well but you can once it's done maybe in this case in react's case it's simple because you know

11:48:20you get a bundle of static files then you can go ahead and deploy it by yourself right so what i'm

11:48:25going to go ahead and do first of all is i'm going to go to get more get you know ignore and add oops

11:48:31and add build folder and i'm going to run the yarn build command locally the reason i'm doing this

11:48:36is to show you why i would be writing the commands which i would be writing now so you can see when i

11:48:42run yarn build i can go to the build folder and we have this static output over here right so

11:48:50on warsaw we would not be deploying this project as a react project but in fact as a static html

11:48:56project right because in that case whatsapp can just skip the build and deploy this directly

11:49:03so what i want to do now is go inside the build folder and actually write the command vc or

11:49:12before that let me just go ahead and add vc that is worse cell i hope that's what they call their

11:49:19cli tool but if not we can check that later but once you add this warself package you're gonna see

11:49:28over here in the package.json that ware cell should be available and this versal package ships

11:49:35with a binary called vc so i can say yarn space vc hit enter and you can see that it tells you to

11:49:44log in into versailles first right in my case i'm going to go ahead and use github

11:49:49right so i'm just going to go ahead and copy this particular url over here open this a new tab

11:49:54because i already have an account with versailles so it should just work right away you can see

11:50:00i have this token with me i copy it back hit enter and now my versailles is connected

11:50:08right now it says me to set up and deploy code for which i'm just gonna reject for now and uh

11:50:16that's that so the next thing i'm going to do is take a look and see that we still don't have any

11:50:23versatile configuration so what we can do is we can say worsel that should be yarn versal and then

11:50:29the path to our project in this case this is build right the build folder it's not the build command

11:50:35it's the build folder and then it says set up and deploy this build folder which in my case i want

11:50:42to say yes and then i would choose my own personal account i'm gonna say no and we can just say test

11:50:49build project and i misspelled that but anyway so because it's already inside this folder i'm just

11:50:57gonna keep it as it is that means it is inside the build folder already so right now you can see that

11:51:04it shows says me that hey do you want to override any settings i'm just gonna go with the default

11:51:08that is no and it starts deploying the the you know the basic setup with the basic instructions

11:51:15okay so over here you can see it created a dot versus folder which has a project dot json inside

11:51:21it right and it has a readme over here as well now this is all fun and games but there are a couple

11:51:28of problems here the first problem is that all of this prompting and setup which we did over here we

11:51:35cannot do that on github actions why because we don't have an interactive terminal right neither

11:51:41do we want to nobody wants to go to that action every single time and hit enter a bunch of times

11:51:46that means this project should automatically be deployed every single time right when we push so

11:51:51what we can do is we can create a small little script which automatically runs and it does

11:51:57take no input from the user and it automatically deploys to versil right so in order to do that

11:52:04we're gonna be taking a look at how we can create such a script inside our package.json that's

11:52:08pretty much it for this video i'm gonna continue in the next one where we will discuss this

11:52:17hey everyone welcome back and in this one we'll be discussing about how we can deploy with the worst

11:52:23cell without any intermediary requirement of this keyboard or anything right so before we actually

11:52:29go ahead and do that let me just go ahead and open and verify that our project is in fact deployed on

11:52:34versailles and you can see that we have a nice test build project.versal.app which loads our

11:52:40snowpack production build just like we would expect it to right super fast on the edge and

11:52:46deployed just like that now if you take a look at the versa project deployment pipeline we had three

11:52:53requirements and and in this little series i'm just discussing about versa but this particular

11:52:58thing basically applies to more or less anything which which provider you're deploying whether

11:53:03that's on an ec2 ssh machine or whether that's on something else you can see in the project we have

11:53:10the organization id the project id and the access token remember that token which i copied pasted

11:53:17in the cli that is the access token so we need these three things supplied to the versailles cli

11:53:24and thankfully enough versailles cli does allow us to pick these from the commands itself so

11:53:31i'm going to say something like deploy and this command over here would actually run

11:53:37worsel which is also you can also call it with versailles or vc right and this command over

11:53:43here this should deploy our app to production so that is flag number one the flag number two

11:53:50is what is the token which we have right and this token over here was the value which i copied so to

11:53:57get that value again i'm just going to go ahead and you know copy this and paste it right here

11:54:03so this is our token over here which i would obviously remove once this video is done

11:54:08so that you don't deploy on my pro my you know environment um but this token is the

11:54:14most important part the next two things that is the versailles organization id and the project id

11:54:21they actually come from the environment right so versailles needs those two values from the

11:54:26environment and it's not up to me it's the way uh you know the the versatile cli as well

11:54:33so it's not something i have configured so for the environment part now this is interesting because

11:54:40for the environment part first of all let's just create a step for deploying the project

11:54:45i'm going to go ahead and say run and i'm going to make this multi-line

11:54:49remember we can do that and i can just start here as well or i can give it a tab it doesn't matter

11:54:56for the run part i'm gonna first of all go inside the build folder because we know it is ready

11:55:01then inside the build folder uh or actually let's not do that at all let's just run yarn

11:55:09deploy directly and for that i think we don't even need a new line because we can include the build

11:55:16folder command just right here right now this command is fine but it's still missing the env the

11:55:24environment support right so in github what you can do is specify another key called env over here

11:55:32and you can start mentioning the environment variables which you want in this step right to

11:55:38be available in this particular step and this is again an object it's not in a list or anything

11:55:43so what we need to specify for whatsapp is the versacell organization and the project id so

11:55:49i'm going to copy the organization id and i'm going to go ahead and paste it right here with

11:55:54the versacell organization id and the second value which we need is virtual project id right and the

11:56:03project id over here was this particular thing now we have all the necessary parts

11:56:08in this particular deployment pipeline we have the organization and project id that means we can just

11:56:14completely get rid of the build folder which also contain the versa folder we don't need this

11:56:18anymore uh we have the token with us in the deploy command and we have the build steps running just

11:56:24fine right so let's just go ahead and try to push this to the build pipeline and let's see

11:56:30how that works so i'm going to go ahead and commit this versailles build test and push it

11:56:41over there so now if i go ahead and take a look at this github repository you're gonna see the action

11:56:49which is running right now should also build and try to deploy your project on versailles once

11:56:56it's done with the node modules part all right i think we have an error here that this is not a

11:57:03option so i guess this cli flag is called prod and not production and we can just test it once

11:57:11by saying yarn deploy ourselves and of course this folder is not found so anyway let's just

11:57:17go ahead and give it a bug fix message and push it to github for it to deploy and we're gonna be just

11:57:24sitting down here sitting back here just seeing if github is able to deploy this or not alright

11:57:29so in this case you can see that warsaw cli is kind of misbehaving and i don't understand why or

11:57:36when they change the behavior where they would not read the organization and project id from the cli

11:57:41so we're gonna do a little bit of improvisation i'm gonna run yarn build again i'm gonna deploy it

11:57:48from the build folder directly and we can construct the virtual folder on the fly

11:57:55which is also something interesting you can do with you know because you can pretty much script

11:58:00everything in the virtual cli so let me just go ahead and say nope to this or you know

11:58:08universal actually we don't need to deploy that we need to deploy universal build

11:58:18and this is also something which we i guess missed in the package.json that we don't need

11:58:22to cd into that we need to build like this yes mohan yes link to the existing project

11:58:32and the project name for this was this was the project name test build project

11:58:40over here and let us see if it creates a versal folder over here and if you go to the

11:58:50build folder you can see we have a versal folder and right here we have the project.json with us

11:58:57right which is basically the same thing so what we have to do now is add a build step where over here

11:59:04before it deploys the project sets the versa env so we can say something like run which

11:59:11is a multi-line command now and i want to say i want to go into the build folder i want to

11:59:15make the directory which is dot versus i want to touch the project.json file and i want to echo

11:59:22this json string which i have into project.json right and this is just a hack right for deploying

11:59:30this thing because versailles for some reason virtual cli is misbehaving right now so this

11:59:34is all we can do at the moment now what we can do next is pretty much add comment

11:59:42improvise or cell deployment and we have already changed the package.json command as well so that

11:59:50should be fine and i can just push it and let's see what happens and of course warsaw has to give

11:59:57one last error to us because we are missing confirm flag over here which should skip all

12:00:03these automated questions let's do one final build and see and there is another error where it says

12:00:09that the token is not valid and today is probably an error day so i'm going to go ahead inside

12:00:14versus dashboard and create a token manually my versa or cell token create this token i'm going

12:00:21to copy this and use this instead and there is one mistake we have to fix is that we have to

12:00:27go inside the virtual folder after creating it so that this is actually inside that particular file

12:00:34right so once we do that we can do a final fix and let's wait for it to deploy

12:00:42and as you can see versal has started deploying on the test build project or checked folder which

12:00:47was our typo for this particular url and once it deploys you can see that it's ready and of course

12:00:54we did not make any change but when you make any change on this text now it will automatically

12:00:59reflect so this right now is an example of a fully functional deployment pipeline over here

12:01:05from github actions you just have to make some changes push your code and it will automatically

12:01:10deploy it but it has some obvious serious flaws like exposing all these secrets like this right

12:01:16so we still need to fix that but we'll take a look at how we fix that in the next video

12:01:26hey everyone welcome back and in this video i want to discuss a very interesting part

12:01:31about github that is known as github secrets now github knows that a lot of times we will need

12:01:38sensitive environments and sensitive values to work with in this case the three sensitive

12:01:43values we have is the project id organization id and those two are not so much sensitive as well

12:01:48compared to this one thing which is the token id right which is very very sensitive so the way we

12:01:54approach these sort of things in github actions especially with something which is like a public

12:01:59project over here is that you go ahead and convert these things into secrets on github now to do that

12:02:08what you should do is go ahead inside the settings on github in in your particular repository and

12:02:14go to this particular manage access and let me actually now i think about this i should

12:02:20have made this repository private because anyone uh at the time of watching this video creating

12:02:26this video could have just you know gone into the repository and copied my voice token and remove

12:02:32all those projects which i have uh so hopefully nobody did that yet and that was my bad on my side

12:02:40but anyway so now the repository is private at least we are sure that nobody's messing around

12:02:45now what i can do is go ahead inside settings and inside secrets over there you see over here this

12:02:51is a place where github allows us to add secrets to our repositories now a secret is basically

12:02:58you can think about this this as a kind of a variable but this is encrypted that means this

12:03:03is not visible in the logs and this is not visible to anyone who's using your code as well right so

12:03:08i can say something like versailles project id right this could be named anything and this goes

12:03:16as a secret now you can never see the secret again you can only overwrite it but never really see it

12:03:22and then versal organization id and there we go there we go we have the two secrets now and the

12:03:30third one is my worst cell token right in this case this token would be this particular thing

12:03:38and of course once you add secrets you should obviously just refresh all the all the values

12:03:43so that you know somebody just does not going to get history and check out what you have done now

12:03:48in order to access these secrets you first have to bring them into your runners environment right

12:03:55the secrets are not just available in to the environment right away so in order to bring

12:03:59these secrets into the environment of your yaml file you have to do two things the first thing

12:04:07like we already did a little bit earlier that is you have to uh in case of the deployment part we

12:04:15want to do this you have to add an env block and the second thing is you have to specify what the

12:04:22secret name was initially in the github uh secrets panel as well so in this case i want to say

12:04:28that hey i want to get this pack as a versailles project id as the env name and what this value was

12:04:37was from secrets dot the same thing right why because this thing right here

12:04:44should actually match this thing over here this thing could be anything right whatever this is

12:04:50this is the name of the environment variable in this case i'm also keeping the same but this has

12:04:54to match the secret of the github right similarly for token we can get the token like this secrets

12:05:02dot virtual token and then secrets.versal organization id this over here this secrets

12:05:09variable is automatically filled by github so you don't have to do anything over here

12:05:14but the moment you do that in any env block now these three environment variables are available

12:05:19right and of course you would want to do this one block above that is in this particular job itself

12:05:27now when you specify the environment variables on a job itself then of course they are available

12:05:32for all the steps when you specify it within a step itself then it is only available for that

12:05:36particular step right so we want to do a little bit of change over here i want to escape these

12:05:43codes real quick like this and i'm going to say over here this is versailles project

12:05:52id right and this over here is worsel organization id i guess yep there we go

12:05:59and now we are filling this from the environment and finally because this yarn deploys also running

12:06:05in a step which is controlled by github action we can go ahead and use the versal token variable

12:06:11directly as a bash variable right because now this is an environment so this also secures our

12:06:17this now secures all of our environment variables as well so i can go ahead and add commit and moved

12:06:24to secrets and i can say git push origin master and this should be more than enough

12:06:31to protect protect our stuff and as you can see over here whenever github tries to echo out a

12:06:37secret variable it automatically masks it in the input that means if you use echo versus project

12:06:43id or anything over here github would not show it in the logs right it is still technically i mean

12:06:49obviously possible that you echo it to a file and then perform an http request and extract

12:06:54it out somehow sure that's possible otherwise how the hell would the command itself use it

12:07:01but for the most part the logging part is protected right you cannot just log a secret and

12:07:06be done with it so yep you can see the builds are still reflected on the main project itself and

12:07:11now we have a fully functional secure deployment pipeline where if i say something like hello from

12:07:18codem this is so awesome all i have to do now is add the change and push it to my github pipeline

12:07:30and this would deploy my project it will build it it'll minify it it'll do all sorts of amazing

12:07:35stuff on the versailles cli itself on the github action itself and deploy it on this particular url

12:07:42test build project which is our typo you can see right now it's not

12:07:47reflecting because it's not built yet but this would be built soon and then it will basically be

12:07:53visible on the screen all right so once built you can go back to the page hit refresh and now you

12:08:00can see that it reflects your production build and it's on virtual deployed app on the edge

12:08:06super fast super scalable all the good stuff with a good nice deployment pipeline setup as

12:08:13well so yep that's pretty much it for this video hopefully you were able to follow along and this

12:08:17video is deliberately you know this whole series with versailles and everything is deliberately

12:08:22done with the versailles cli otherwise there was a reversal action as well just so you know about

12:08:27environment variables and you know all this hacky stuff and all that stuff so this is just

12:08:32a way to learn ideally you should probably be using some easier solution like versus versatile

12:08:38action directly or even you know just using warsaw runner if you want but yeah hopefully this

12:08:43teaches you a bit about how to work with github actions which was the purpose of this series

12:08:53hey everyone welcome back and in this video let's just go ahead and take a look at how you

12:08:57can create dependent jobs inside of your workflow now this is interesting because

12:09:05a lot of times when you start a second job you don't necessarily want to run it in parallel right

12:09:10for example this might be a build app this might be a test app and you cannot really test a web

12:09:16app until it is built and deployed right then then that is the point where you will run the cypress

12:09:21end-to-end test and all that stuff so in this case if i also specify a ransom thing as ubuntu

12:09:28latest and in this video let's just keep the steps as very simple i'm just going to say

12:09:32run echo yellow something like that what i want is that this yolo waits until the build

12:09:40is complete until the build is complete right and the way you can create these dependent uh

12:09:46jobs is by using something known as needs now this needs key is a special key for github

12:09:53which says that hey if i specify this build app over here

12:09:57it's going to wait for this particular job right here to finish so now if i deploy this dependent

12:10:05job and push it on github you're gonna see that if i go back to github it's gonna wait for us

12:10:12it's gonna wait for our build to complete and then it goes to the desktop and you can see this

12:10:18with this little link which github creates right earlier you knew that when we created this job

12:10:24both of them appeared here apparently and they were executing right here you can see this test

12:10:30app is actually you know a little dimmed right and it will only become active the moment this uh the

12:10:36first job actually succeeds right or not exactly succeeds but it completes and not i mean succeeds

12:10:44is also of correct word because if it fails then the next step would not run right which is the

12:10:49which is the build which is the test test app job you can see now the moment it completes it jumps

12:10:56to the chest test app version now and now you see a dependent shop and it runs the yolo command and

12:11:02that's pretty much it now this is of course fun but how do you get the data from previous job to

12:11:08the next job because that is pretty much you know you would be doing a lot of times so there's a way

12:11:13to do that and we're going to discuss about that how you can get some information from between the

12:11:18jobs in the next video that is all for this one i'm gonna see you in the next video really soon

12:11:28hey everyone welcome back and in this video we're gonna be taking a look at how you can pass

12:11:34information between two jobs now this this becomes super important and super interesting because in

12:11:39this case for example we want our second job to run end-to-end tests and the first job just

12:11:45builds and deploys right now the reason you need to pass information between them in a special way

12:11:51is because if you take a look the different jobs all the different jobs run in completely separate

12:11:57environments you can see it starts from scratch it does not share the file system or the underlying

12:12:04uh anything variables or anything as well from the previous job from the previous build right

12:12:11so this this becomes really important that you understand why we need to transfer this

12:12:16information in a special way now the way you do that is using a special syntax we

12:12:23said we echo a special variable we call as we're going to say set output output

12:12:31we're going to set this name in form of a pair right so in this case let's say if i want to

12:12:37send this link or send some information send some text over here and this text should be hello world

12:12:45from build job right a simple enough text string now the way i have exposed this is that there is

12:12:53this variable text in this particular job which can be read by any other job which needs it

12:13:00this step is also important so if i copy this text and mark this as a export kind of thing now

12:13:08again we are we know that yaml is not strictly speaking a language but you can still use these

12:13:13features because github provides them out of the box you can add an outputs key over here and say

12:13:19that hey my text variable would be a variable which would be available from steps dot and

12:13:25then you have to add the id of the step which you want where this particular variable is exported

12:13:32in this case we do not have an id on this so we're gonna say something like id as final step or you

12:13:40know let's just say finished something like that and then steps dot finished and then the name of

12:13:48your variable right in the output section so this is text so what we are essentially saying over

12:13:55here is that the output we are setting the output variable of text to this particular string job

12:14:03and we are marking that hey this particular text is the output of this whole job itself this build

12:14:11app itself now you can consume this particular output inside of your basically in your next shop

12:14:19which needs this particular thing and the way you do that is with another special syntax of github

12:14:27just like we used in the in the you know secrets part so i can say my job output as

12:14:38needs remember this needs thing which we did dot build app dot and let me just go ahead and

12:14:46mark this as build app because the dashes makes me a little nervous because that's not how you

12:14:53usually write in programming languages build app and we will also need to change this to build app

12:15:00then needs.build app dot outputs and dot text why because outputs.txt is the property which gets

12:15:09outputted right and once you do that and once you try to use this right here it should just

12:15:15spit out this particular string from the last job so now if i go ahead and say

12:15:21dependent jobs with data sharing then this should pretty much be everything you would probably need

12:15:31in a in most of the cases this is all you would need to work with github actions in general

12:15:36right you have a build step you have a test step you can use this area to not just send a static

12:15:42string but you know something like the dynamic deployed url of the staging or the preview write

12:15:48it here read it from here and send it to your cypress runner or something and why stop here

12:15:54after test app for example you can have another step which says like the email the deployment

12:15:59status where you get an email from github i mean you by default also get emails from github on

12:16:04the default action status but yeah i mean you can why not just add it as a step so you can see our

12:16:10build app step is completed now we are waiting on the test tab part and right here if i take a look

12:16:18you can see it says me hello world from build shop which is exactly what we wrote as the string over

12:16:24here so yep that's pretty much it for dependent jobs with data sharing super important stuff

12:16:29for building your custom pipelines that is all for this one i'm gonna see you in the next video

12:16:35really soon if you're still watching this video make sure you comment down in the comment section

12:16:39i watched this video till the end also if you're not part of code dam's discord community you are

12:16:45missing out a lot on events which we organize on a weekly basis to code you already know the

12:16:51drill make sure you like the video subscribe to the channel if you haven't already and thank you

12:16:55so much for watching hey everyone welcome to the linux cli fundamental course this is a part of

Linux CLI - Learn the basics of bash

12:17:01code i'm back in learning path and in this course we're going to be learning so much about linux cli

12:17:06fundamentals that you are more productive and you are more familiar with the command line interface

12:17:13if you're somebody who who's new to linux cli or maybe you just know some sort of commands you can

12:17:18change directories here and there trust me you're gonna be a thousand times more productive once

12:17:23you're done with this course so let's see why we should go ahead and start with this course

12:17:28in the backend learning part before we do anything else first thing is that you usually work with cli

12:17:35with servers so if you are working on any sort of technology whether it's node python

12:17:40php anything if you're working on cloud if you're working with actual real machines you have to ssh

12:17:46into them and the moment you ssh into a server you are into the cli of that server now there are

12:17:52some ways people use gui to work with servers but when you're working with linux servers the most

12:17:58common way to interact with them is using command line you can pretty much do anything a gui does

12:18:07and more right so you have so much power with cli to customize your operating system customize the

12:18:14actual configuration files which your operating system reads and write and a lot of time you do

12:18:19not have that luxury with gui gui can do a lot of things but not everything and cli tools are easier

12:18:27to build by developers and they're easier to ship as well so cli does a lot more than a gui can do

12:18:36operations with cli a lot of times they are much much faster and you as an individual can be much

12:18:42productive than a gui for example let's say if you want to append a certain string to every

12:18:49name of the file in a folder and you have let's say a 10 000 file list in a single folder with gui

12:18:57it would be a nightmare unless you are using some sort of automation program but with cli if you

12:19:02know the right commands you can go ahead and start doing those things very easily and within a couple

12:19:07of seconds maybe less than a second you will be done and would be much more productive and finally

12:19:14you get that those hacker fields right when you're working with cli you actually have that sort of uh

12:19:20wipe within yourself that you actually know you are actually doing something you know stuff so

12:19:26this is like the coolest thing of knowing cli and working in front of your friends and colleagues

12:19:32the objective of this course is going to be introduce you to linuxcli as a back-end developer

12:19:38now this means that we're going to be working with a lot of cli in this whole learning path

12:19:43but this course would specifically focus on some of the things which we might not just cover um

12:19:50directly in other modules right so we're going to be focusing on the most common things

12:19:55which we will not cover we're going to be using cli for the whole part and would be learning for

12:19:59the whole back-end learning path but this course just dedicates some time a good amount of time

12:20:06to learn cli in a much better way then we will be working with and writing simple bash scripts

12:20:13so that you actually understand the nuts and bolts of things you're working with most of

12:20:18the time you would not be really writing bash scripts but instead actual you know programming

12:20:23scripts within your programming language but you should still know how to interact with

12:20:27uh bash scripts or zsh scripts or whatever shell you're using so we'll be working with that as well

12:20:33we'll also be using common linux commands which are super powerful and helps you dig

12:20:38a lot deeper into your operating system your application performance

12:20:42and allows you to monitor a lot of things so that is pretty cool we'll also be learning

12:20:47about shell configuration files you know along the way how you can configure your shells how

12:20:52those configuration files actually work how you can look back into past which command you ran

12:20:56stuff like that and finally we will also be creating some small project

12:21:01apps that is some tasks to do with the help of goddamn classrooms where you instead of

12:21:07the static video content will be actually going ahead and taking a look at hands-on practice

12:21:14very soon so this is the objective this is the whole picture of what is gonna happen in the

12:21:20course i'm pretty excited to start everything in this course with you guys let's just make

12:21:26the best out of it that's all for this video i'm gonna see you in the next one very soon

12:21:31hey everyone welcome back and in this video we'll be taking a look at what actually is linux now we

12:21:38are starting with linux cli which is all fun and good but you'll appreciate the usage of linux even

12:21:44more when you have the background of what it is what it actually consists of on a surface level

12:21:51so linux basically when you're talking about any operating system or any distribution in linux for

12:21:57example if i say you install ubuntu or anything what it consists of are basically three things

12:22:04the kernel the operating system tools and then the distributions so the kernel is basically a piece

12:22:11of software which is responsible for interacting with the underlying hardware now you see that you

12:22:17have all those ramps and hard disks and you know all sort of chips inside your computer

12:22:24there should be some software which is managing everything everything in the hardware section

12:22:30which is interacting with these hardware sections which is checking if there's a fault with hardware

12:22:35or not if you are able to perform a certain action or not all the low level things right so that

12:22:40particular software is kernel let's let's actually move on to the slide for kernel as well so it's

12:22:46basically the core of any linux distribution and it is shared by all the linux distributions

12:22:53the android which you use right on your mobile phones chromebooks anything which uses linux

12:23:00under the hood shares the linux kernel it is a bridge for hardware software just like i said

12:23:07it allows other softwares built on top of linux kernel to interact with the underlying hardware

12:23:13for example if you want to calculate a certain operation if you want to add two numbers your

12:23:19program which is running need not really know about hardware right it need not really know about

12:23:25how it should store a number on to the physical memory so that work is handled by the linux kernel

12:23:32whereas the programming languages and other things at the top just handle the logic and the actual

12:23:38code responsible then linux kernel also manages hardware interacting with all the hardwares you

12:23:45know when you're installing a certain driver for a certain hardware and that means you are making

12:23:49sure that the linux kernel is able to interact with that particular hardware in that sense

12:23:55then the next thing is the tools now kernel with itself cannot really work in a very great way it

12:24:03would not be very useful because it's just the underlying software which can talk to hardware

12:24:09so you need tools on top of kernel to help you as an individual developer as an individual person

12:24:16to help you to run certain programs right so there's this collection of tools which is

12:24:22built on top of linux kernel then enable you to interact with hardware by writing your own code

12:24:30so for example you must have heard about gcc it is used as a compiler to compile c programs so

12:24:37that is one example of a tool gnu is a collection of these tools right so gnu is a huge collection

12:24:44of all these useful tools and it ships with linux and shipped with linux very first time as well so

12:24:51gnu slash linux was the name was the actual name given to the linux operating system although a lot

12:24:57of people just drop off g and u and just stick with linux and say it's an operating system

12:25:02but if you want a full operating system you are actually talking about gnu slash linux

12:25:07because linux ships with the kernel or linux actually shipped with the kernel when it was

12:25:12released and the gnu consisted of all the tools which were required in order to actually call it

12:25:18an operating system in order to actually make it usable by humans finally the layer above

12:25:25tools is the distributions now the distributions like you can see on the screen kali linux centos

12:25:31ubuntu alpine there are so many distributions of linux basically aim at mostly two things

12:25:39the first one is the package manager included in the distribution and the second one is the

12:25:44goal of creating that distribution right now for example take example of kali linux it is

12:25:52a distribution which is more oriented towards penetration testing people which want to get

12:25:59into ethical hacking which they want to have all those tools and environments ready for themselves

12:26:04metasploit you know any any sort of tool which is super common in pen testing environment so that

12:26:10is the goal of kali linux you take alpine on the other hand alpine's docker image for example has

12:26:16a size of 5 megabytes so it's a super small image which consists of just the required bits to run an

12:26:23operating system as a cli so there are different goals for different distributions but all of them

12:26:30really share the linux kernel that is the basic functionality which enables a linux

12:26:37program to interact with the hardware which is shared among all of the distributions but they

12:26:43might have different packages installed they might have different package managers they might have

12:26:47they might have different goals in mind but at the end of the day all of them are linux distributions

12:26:53so this was a little bit about what linux is i hope this gave you a little bit idea about

12:26:59um you know working with linux in general really means that you are working with a wide variety of

12:27:05operating systems and a lot of your knowledge for example if you learn linux or ubuntu

12:27:10a lot of that knowledge would be transferable on let's say centos or let's say alpine because even

12:27:16though there might be a little bit variations in the installed tools but the underlying concept

12:27:23the underlying management of things the memory and the hard disk and all that stuff would be

12:27:29same because of the shared kernel so yeah this is pretty much it for the introduction part

12:27:34let's move on to the next video hey everyone welcome back and in this video let's start

12:27:40with the practical linux cli which we have been waiting for so we're not gonna get into a lot

12:27:46of theory first and just jump right on to what we have to do here that is learning about cli

12:27:52so first things first i want you to install and you know just set up somehow an operating system

12:27:59which would be ubuntu favorably because i will be using ubuntu in this whole demonstration if you

12:28:06have some other cli if you have some other linux distribution that is also fine because the basics

12:28:11of linux are just gonna remain um pretty much more or less same irrespective of the distribution

12:28:18so once you have ubuntu setup on your system open the terminal you can just go to the application

12:28:26manager of your operating system and just search for terminal all linux distributions are gonna

12:28:31have a terminal so go ahead and open that and you should have something like this now your

12:28:37username right here might vary it might be something else at the rate your host name might

12:28:42also vary so this is your username which is the current user which you are logged in as and this

12:28:47would be your host name right which is the name of your computer sort of this at the rate means

12:28:52that this user is logged in at this computer also root is a common word in linux terminology which

12:29:01means somebody who has access to everything so if you are root that means you have access to every

12:29:08thing you can do possibly on an operating system so it might sound dangerous just like you know

12:29:15it actually is as well so we are still gonna i'm just still gonna keep it to root because i'm just

12:29:22teaching you but you might see something else here depending on how your system is configured

12:29:27so anyway once we are done with this you can see the next thing is we see that there's a sort of

12:29:33a column here and then a slash and then a hash now you might see a dollar sign here

12:29:38right this hash appears when you are signed in as a root user right if you are signed in as

12:29:44some other user you'll see a dollar sign here that is it this hash just determines that hey

12:29:50you are working with super powers so if you see a dollar sign here do not be confused

12:29:54then you have a sort of a cursor right here where you can basically write anything

12:29:59and hit enter and it's just going to spit out some information that this would not be found if you

12:30:04write just anything right but we you can see that we have a space to write something so there's that

12:30:10you can see that there's not a lot of gui going on here you can only use your keyboard for the

12:30:14most part and this is fine because we'll be uh using this only for the most part

12:30:22so let's start with our first command our first command would be you can see that there's you

12:30:26know we have done a lot of damage on the screen in terms of text so let's clear this out and how do

12:30:32we clear this out is by writing clear in linux and hit enter and there you go so if you write

12:30:39you know anything which is garbage and then maybe you want to clear out the screen or if you have

12:30:45done just a bunch of things and you want to clear out the screen you can write clear as the command

12:30:50and hit enter once you do that your contents would be cleared so there's your first command

12:30:58the second command which you should learn is a valid command right so we have just seen clear

12:31:03but it does not really do anything so let's learn about echo as well so echo just like the name says

12:31:10it echoes back what you're saying so if i write echo right here and let's say i write hello

12:31:17and hit enter you're gonna see that we get hello written on the terminal again so it's sort of like

12:31:23you know talking to a mountain so you say something it says that thing back so if you

12:31:28write echo hello it says hello there's one more thing you can write something like this or you can

12:31:37say hey i want something like this but see that this time we are using quotes to encapsulate this

12:31:44thing right so quotes basically means that hey i want this whole expression and if i hit enter

12:31:51you still see that we did not get quotes but we just got the text between these quotes now why

12:31:57these quotes are important because sometimes you might want to write something here which has a

12:32:04special meaning right it might have some special meaning and you want to perform a special action

12:32:10which we're learning which you'll learn later on but these quotes just provide you a sort of a

12:32:17feature or a sort of a safety that the text you want to echo out is echoed out in the correct way

12:32:24so it's fine if you just have regular text you can go ahead and use it without quotes as well

12:32:29but you can go ahead and use single quotes or double quotes both of them work just fine

12:32:36once we are done with this you can just clear it out and you know you can just say uh hello

12:32:40world for the first time like this so this is your first command your first introduction with linux

12:32:47i hope you were able to follow along if not let me know below and i'll be happy to help that is all

12:32:52for this video let us move on to the next one hey everyone welcome back and in this video let's just

12:33:00take a look at you know just let's take a step back rather and see what we are actually doing

12:33:06you see we are actually writing commands right we wrote echo and clear in the last video

12:33:12but where is exactly where we are writing commands you see i told you to open terminal but what is

12:33:21a terminal really so terminal basically means that it is sort of a window which runs a program which

12:33:29is called a shell so a shell in linux is basically responsible for providing you a interface like

12:33:38this where you can actually write commands and you get response and all sorts of stuff happen right

12:33:43so you can execute programs you can write commands so it's shell is itself a program which runs your

12:33:53commands right so you see then when i write a bad command we get bash this command was not found so

12:34:03you know we can understand about command not found that is common english we can understand this is

12:34:08what we wrote so that's fine but you see this bash right here this bash means that this is the shell

12:34:16so bash is our shell which is saying that hey whatever you wrote i was not able to understand

12:34:21that and therefore i cannot execute this so i'm just gonna say that hey this command was not found

12:34:27there are a lot of shells as well so if you are probably if you are running linux you would be

12:34:35if you are running ubuntu for example you will be using bash by default right if you are running

12:34:41a distribution which is not strictly speaking linux but is linux like for example mac os then

12:34:48by default mac os comes with zsh shell so zsh is also a shell which is like bash for the most part

12:35:00but has a lot of differences as well in terms of commands and everything so if i just go ahead and

12:35:06show you zseg you can see this is my mac os shell so this is an ubuntu shell trust me i'll just show

12:35:13you why i can say that this is ubuntu later on but you have to trust me for now this is an ubuntu

12:35:19shell this is a mac os shell right so yeah i mean if i try to write something which is invalid here

12:35:26you're going to see that we get zset instead of bash here so we can see that hey the shell

12:35:32for this particular environment is zerus h and for this particular environment is bash so you can

12:35:38have different shells there is also a fish shell and yeah there's also the research there's also

12:35:46bash there can be a lot of other shells as well most popular shell is bash because obviously it

12:35:52comes with a lot of distributions by default but these other shells you see like zsh for example

12:35:58or maybe fish shell these shells provide you a lot more interactivity these shell provides you

12:36:04a lot more features sort of in terms of commands and everything but at the end of the day bash and

12:36:09zero such have one common purpose and that is to allow you as an end user to execute programs right

12:36:18so yeah i mean this is pretty much it for having a little bit of knowledge about differences in shell

12:36:25pretty important stuff but you know something which a lot of people overlook in their initial

12:36:31days that is bash is not the only way not the only shell for executing commands

12:36:37however most of these shell just like i said share a lot of common commands so

12:36:43just like i said between distributions as well as between shells you can transfer a

12:36:48lot of knowledge so if you learn something on bash if you learn a bunch of commands on bash

12:36:53similar thing would work on zero such as well for example this hello world is just gonna work

12:36:59fine on z as well we get similar thing but it's a different shell so there's that

12:37:06and that is all for this video let me just quickly catch up with you in the next one hey everyone

12:37:13welcome back and in this video let's take a look at how you can browse your computer on a single

12:37:20shell so on this shell which we have which is the bash shell how you can browse your computer

12:37:26now on gui you know that you have all those files and folders and you can double click on an icon

12:37:32or double click on a folder to open it you can double click on a file to open it but

12:37:36it's obviously different in a shell because you do not have access to a cursor well you do have

12:37:41a cursor access but for the most part you will do all of the stuff with code or with your keyboard

12:37:48so how do you start well you see first of all this slash right here the slash basically means you are

12:37:57at a path which is the root of the of the whole um file system right so by root i mean that there's

12:38:05nothing below this right so for example if you are nested in let's say a photos folder which has

12:38:14subfolders like 2018 2019 2020 2021 then 2020 for example has let's say a march folder

12:38:22then march folder has let's say uh 23rd of march folder so you see you were inside the photos

12:38:28folder then 2020 then march and then 23 right similarly if you start going back from 23 you

12:38:36can you will go back only to the root the the main photos folder now how far can you really go back

12:38:44if you keep on doing that this is how far you can in linux that is a single slash so all the parts

12:38:51in linux if you are talking about absolute parts would be something like you know root folder then

12:38:59folder one folder two then maybe somewhere down the line you might be able to let's say store a

12:39:06file called my 23 march pic.jpg right so this is gonna be the whole path of that particular thing

12:39:17which you're trying to open or which are trying to which you're trying to manipulate in some way so

12:39:23in linux just like this is just a quick another tip if you do not know about this you see this

12:39:29what what is this thing which appeared well that is because i write i wrote control c right here so

12:39:36control c is basically um a quick little command to cancel what you're doing right now so instead

12:39:43of if you have written all the stuff and you do not want to execute this but you want to remove

12:39:48this so instead of just pressing backspace all the way down what you can do is press ctrl c and you

12:39:53will not be executing this at the same time you will be back to a new line so there's that right

12:39:59so yeah let's come back to the browsing your computer in this one so what i can do is i can

12:40:06tell you about another command which is called pwd so pwd stands for print working directory right so

12:40:14print working directory means that hey just echo out a directory in which i am right now and you

12:40:21do not really need the echo keyword instead in front of this because this automatically echos

12:40:26right so if i enter this you see that i just get a slash this is because i am in fact in uh in that

12:40:33particular directory and this is what it tells me to so let me just go ahead and ct this is another

12:40:40command which is change directory let me just go ahead and cd into a directory called root

12:40:46now you might or you might not have this directory but i'm sure that i have why i'll just tell you

12:40:52in a couple of videos but just stick along for now so if i try to cd into root and hit enter

12:40:59you can see um this sort of change to a the tilde sign right which might be confusing but

12:41:06don't worry about this but once i do that you can see this has changed from slash to something else

12:41:13and if i do pwd right now and hit enter you can see it actually tells me hey that you are

12:41:18inside the root directory so what has happened well pwd tells you that which directory you

12:41:25are in currently and cd allows you to change the directory now cd actually allows you to specify an

12:41:35absolute path or a relative path here so cd root basically means that go into a folder called root

12:41:43which is in the current directory right whereas if i do cd slash root this means go into the folder

12:41:53called root which is at the root of the directory root of the file system right so in this case what

12:42:00we are doing is i want to go into the root folder but that should be in the root of the file system

12:42:06so if i hit enter nothing sort of happens why because this folder is actually this folder itself

12:42:12in which we already are so that is why nothing happens if i try to just do cd root instead

12:42:18you can see that bash tells me that hey there is no such file or directory

12:42:22because there's no folder called root within the current directory because we are already inside it

12:42:28so i hope this is clear if i do a pwd we are still in root if i do cd slash and that's it and

12:42:34hit enter you can see that we go back to our root directory and if i do pwt here we are again inside

12:42:40the root directory so that would be a little bit information about how you can work with file

12:42:45systems in linux that's how it all works in the next few videos we're gonna be learning more about

12:42:52common commands common linux commands which would be super helpful to you and uh yeah let's just

12:42:58start escalating the level now so that would be all for this video i'm gonna see you in the next

12:43:03one hey everyone welcome back and in this video we'll be learning about our first linux commands

12:43:09the first one is gonna be ls so ls basically means list right so if you write list you can

12:43:15see that we just got removed we removed the i and d from it and just ended up with ls so if you hit

12:43:22that and enter that you're gonna see you get a bunch of stuff here so this is basically what

12:43:28you actually see inside of a file explorer for example when you're browsing your computer using

12:43:33a file explorer you see all sorts of folders so these are all sorts of folders which you can see

12:43:39right now um in the last video what i did is i seeded into root and how did i know

12:43:45that root was a folder you can see right here root is listed as one of the folders right here

12:43:51and how did i know that root is a folder and not a file i'll just tell you about that later on

12:43:56but right now you can see that there are other folders as well for example this

12:43:59etc folder so let's just cd into that and let's just hit enter uh ls and hit enter and you can see

12:44:06that you know there's a bunch of different files now depending on your shell your shell

12:44:13if it has colors sometimes it just lists files as different colors and folders as different colors

12:44:19for example in our case you can see my shell bowls the names of folders and the names of files are

12:44:26not bolded right so obviously you cannot cd into a file so let's say if i try to cd into this issue

12:44:33cd issue you can see that bash saves me that hey issue exists but it's not a directory so i cannot

12:44:40change your working directory into issue however if i try to let's say go into m tab so if i do

12:44:47cdm tab hit enter well i still get not a directory so that's that was a bad example that it boils uh

12:44:54the things but let's let's actually understand how you can understand which is the file and

12:45:01which is a folder in this simple shell within the simple raw shell so let me just clear

12:45:05this out first of all and inside edc what i'm gonna do is write ls and then space dash l so

12:45:13what does this mean so if you go ahead and hit enter you're gonna see that you have

12:45:17a bunch of output which might be super weird if you're seeing this for the first time but what

12:45:24is really happening here is that ls-l allows you to list all the files that is fine which

12:45:30we were already doing but with a lot more details about a particular thing right so you can see for

12:45:37example this is a file and how did i know that you see that this first character is a dash right so

12:45:44for any case if the first character is a dash in front of anything that is going to be a file

12:45:50otherwise you can see this is a d which means that this is actually a directory

12:45:54so if it's a d forget about everything else right forget about everything else if this is a d

12:46:00then that means it is a folder if it is a dash then that means it is a file so if i try to go

12:46:06into alternatives for example so if i do cd alternatives and hit enter you can see that

12:46:12i am inside that particular directory now if i do ls you can see we have again same thing but cannot

12:46:17really trust the bold font because it has ditch to me once so let's just do ls la again uh lsl would

12:46:24also work right so this is it and once we do that you can see that all of these are files right so

12:46:33there's no d right here there's this l which means something else we'll discuss that later on but

12:46:38this is not a folder because a folder would have a d here so this is how ls would work in a nutshell

12:46:46hopefully you have a better understanding if i go back to my directory you can see that if

12:46:51i do ls here lsl here you're going to see that we have all these bunch of directories with us

12:46:57right so you can see ddd now i said that l would not be a directory but sometimes it could be

12:47:05it's little bit tricky right l just means that this is a magic door sort of thing

12:47:13which really means that it just points to some other file or some other folder on the system

12:47:20right so you see that bin in our case is actually a directory so if i do cd bin i'm actually in a

12:47:27folder but this is an l this is not a d right but still it is a folder why because it is pointing

12:47:34to another folder on the system so you can see that user is right here which is a d so if i go

12:47:41back and if i go into user you can see that i can go into bin as well so i'm inside user bin which

12:47:48is same as going into cd slash bin so these two directories are same we're gonna cover this later

12:47:55on but for now just understand what ls is and how it works so if i do lsl here inside user bin you

12:48:01can see that we have a bunch of files which have a dash then we have some special things with the l

12:48:08and we do not have a lot of directories here right so we do not know so yeah this is pretty much

12:48:16how you're going to work with ls ls on itself is pretty much you know you're going to get all the

12:48:20files but when you do lsl it kind of becomes a little bit more organized because you get

12:48:25a single fine on each line and yeah it becomes sort of more readable as well so that is all for

12:48:32this video i'm going to see you in the next one with some more commands with some more insights

12:48:36on how you can use a particular thing but this should get you started with ls command at least

12:48:43hey everyone welcome back and in this video let's just go over through basics of linux command again

12:48:48which would be the cat command now you see right now i am inside the root directory if i do pwd you

12:48:55can see that if i try to do lsl here you can see that i have a file which is called index that is

12:49:02it right so in linux there's a special thing if you're coming from a windows environment that you

12:49:06can have um sort of all sorts of files without extensions so extensions are not really um the

12:49:14concept of linux although you're going to see all of a lot of files with extensions but you

12:49:18can have files without extensions as well a lot of meaningful files that is right so once we see this

12:49:26index file you know i know that this is a file i know that it exists right here because i can do ls

12:49:32but how do i read what is inside this file with let's say a gui you can just double click this or

12:49:39maybe just right click and open with a text editor but how do you read inside a terminal what is

12:49:44inside this file there are a bunch of ways but the most common one is to use a software called cat

12:49:50so cat is a binary which is again very common and is available with a lot of shells right so we are

12:49:57using bash it is also available in zset or fish so you just do cat and write the name of the file

12:50:03in front of it and hit enter so you see i did cat index and i got 1000 this means this was written

12:50:10inside this particular particular file right so there's that so how do you read from something

12:50:18like this is using cat now let me just quickly go ahead and create another file here for you

12:50:24and we'll read from it also all right so now if i do ls you can see that i have a file

12:50:30as well as index so we just did get index and we got a thousand if i do cat file we get

12:50:36this is a string right so file actually contains this string called this is a string so this is how

12:50:42you're going to use cat you're going to use cad so many times a lot of times because you're going

12:50:47to be reading files from terminal all the time because it's really infeasible if you're working

12:50:51with terminal and you switch to gui to open a file in text editor so that's the introduction

12:50:56basically to cad that's all for this video i'm gonna see you pretty soon in the next one

12:51:03hey everyone welcome back and in this video i'm gonna show you a quick way to determine your linux

12:51:08operating system most of the linux distributions ship with this file you know you remember that

12:51:13initially i told you how you can go ahead and determine your operating system and how i am using

12:51:19ubuntu here but how can you trust me when i'm saying that i'm using ubuntu and not maybe centos

12:51:25so to do that to tell you that i'm actually using ubuntu what i'm gonna do is make use of cat

12:51:31and i'm gonna read a file which is sitting inside this etc folder so i'm gonna first of all go to cd

12:51:37slash i'm gonna do ls you see this edc folder let's go into that ls you can see there are a

12:51:43bunch of files but there's a special file let me just see is this is called os release so let

12:51:49me just do lsl here and see that this os release is actually this particular file but it does not

12:51:56matter right this is still a file i know that this is a file but it points to user lib os release but

12:52:02it's fine we can operate with it from here also so what i'm going to do is just say cat os release

12:52:09and hit enter so what happened is that cat told me that hey these are the contents of these this file

12:52:17and we get all this information so you can see that the name of this operating system

12:52:21is ubuntu and the version is 20.04 there are a bunch of other tags and information as well

12:52:27but for the most part we should be done and satisfied with these first two things right

12:52:32so this name is ubuntu and the version is 20.04 so yeah that was a quick video on determining

12:52:38your operating system you can just go ahead and run this command from anywhere so for example if

12:52:42you are inside root and if you go ahead and run cat edc os release this is also going to work

12:52:49because instead of now giving that a relative url the relative path not really url relative path

12:52:56you're giving it an absolute path and this is also fine right for example if i have ls with

12:53:02a file here if and if i do cat root and then file then you also get this is a string right

12:53:10so it does not matter if i do cat file or if i do a full path from the root directory that is also

12:53:16fine so yeah that's pretty much it for this video i'm gonna see you really quick in the next one

12:53:22hey everyone welcome back and in this video let's just take a look at how you can actually read big

12:53:28files on linux inside terminal so you see i have three files here and if i try to cat this big text

12:53:36you're gonna see that it actually overwhelms the whole screen it fills the whole screen and we have

12:53:40to eventually scroll up and down for in order to read this file right so what happens is that a lot

12:53:47of times for example if you're running a back end which generates a lot of logs and if you try to

12:53:51cap that thing you're going to be lost in all those logs so what you want really is to read

12:53:57them in sort of like pages so how you can do that is using the less command so you write less space

12:54:05the name of the file which you want to read just like we did in cat which would be big text or txt

12:54:10and you can see that suddenly this file opens from the very start you can see this is the start of

12:54:16the file we get the name of the file here and i can use my arrow keys to browse up and down so if

12:54:23you i can go up in the file i can go down in the file and once i reach the end of the file it says

12:54:27me that this is in fact the end of the file so you can see i can go up down and this is how you can

12:54:33read large files and with the help of sort of you know a sort of pagination instead of just

12:54:41throwing the whole file on your face right away and just to quit this interface just hit the q

12:54:47key so once you hit the q key you're going to be out of this interface right otherwise you can use

12:54:52arrow keys to go up and down so this was a quick introduction to less command it's pretty useful if

12:54:58you are working with logs and stuff so yeah that's pretty much it for this video i'm gonna see you

12:55:03in the next one hey everyone welcome back and in this video let's just take a look at the

12:55:10make directory command because at the end of the day you will be using all sorts of making

12:55:16files and folder stuff from the cli all the time so in gui what you will typically do is go to a

12:55:23folder right click and select a new folder and then a new folder will appear and then you will

12:55:28write the name of the folder and hit enter which seems like a lot of work if you think about it

12:55:33for us action as simple as creating a directory in terminal it's just two steps the step number

12:55:39one is to go to a directory where you want in our case we are already inside that directory and the

12:55:45second step is run this command called mkdir and then the name of the folder so for example my own

12:55:52folder and hit enter and that's it if i do ls now you can see i get my own folder and i can

12:55:57actually go ahead and cd into this so you see um i can ls this ls but it's empty so we're not going

12:56:05to see any file if i do lsl we can see that there is no file right here so there's that now with cd

12:56:11a quick neat trick is that you can move a folder back right you can move a folder back for example

12:56:18i'm inside my own folder right now i can move to this home directory or my cd root by just writing

12:56:24cd dot dot so this dot dot really means that go back a directory so this would really work like

12:56:32this as well cd dot dot slash dot dot so this means go back a directory then again to go back

12:56:39a directory so if i hit enter you can see i'm back into the slash so if i do pwd i'm back in slash

12:56:45if i do a cd dash this command right here means that go back to the directory which

12:56:53you were working in before coming to this so if i go ahead and enter this you can see i directly

12:57:00go into this my folder directory and if i pwd into this you can see um that we are actually back into

12:57:08into our my own folder right similarly you can for example let's just go ahead and make folder 2

12:57:14and cd into this right and now i'm inside my own folder folder 2. i can go cd dot dot dot dot

12:57:22and i'm inside still the home pwd there we are cd dot dot we are in the root directory if i do

12:57:28cd dash i'm gonna get back to root directory because that was the last directory i was in

12:57:35and yeah this is how pretty much it's gonna work one quick thing which you should understand with

12:57:40make directory is that you cannot just really go ahead and make multiple folders with it

12:57:46with the same syntax so if you want folder 1 folder 2 folder 3 like this structure and if enter

12:57:54you can see that it gives you an error why is that error because you know it can go ahead and

12:57:59create a folder one but it cannot really go ahead and create nested folders within itself unless

12:58:04this is created so how do you instruct instruct make directory to create these nested structure

12:58:11is by passing a flag called dash p now this dash p is basically a flag and we have not discussed

12:58:17flags really but whenever you write a command and you write a dash and then something that

12:58:23really means that you are passing a flag a flag is basically an extra information to a command

12:58:29when you are executing it so now if i write folder 1 folder 2 folder 3 and hit enter you can see we

12:58:36get no error and if i do ls you can see we have folder one we have folder two and we have folder

12:58:42three so you see how easy it is to create nested folders with command line and it will take you a

12:58:48lot of time if you do it with gui right because you have to just repeat all those five six steps

12:58:54again and again in every directory so i can pretty much just go back to let's say root and then i can

12:59:01use cd dash to jump back into all the folders so it's sort of a sort of a video for both cd

12:59:08and mkdir in this one which obviously stands for make directory if you haven't figured that out yet

12:59:14but yeah this is how you're gonna use mkdir and uh yeah that's pretty much it for this video

12:59:21i'm gonna see you in the next one hey everyone welcome back and in this video let's just go ahead

12:59:25and learn about the remove command now you can see that we have a lot of clutter going on here

12:59:31so let's remove some files and folders so there's a command in linux called rm which just stands

12:59:37for remove and you can give it a file in front of it so for example if i do an index and hit

12:59:43enter what it's going to do is remove that file so if i do an ls now you can see that that file

12:59:47is no longer with me it's pretty much similar to how you're going to delete a file using

12:59:54the gui but the difference here is that when you use the rm command there is no trash on linux

13:00:01right so your gui provides you that convenience that if you delete a file you can restore it but

13:00:07with rm it does not go to trash it's just deleted from your computer you can no longer access it

13:00:14so this pretty much works with files nicely but if you are for example in a folder if you try

13:00:21to remove a folder what's going to happen is that it's going to say you that hey you cannot remove

13:00:26a folder because it's a directory now with rm in order to remove a folder what you have to say that

13:00:34hey just go ahead and open this folder and delete everything in it as well because deleting a folder

13:00:41literally just means that deleting all the files in the folder first and then deleting

13:00:45that folder itself so how do you do that you do that by passing this dash r flag this r

13:00:51dash r basically means that recursively go ahead and delete all the files in that folder

13:00:57so once you do that and hit enter you're gonna see that we get no error this time and if i do an ls

13:01:02now you can see that that folder my own folder is gone similarly if i try to do folder one we cannot

13:01:09really do that unless i pass the dash r flag which says recursively and go ahead and delete that

13:01:15and there we go you can go ahead and see that it does not really give us any error message

13:01:20now and if i do ls you know it will just work interestingly enough because this dash r flag

13:01:26is just meant to say that releat stuff recursively you can pretty much just go ahead and use it with

13:01:32a file as well so it does not really matter it would not throw you any errors or something

13:01:37because a file is just a single file there is nothing to recurse about it so it's fine bash

13:01:42will just you know just just take a laugh and ignore your dash r command here but this would

13:01:47become very handy when you're deleting folders because it will allow you to not go ahead and

13:01:52delete all the files manually one by one inside a particular folder so yeah that's how pretty much

13:01:57you're gonna use rm for the most part there's also a force option here but we're not gonna discuss it

13:02:02in this particular video but yeah this is this is most likely what you're gonna be seeing and

13:02:09working with in the coming tutorials so that's all for this video i'm gonna see you in the next one

13:02:17hey everyone welcome back and in this video let's just take a look at a command called

13:02:21copy which is cp which basically just means what it says that it copies a particular file

13:02:28into another location or into the same location but with another name so how do you use that if

13:02:34i else this you can see that we have big text and hello world and new file and script so these are

13:02:39some new files but what you can see is that you can understand for example if you want to copy

13:02:45this big text file and store it as a backup what you can do is just write cp which is

13:02:50copy write big text and then write the name of the new file so i'm going to say bigtext.backup

13:02:57and hit enter and if i do ls you can see if i cat this big text or if i catch this bigtext.backup

13:03:05these are both the same files right so you can go ahead and verify that from hello world as

13:03:10well so if i go ahead and cat hello world this is hello world so let's just go ahead and see copy

13:03:15cp hello world and then hello world dot backup and hit enter and you can see that if i try to

13:03:23get helloworld.backup now you can see that it is same as the previous file

13:03:29now copy that is the cp command works with folders as well so for example if i have a folder one here

13:03:36it will work with folder as well folder one for example if i want to copy folder one as folder

13:03:42two for example let's assume that this had some contents it does not right now but let's assume

13:03:47that it had some contents so if i want to create a copy of this folder i'm going to do something like

13:03:52this but it's not going to work and the reason it's not going to work is that you can see that

13:03:57this command actually tells you why is that dash r is not specified just like with the rm command

13:04:04we need dash r to remove a folder similarly with copy command we need stash r to copy a folder so

13:04:11if i do it now you're going to see that now we have folder two with us as well and if i can go

13:04:16back go into folder let's say folder one and if i go ahead and create a file by let's say touch

13:04:24xyz which just creates a empty file right touch command just creates an empty file and if i

13:04:30carried you can see there's nothing inside this but if i go back and if i try to do copy folder

13:04:37one and obviously you might want to do a dash r here folder one and then folder three now and if i

13:04:43go into folder three you can see that we have the xyz file present we also have the xyz file present

13:04:52inside dot dot slash folder one right so this is the ls4 folder one this is the ls for folder three

13:04:59and we have the xyz file present for both of them because we copied the whole folder so this is how

13:05:06you're gonna work with copy command in a nutshell and that is all for this video i'm gonna see you

13:05:12in the next one really soon hey everyone welcome back and in this video let's just learn about

13:05:18the move command now this move command basically just how copy the cp command copies the stuff

13:05:25the move command actually cuts the stuff right so it moves it somewhere else and move command

13:05:31is actually very useful in renaming stuff as well because you know if you just move a file from one

13:05:37name to another in the same directory that is basically renaming right so that's how it works

13:05:44so what you want to do for example let's just ls and let's say i want to rename this bigtext.backup

13:05:51to backup.bigtext and why do how do we do that is by using this command called mv mv stands for move

13:05:59and i say bigtext.backup and what i do is i just go ahead and say backup dot big text

13:06:06and hit enter and once i do that you can see that bigtext.backup is gone and the only thing

13:06:12i have now is backup.bigtext you can pretty much just go ahead and move stuff between directories

13:06:18as well so you can say movebackup dot big text inside folder one so once you do that

13:06:24if you go into folder one now folder one and if i ls you can see we have backup.bixtext

13:06:31inside this particular folder now and if i do an ls of the previous directory

13:06:35you can see we do not have backup.bigtext with us anymore in that directory so let's just go ahead

13:06:41and clear the screen and move backup.bigtext from folder1 back a directory this is with the two dots

13:06:49which is we have specified hit enter and again we do not have that file in this folder anymore

13:06:55oops and if i go to folder one you can see we do not have that file and if i go back

13:07:01you can see that we have backup.bigtext available with us here so this is how move works

13:07:07again you can use move to move folders as well so you can see if i do folder one inside folder three

13:07:14hit enter you can see that if i go ahead inside folder three it is containing folder one now now

13:07:22one quick thing you might have observed compared to copy is that in move if you are trying to move

13:07:27folders you do not need the recursive option right so it just works out of the box like that

13:07:33so yeah that's pretty much it for uh moving stuff with the move command that's all for this video

13:07:40i'm gonna see you in the next one really quick hey everyone welcome back and in this video let's

13:07:46just take a look at a quick command which is known as which right so this command is named as which

13:07:53and this actually helps you determine where a particular binary is located now what do i mean by

13:08:00that you can see that we have been executing these commands like ls you know pwd echo stuff like this

13:08:09all the time but honestly these commands are actually a file on your system which is a binary

13:08:18file by binary i mean it is not a human readable sort of text file it is actually a compiled

13:08:24code a compiled binary which is executed by the system so when you really call echo124

13:08:31what happens is some system level code is invoked within this binary and that is responsible for

13:08:37telling your display driver to say that hey go ahead and write one to four on the screen

13:08:42so the code for that the binary the file for that is located somewhere on the system and you can

13:08:49see that you can access a lot of things without actually going into any folder but to be honest

13:08:55when you're writing ls what you're really doing is you are actually executing a binary inside this

13:09:01bin folder which is named ls so if i go ahead and hit enter on this you can see it still works fine

13:09:08why because if you go to bin folder and if you just write ls you can see in this bin folder we

13:09:14have all sorts of binaries and ls is one of the binary right so you can see ls actually lists

13:09:22itself so it's sort of a recursive thing but you know you get the idea so you can see there are so

13:09:27many commands you can see that we just uh talked also talked about less command we will talk about

13:09:33a lot of commands we talked about cp we talked about uh you know you'll if you spend some time

13:09:39you're also gonna find mv here you can see we have the rm file we have a bunch of stuff right

13:09:45so what you're really doing is you are executing just like i said you are executing these commands

13:09:51when you are actually writing something so echo one two three four five under the hood is really

13:09:58what it's doing is it's calling bin echo and then it is executing this particular stuff right

13:10:04and uh yeah this is how it is working and what which would do is which would actually give us

13:10:11the path of this particular binary so you can say which echo and you can see it saves me user

13:10:17bin echo instead of bin echo because if you go to the root directory and if you do lsl you can see

13:10:24that bin is really a directory which is pointing at user pin and user is another directory here

13:10:30right so anyway we're going to discuss about that later on but what you should know about which is

13:10:36that it gives you the path of the binary now you might wonder that if all the binaries are just

13:10:42going to be stored in bin then wouldn't this command be useless because we will always know

13:10:47well no right because which which actually tells you where the binary is stored

13:10:53and it does not it is not mandatory that the binary would always be inside user bin or in the

13:10:58build folder right it depends on a lot of things how your environment variables are configured

13:11:03where your linux operating system is looking for the stuff so which allows you to just go ahead and

13:11:11take a look at where it is exactly calling that binary form so if i go ahead and do a [ __ ] bash

13:11:18you can see that bash which is actually this shell which you are using is located as a binary

13:11:26right here so yeah this is how which command works that's all for this video i'm gonna see you in the

13:11:32next one really soon hey guys welcome back and in this video we're gonna be learning about nano

13:11:39now nano is a text editor for command line and for the most part you're going to be using nano

13:11:47if you want well that's up to you some people prefer vim as well but i'm more of a nano guy

13:11:53you can use nano to edit files within the terminal now why is that necessary why you can use visual

13:11:59studio or something like that well just like i said you'll be working with cli a lot of times

13:12:05on server as well and sometimes you just need a quick edit right you do not really want the whole

13:12:11vs code sort of thing to boot up that's just not feasible and it's just not practical so a

13:12:16lot of times you if you need just a quick edit nano or vim is your way to go which are just

13:12:21the internal text editors of your um shells so let's start first of all if you are using ubuntu

13:12:28nano would come installed so let me just go ahead and ls first of all you can see we still have the

13:12:32big text file so what i'm going to do is i'm going to say nano and then i'm going to write

13:12:38big text and one second nano and then i'm going to say big text so here we go and right away you can

13:12:46see that a sort of interface like this opened up for us which is gnu nano like you can see that ga

13:12:54it says gnu nano because nano is a utility nano is a tool which is built on the top of linux kernel

13:13:00which we discussed in the first video right so hopefully you are able to link some parts now

13:13:06and this is the screen for your text editor might not be the best shiny screen but it is

13:13:13super performant it gets the job done so you see that it's basically again just like we had in

13:13:19terminal you can browse this using arrow keys right and you can just basically start typing

13:13:26right so it is as simple as that it's just a text editor you can remove stuff you can type stuff

13:13:32everything works fine at the bottom you can see there are a bunch of shortcuts which are listed

13:13:39so you see this this key right here which is denoted by this character this is basically

13:13:44called a control this is a control key character right so whenever you see this this means that

13:13:50you have to press control so you see that we're going to start off with this write out option

13:13:56so you see that in a typical text editor you have the option to you know just work a little and then

13:14:01press ctrl s or command s to save a file we have the similar option with nano but we have to write

13:14:08we have to type control and o so once we do that you can see it asks me the file name to write

13:14:14and i'm just gonna go with the big text only which is our original file and hit

13:14:18enter you can see once i do that it sees me wrote to 12 lines and that modified which

13:14:23was appearing here got disappeared so if i try to write it again you can see we get a modified here

13:14:29and we again get the option to write out so if i go ahead and do uh one second if i go

13:14:35ahead and do control o it asks me to file name to write big text that's it and that is all

13:14:41now we have another command which is pretty much uh exiting nano which you might might be

13:14:48wondering that how do i exit this interface and that is using control x so if you press control

13:14:53x you can exit the nano now what you can do is you can just go ahead and create a new file instead of

13:15:02reading uh or editing an old file so i'm gonna say this is hello world which is you know this

13:15:07file does not exist and nano would automatically create this file for you once you're done with the

13:15:12edits and save this so you can see i open hello world this is the name of the file it says that

13:15:16it is a new file it knows that so i'm just going to write hello world right here and then i'm going

13:15:21to press ctrl o to write it out and it asks me hey do you want to write it to hello world only

13:15:27yep that is it i press enter and then i press ctrl x to exit nano and now if i go ahead and ls this

13:15:33and if i try to cat hello world this is what it is i can also open it inside nano nano so that

13:15:40i can go ahead and for example just add an exclamation mark here and let's not just write it

13:15:46out now let's not press ctrl o let's press ctrl x directly so you can see that when you press

13:15:51control x it actually asks you before leaving that hey do you want to save this file because

13:15:56you have some unsaved changes and if you press y it's gonna save it if you press no it's just gonna

13:16:02discard the changes and if you press ctrl c you're gonna get back into the editor right and you get

13:16:07the status that hey it is cancelled so pretty cool stuff pretty cool stuff with nano this was

13:16:13a little bit of introduction to nano basically we're gonna explore more in the next videos

13:16:19um trust me if you are able to master a tool like nano or wim in a cli environment it becomes

13:16:26very easy when you are trying to interact with um configuration files on servers something which

13:16:33you really truly do not have access to in terms of gui right so yeah that's pretty much it for

13:16:38this video i'm gonna see you in the next one super quick hey everyone welcome back and in this video

13:16:45let's just learn about how you can use copy paste in nano so let's just go ahead and take a look

13:16:51at our big file or maybe let's just go ahead and create a new file so new file it is and i'm gonna

13:16:57say hello world again in this one so i'm gonna go back to the first character and what i'm gonna do

13:17:02is press my ctrl key and the carrot symbol which is this number six key so once i do that you can

13:17:09see it changes to mark set that means i can now go ahead and use my cursor in order to get the

13:17:16amount of text which i want to select right so it is your sort of way to select text so let's

13:17:22say if i go ahead and go to this thing or maybe just this thing you can see the last character

13:17:29will not be um copied or cut whatever we do right so only the characters before that would

13:17:37have action so in this case w would not be copied in this case o would not be copied but w would be

13:17:43copied so the last character is left behind so if i do go ahead and something like do something

13:17:48like this now what i have to do in order to cut this text is press ctrl k right so once

13:17:57i do that you can see that the text is gone now the text is truly not gone because it is in our

13:18:03clipboard it is in that memory so what i can do is press ctrl u to paste that text again

13:18:11and as a matter of fact our text is still in our clipboard right so i can go ahead go down

13:18:17a couple of lines and press ctrl u again to give that text back and you can see that there is no

13:18:24uh space here as well so if i press ctrl u again you can see that there is no space because space

13:18:30was our last character and it was not copied so let's just go ahead and do this again oops with

13:18:35the control 6 key that is the control caret symbol and this time i want to copy space but not w

13:18:42so there we have it right and i'm going to press ctrl 6 again which saves me mark on set

13:18:47i'm going to go down a little bit and i'm going to press ctrl k first of all oops control 6 mark

13:18:58set and we want it up to w and i'm going to press ctrl k now so you can see it's gone now i'm going

13:19:05to say control u so it restores it back and then i can just go back go down a little and press ctrl

13:19:11u again and you can see this time it copied with the space so we have all these spaces in between

13:19:16right so this is how you're going to copy paste in nano you can cut paste as well just like i

13:19:22said for cutting you will obviously use ctrl k button would not paste it here there's actually

13:19:28a way to really copy it without you know just going ahead and cutting it in the first place

13:19:33but i use this shortcut which is the control k first of all and then ctrl u to restore it because

13:19:41inside mac os if you're running mac os there is no alt key if you do have a windows keyboard if

13:19:47you do have a regular keyboard just to copy this thing for example once you have selected

13:19:52by hitting ctrl 6 and selecting this thing if you want to just copy this without actually cutting

13:19:58in the first place just go ahead and hit alt plus 6 that is alt plus caret symbol once you do that

13:20:05it will be only copied and would not be cut but we press ctrl k in order to cut it then paste it

13:20:11and it's still in our clipboard so that sort of works fine so yeah that's pretty much it

13:20:16for this video how you're gonna cut and copy and paste with nano pretty useful stuff you're gonna

13:20:22use it all the time when you're working with real files so yeah that's pretty much it for this video

13:20:28and i'm gonna see you in the next one hey everyone welcome back and in this video let's just go ahead

13:20:34and learn about how you can search for stuff in nano because that is going to be extremely useful

13:20:40as well in saving your time so i'm going to say nano big text in this one and you can see that

13:20:48we have opened this inside nano text editor let's take a look at this industry word right

13:20:53so if you want to maybe change this industry full stop to index industry exclamatory mark what you

13:20:59can think of is you know just using arrow keys all the way to the industry and it is super super slow

13:21:08right it works but it is super slow now let's say if you want to go to this simply word now

13:21:14it is a nightmare right you have to do the same thing again and you have to do something like

13:21:18this so what we can do instead is we can directly jump towards inside nano and how we do that is by

13:21:26using search in nano just like in your typical text editor you're gonna use ctrl f or command

13:21:31f to perform a search in nano you press control w and once you do that you can see it's switched to

13:21:38the search thing right here and what you can do now is start typing for the word you want

13:21:44so for example let's say i want simply right and once i do that and hit enter you can see that we

13:21:51came at the first iteration of the word simply but hey i wanted this one not this one so what do i do

13:21:58well you press ctrl w again and you can see that nano is smart enough to keep your last suggestion

13:22:04up so unless if you want to change the search word you can just go ahead and press enter again

13:22:09and there you are you are on the next word now and you can go ahead and change it for example

13:22:13let's jump to readable now this one so readable hit enter and here we are and i can do something

13:22:20like this let's just jump to lorium which is the first lorem or whatever however you pronounce it

13:22:26and there we are so this is another one this is another one this is another one we have a bunch

13:22:31of them right all the way down and there we are on the first one so here we are so this is how you're

13:22:38gonna search in nano and one quick thing you can see that you can see that there is sort of a

13:22:43uh you know sort of this character right here which is um on both sides of the screen this one

13:22:49and this one this basically means that there is text on both sides of this particular line it's

13:22:55not just um this much content right so if you go back you're gonna get more con more of the text

13:23:02one more quick shortcut is that if you are anywhere on the line if you want to move at the

13:23:08end of the line you press control e right and if you want to move at the starting of the line you

13:23:14press control a so control e moves you end of the line control a moves you to starting of the line

13:23:21and to be honest it's not just a terminal shortcut it's not just a nano shortcut

13:23:26it will work on your terminal commands as well so if you want to move within the terminal uh between

13:23:32and you know at the end and starting of the commands you can press ctrl a and ctrl e control e

13:23:37moves you to the end control a moves you to the start control e control a e a stuff like that

13:23:44so yeah i mean that's pretty much it what you can do is probably if you want to go to dummy

13:23:52and hit enter you are here and if you want to move the end of this line you press ctrl e and i am

13:23:58now at end you can also press ctrl a to go to the starting and that's how it all

13:24:03works so this was a quick tutorial on nano search that's pretty much it for this video

13:24:09hopefully this much information should be good enough for you to work with nano in a better way

13:24:15and yeah that's all for this one i'm gonna see you in the next video really soon hey everyone

13:24:22welcome back and in this video let's start with bash scripting so this in this whole section we're

13:24:30gonna be learning about what scripting is how you can do bash scripting how you can actually work

13:24:35with stuff and uh automate things with the help of coding right so you can write a bunch of code

13:24:41and execute it with bash and uh be done with it so you're gonna be learning a lot of languages in the

13:24:48back and learning path like node python you know whatever you have chosen whatever route you have

13:24:53chosen but you can also program with the help of bash because bash is not only a shell it allows

13:25:02you to actually execute shell scripts as well so there are certain ways you can write code in shell

13:25:10and to be honest whatever you have been doing so far with commands this is nothing but code right

13:25:15echo 100 for example is a code which echoes something back ls is a code which uh tells you

13:25:21what files are there in a particular directory so we're just going to be using a bunch of more

13:25:27commands than these in a shell script and would be executing them using bash as our interpreter right

13:25:35so let's get started with the bash scripting we're going to learn about a bunch of things

13:25:41in batch scripting and to be honest you do not really have to just understand or maybe just mug

13:25:47up everything because most of the things if they are relevant to you you can always google them up

13:25:52or maybe um just because we're gonna be seeing a bunch of things and a lot of them

13:26:00would not be relevant to your use case a lot of times when you're working and developing

13:26:04a shell script so you might be just using for example two or three commands out of all the ones

13:26:09which we'll be learning but nonetheless we'll be creating more a little bit of more utility based

13:26:15programs so that we can actually learn about these things and at the end we can also look at some

13:26:20code damn classrooms in order to actually build certain interactive programs using shell scripting

13:26:26so yeah that's pretty much it for the introduction part of shell scripting with bash in the next one

13:26:31from the next one we're going to be starting off with building a little bit of new projects here

13:26:35and there and learning about shell scripting as well so see you then in the next video

13:26:42super soon hey everyone welcome back and in this video let's just kick start our bash

13:26:47scripting so we're gonna take a look at some quick commands and basically we'll be doing what

13:26:52whatever we have done so far so let's just go ahead and start with a simple script so i'm

13:26:57gonna open this inside nano editor which we have just learned about and i'm gonna start with a very

13:27:03simple script i'm just gonna say this is my first echo from a script right i'm going to press ctrl

13:27:10o yup and i'm going to press ctrl x to exit this now so this basically if i do cat script now you

13:27:18can see that we have our code with us but i want to execute it now how do i execute the script

13:27:25is i want bash that is the shell which you are inside to execute this script as a

13:27:33um you know as a special piece of code so i want this to understand i want this to take in

13:27:40it as a piece of code and just not a text file which is what happens apparently with the cat

13:27:46so to do that what i'm gonna do is i'm gonna make use of bash as the utility name just like we did

13:27:53ls and you know ls or cat or less or rm things like these these are all binaries right so we know

13:28:01that these are the binaries which you can locate with the help of which command so if i probably

13:28:08try to do which bash you can see that it is in user bin bash so there it is for you it might be

13:28:14in bin bash it's fine if you can remember you're gonna realize that bin and bash pin is basically

13:28:21a directory which is mapped to user bin so these are the same two directories so if we go back to

13:28:28let's say our home directory which is i can do with the tilde symbol and if i do ls we have the

13:28:35script here so in order to execute this what i'm going to do is write bash and then i'm going to

13:28:39write script and hit enter and you can see that we just get this as my first echo from a script we do

13:28:46not get this echo we do not this get these codes no space nothing because this is an actual output

13:28:51now there's a better way to execute the script by actually making it executable but we're going to

13:28:57learn about that later on when you are learning about file permissions and stuff like that

13:29:01right now for now it is perfectly fine to use bash like this so write bash and then specify

13:29:06the name of the file so you want to execute this file it reads this file and executes all the code

13:29:13you can go ahead and edit this for example and just go ahead and say echo this is a cool

13:29:21line right and write bash script hit enter and you can see

13:29:27that even though you know this had a space because this was not a code we just got this

13:29:32is a cool line and this is my first echo so yeah this is pretty much how you're going to start with

13:29:37bash scripting this is as simple as it gets and you have actually written a bash script yourself

13:29:43which you can execute using bash script like this right so that is all for this video i'm gonna see

13:29:48you in the next one with some more things in um bash scripting so see you soon in the next video

13:29:56hey everyone welcome back and in this video we're going to be taking a look at how we can

13:30:00run a simple bash script and we just did that in the last video but in this one we'll be just

13:30:07um taking a look at more things which we can do in a bash script so let's just go ahead and open

13:30:12our new script right and this is a new script file so first thing what i'm gonna do is i'm gonna go

13:30:19ahead and say i want to declare a variable in bash right so how do you declare a variable in bash

13:30:27well you just go ahead and start writing the name of the variable so for example myvariable and then

13:30:33if you want this to be a variable you put an equal to sign without any space here make sure you do

13:30:37not have any space here and inside the quotes what you can do is just specify this is a cool

13:30:45string right and this is now a variable so once you do that how do you make use of this particular

13:30:51variable so you say for example i'm just going to say echo i am about to say something in a variable

13:31:00and then in the next echo i want to use this variable but if i go ahead and just say my

13:31:05variable like this what's going to happen is that echo would really just say my variable on the

13:31:12screen so you can see so not very helpful right so what we want to do instead is oops nano new script

13:31:21what we want to do instead is we want this to be treated as a variable instead of a string

13:31:27so how do we do that is we append a dollar sign so if you want to get a variable in

13:31:33bash that is if you want to read a particular property if you want to read that variable you

13:31:37use a dollar sign if you want to set a variable you do not use a dollar sign so you do not say

13:31:42my variable like this but simply my variable but if you want to read it you say with a dollar sign

13:31:48so if you go ahead and save this and try bash new script now you're going to see that you get i'm

13:31:53about to say something in a variable and this is a cool string which was the value which was stored

13:31:57in my variable right so this is how you're going to create variables in bash and this is how you're

13:32:03gonna basically use them in a statement like echo as well so that's all for this video i'm gonna

13:32:09see you in the next one really quick hey everyone welcome back and in this video i'm gonna show you

13:32:16how you can use bash scripting to read the past arguments to a script so what do i mean by that

13:32:24is that a lot of times you would have seen that you are running if you are running a script then

13:32:29you can pass certain arguments to it and arguments is just basically a little bit more information to

13:32:34that script so what do i mean by that let's just go ahead and open this new script file and you can

13:32:42see we have the code from our previous thing but instead of using my variable as the echo i'm just

13:32:48gonna say echo dollar one and maybe dollar two and dollar three and dollar four right so what does

13:32:55that mean well i do not have defined any uh dollar one or dollar two variables so what does this mean

13:33:01and if you think about it actually you cannot really define something like this right so it is

13:33:07an invalid statement so we are not gonna be using this and i just put a hash in front of it because

13:33:14hash is used to comment in bash so i'm not really taking a whole video to just explain explain that

13:33:21so what does this dollar one dollar two dollar three mean then well you might have guessed by now

13:33:26that it means the arguments which you are passing so if i do a bash new script and hit enter you

13:33:31see that we do not get anything at all except the our regular statement but if i try to do let's say

13:33:38cool and hit enter you see suddenly we see cool right here right and if i go ahead and

13:33:45encapsulate inside the quotes you can see it does not really matter so we are good to go

13:33:50then once we have done cool let's say i want to say dude here and hit enter and

13:33:55you can see that we get dude here as well and if i go ahead and say that this works

13:34:02hit enter you can see this works is also there and then this too you can see this two is also there

13:34:09but if i do this won't and hit enter you can see that we do not get this want why because this is

13:34:17dollar one this is dollar two dollar three dollar four and this is dollar five and if we take a look

13:34:24at inside our script inside our new script we're gonna see that we do not echo dollar five we just

13:34:29echo up to dollar four and uh yeah dollar five is this one so that is why we do not get that

13:34:37so this is how you're going to access arguments inside a bash script and use them right so

13:34:45yeah that's pretty much it for this video i'm going to see you in the next one really quick

13:34:52hey everyone welcome back and in this video let's just write a quick simple program to um

13:34:59enter a word from the user to get a word from the user and print it out right so let's just

13:35:05go ahead and first of all create a new file it's getting a little bit messy so we're gonna see how

13:35:09we can remove all of them together but let's say this is user input right and what i'm gonna do is

13:35:16i'm gonna say that first of all echo hello to my program right and then i'm gonna say i want

13:35:26to read the input of the user into a variable so i'm gonna say enter your name please

13:35:36right and now what i'm gonna do is i'm gonna say read and then i'm gonna write let's say name

13:35:43so what does this mean is that read is a command which actually hauls the program for getting the

13:35:50input and it's going to store the whatever the input the user has written inside the variable

13:35:56called name and you know that in order to access this variable i'm just gonna say your name was and

13:36:03after this i'm just gonna say name like this right so this is how you're gonna make use of it and if

13:36:10i go ahead and save this and i'm going to run this using user input you can see that it says hello to

13:36:16my program and it waits for me to enter something so if i go ahead and write me whole and hit enter

13:36:22you can see it says me your name was mahul right and let's say if i want it on the same

13:36:28line so how do we do that so for for doing that what i can do is just move this echo statement

13:36:35from this to something inside the quotes itself so inside the quotes what's going to happen let's see

13:36:42if you run this what's going to happen is if i write mahul you can see that we get

13:36:48the value directly because double quotes in bash parse very variable values right

13:36:55so you see that it started with the dollar sign so bash knew that this is a variable value

13:36:59so it's going to parse it if you literally just want to enter dollar name instead of actually

13:37:05getting the real value you should go ahead and use single quotes so if i do something like this

13:37:11and run this program again and if i enter mayhold you can see that we literally just got dollar name

13:37:16here so double quotes are gonna pass the value of your variables but single quotes would not

13:37:24so yeah this is pretty much how our program final program would look like

13:37:28and that is all for this video i'm gonna see you in the next one really soon

13:37:36hey everyone welcome back my name is mahul and in this video we're going to

13:37:40build on the top of the program which we left in the last video and let's just create a new

13:37:45program out of that but before that let's just remove all this clutter which we have so far

13:37:50so i'm gonna use the rm command and dash r command and instead of just naming every single thing

13:37:56one by one i'm gonna just go ahead and put a star here the star right

13:38:00here means everything in the current folder now make sure you do not write slash star or

13:38:05something like that because this means that you want to delete everything in the root as well

13:38:09so be careful about what you are writing with rm because it is a destructive action

13:38:15so let's just go ahead and do that and there we have it our folder is clear and we are good to go

13:38:20so let's start with our script again but this time what i'm gonna do is i'm gonna just use

13:38:27the read command in order to get a prompt so last time you saw i did your name and then we did read

13:38:34name right but name actually allows us to pass in a placeholder as well a prompt sort of thing

13:38:41so i can say read and i can say for example dash p basically means placeholder or prompt username

13:38:49and that's it so if i go ahead and run this uh not really this because we also need a variable name

13:38:54right here username so if i go ahead and run this you can see that we get username automatically

13:39:00right we did not have to write any echo statement plus there is no line break as well which is

13:39:06pretty cool let's just go ahead and edit this even more next i want to write read the password

13:39:14and i'm going to store this inside password and i'm going to say echo uh your username

13:39:21is username and that's it and i can probably say your password was wrong for example let's just

13:39:32go ahead and do that so bash script is going to give me admin and password let's say if i enter

13:39:38admin as well so you i can see that your username is admin your password was wrong so firstly let's

13:39:45just improve this a little bit let's say i want to hide this password right so how do we do that

13:39:51well in order to hide this password that is in linux a common convention is when you're writing

13:39:57the password instead of getting this as stars you get nothing at all on the screen that is how linux

13:40:03has implemented sort of the tradition way so what you can do is you can say dash s here to silent

13:40:10the input and once we do that if i run this program again you can see that i can enter admin

13:40:16i can enter password i'm all actually entering password at this time but it is not visible to

13:40:20you and hit enter so we get you know uh basically nothing so we get echo from the same line which

13:40:28we can improve by writing a new line but we get your username is admin your password was wrong

13:40:33and just to verify our changes i can actually just echo out password as well for the time being

13:40:39right so let's just go ahead and run this program again and i'm just writing some password and you

13:40:45can see we get the password but that was not visible here so it's a pretty cool feature

13:40:51and you should for the most part accept passwords like this only right so this is how you're going

13:40:56to build up a username simple username password in the next one we're going to be taking a look

13:41:00at some if else so that we can actually verify if that particular user in fact had a correct

13:41:06password or not so that is all for this one i'm gonna see you in the next video really soon

13:41:14hey everyone welcome back and in this video let's just take a look at some if else statement so you

13:41:20can see right here we have written a quick statement that if then a square bracket

13:41:26then in the quotes i'm saying username is equal to admin then i want to perform certain actions so

13:41:34let's say if i want to say and indentation is not really required so i just want to say hey you

13:41:42just entered admin as the username

13:41:46so what's going to happen is that the syntax is you write if then you write a square bracket

13:41:51give it a space and inside quotes you write the variable name and inside quotes as well

13:41:56you write the actual string name right and you also want to have a single equal to right here

13:42:03now why do you want to write variable name inside quotes that is because for example if your

13:42:08username was empty then your expression might just evaluate to something like this which is invalid

13:42:14bash right without codes but if it has codes then it will evaluate to this which is sort of

13:42:19correct right so you want admin not really admin your username to be here and let's try this out

13:42:28so i'm going to say bash script admin and something else and you can see that we get

13:42:33this line hey that you just entered admin as your username let's try to oops let's try to run this

13:42:39again but this time with admin 2 for example and any password and you can see that we did not get

13:42:46this line this time right because our conditional check did not match similarly what we can do is we

13:42:53can um extend this with the help of and and for adding more conditions so i can say and

13:43:00and password is equal to admin as well so in that case what i want to do i just want to say hey your

13:43:12credentials seems good right and that's it so let's just go ahead and run this

13:43:20and write admin and admin and hit enter you can see that it saves me that hey your credentials

13:43:25seems good if i run admin and something else then i just get these messages nothing like that so

13:43:33let's just go ahead and do that let's just go ahead and get rid of these two commands now and

13:43:38add an else block so what i'm gonna do in order to add an else block is just gonna say else directly

13:43:46and i'm just gonna say hey your login is invalid and again just to close the if block we write the

13:43:57opposite of the if that is fi and that just ends the if lock so i'm just going to say bash script

13:44:03now admin oops admin and something else and you can see i get hey your login is invalid but if

13:44:10i write admin and admin again we get hey your credentials seems good so this is how you're

13:44:17going to test for you know string equality in bash and use if else for that particular part

13:44:25and yeah that's pretty much it for this video i'm gonna see you in the next one really soon

13:44:33hey guys welcome back and in this video we're gonna be taking

13:44:35a look at how you can exit your bash script with a different status code

13:44:41now what do i mean by that well you see when you are writing something which is garbage you get

13:44:47certain output on the screen but as a person suppose suppose you do not understand english

13:44:55then can you really tell me if this command was successful or not

13:45:00well you cannot right because let's say if this output was in chinese or some other language which

13:45:05i do not understand then i won't be able to tell whether this command actually did its job or not

13:45:11status quotes allow you to determine that right status quotes are basically telling

13:45:18you once the command is done once something runs then you can read a particular number

13:45:24which is the which is called as the status code of that particular command

13:45:28so if the status code of a particular command is 0 that means that command exited normally that means

13:45:35everything was fine everything was expected and the exit was normal if it is a non-zero status

13:45:42code that means something went wrong either you know there was a runtime crash or maybe

13:45:48the command was not expecting those sort of inputs or something went wrong right so as a back-end

13:45:55engineer as a devops as somebody who's writing shell script you're going to be writing a lot of

13:46:00status code checks sometimes when you're working with scripts just to determine if they exited

13:46:05properly so how do you determine how this command exited is by actually writing echo for example

13:46:12you want to echo that out and then a dollar sign and then a question mark you might have remember

13:46:17that remember that a dollar sign is used to echo out a variable value and a question mark in this

13:46:24case again is a special variable which holds the status code of the last command which ran

13:46:31right it is not holding status code of every command it's just the status quo of last command

13:46:36and in our case it was this thing so we echo out this special variable and you can see we get a

13:46:42status code of 127 let's go ahead and just write hello world here right hit enter and then let's

13:46:49try to read the status score of this command you can see we get a status score of zero in this case

13:46:55and just like i said if the status quo is zero it is fine the command just worked expected and

13:47:00that is what really happened with the hello world there was no error or nothing like that but with a

13:47:05random command the bash failed and set the status code to 127 which means there was an error which

13:47:12means something went wrong so similarly what you can do is you can take a look inside your script

13:47:19and what we can do is once we are right here i can say i want to exit with a status code of 0. so

13:47:28this exit basically means that i want to exit the execution of this program if we get your login is

13:47:35invalid i'm going to say exit with a status score of one right so let's just go ahead and do this

13:47:43and let's go let's just go ahead and run this script i'm going to write admin admin hit enter

13:47:49your credentials seems good let's echo the status code and we get zero let's run it again

13:47:55but with wrong values and let's try to echo the status quo and you can see it's one now

13:48:03the fun part comes when you can make use of the status code with other commands so if we take a

13:48:09look inside the script you can see that inside the if else we are able to check how you can

13:48:17verify two conditions using these two ampersand symbols right similarly in bash what you can do

13:48:23is you can make sure that two commands run that is not the number one thing that two commands run in

13:48:30a single line so i can say echo one and echo two and hit enter you can see that we get one and two

13:48:37but most importantly this and double and basically determines that if the status code of this command

13:48:46was zero then and only then i'm gonna proceed forward otherwise it's just stops right here so

13:48:54how we can use this i can use this by saying bash script and echo everything

13:49:04went right and hit enter and if i enter admin and admin you can see that we get status score of zero

13:49:11which we have already looked at and we get this echo as well everything went right however if i

13:49:17go ahead and use this and enter wrong credentials you can see that we do not get this everything

13:49:22went right why because this ampersand does not let it proceed further because this returns a

13:49:30non-zero status code similarly just like ampersand we have this or symbol right which basically means

13:49:39either this should be successful or this should be successful or both could be successful right but

13:49:45it's not that both should fail so what do i mean by that if i try to enter this and if i write the

13:49:52right credentials you can see i hit enter and you know we do not get this message why do why we did

13:50:01not get this message is because this in ourselves returned a status score of zero so it did not

13:50:07bother to go here and check if it returns status score of zero or not because this expression

13:50:14in itself was self-sufficient because of the status quo 0 returned by this particular part

13:50:20now if i go ahead and enter let's say invalid credentials you can see this returns a status

13:50:25score of 1 which is what we did in the script that is why we went over right here to verify

13:50:32um uh that not really verified to run this particular piece as well to get the status code

13:50:38so i hope you understand how this logical or and and works in a bash script with the help of status

13:50:45quo it is a super important and super interesting concept to be honest and uh yeah i hope you get

13:50:52this understanding that is all for this video i'm gonna see you in the next one really soon hey

13:50:59everyone welcome back and in this video let's just go ahead and take a look at if else syntax in a

13:51:04bit more uh depth because we have already covered refills but not really in a very satisfactory way

13:51:12so i'm going to start off by saying for example let's see if i have a variable with x equal to 100

13:51:17and now let's see if i want to check if this value is greater than or less than a certain value

13:51:22so i'm going to say if x is greater than and you see that i'm writing this dash and then gt greater

13:51:28than let's say 20 then i'm going to say echo yup the number is greater than 20 and i'm going to say

13:51:36fi to end that so if i do that and run the script you're going to see that we actually get here

13:51:42and if i for example say less than which you might have guessed is just lt instead of gt you're going

13:51:48to get no output now you can also specify an else if block so how do you do that is you say e l i f

13:52:00right so elsif is just l f and then you can also specify another condition so i'm going to say

13:52:08like this so if x is less than 20 which is not the case else if x is greater than 100

13:52:16uh or maybe x is greater than 99 then i want to have this happen and that's basically

13:52:22yeah so you see that now we get a longer e up because this time the second condition matched

13:52:29and then finally if nothing is really happening what you can do is just write else and because

13:52:34else would not take a condition because this is the final case you can just say echo no match

13:52:41found right and let's just make this as 90 so that the condition fails and if you run this

13:52:48you can see we get no match found so this is how the control would work inside if else if

13:52:53and you can just go ahead and indent this if you want but it does not really matter

13:52:59so you have greater than less than you can also check for equality with equal

13:53:04so if you this is 20 then you can go ahead and see that yup is what we get so that is

13:53:10how pretty much you're gonna work with um things like this in batch that is comparing numbers

13:53:18and that's all for this video i'm gonna see you in the next one really soon hey everyone

13:53:24welcome back and in this video let's just work on loops a little bit so just a quick

13:53:30heads up instead of like creating a new file every time with nano what we can really do is

13:53:35we can sort of work within the terminal itself for writing scripts for simple small scripts how

13:53:41because you know if i try to do something like if for example let's say a is equal to a and then i

13:53:51hit enter you can see it's actually waiting for completing my input so i can say echo

13:53:56yes and then i can just say fi to make it done and you can see that we get dss output so instead of

13:54:03like opening nano every time and then using bash script this is how we can do it now coming to the

13:54:09for loops what we can do is i'm gonna actually just go ahead and keep it in the file itself so

13:54:14that it's much cleaner for you to look but what you can do with for loops is you can start a

13:54:20for loop basically by saying for i in a particular expression where you in which you want to evaluate

13:54:27things right and a loop is basically just running an expression multiple times till the condition is

13:54:33not satisfied so basic example i'm going to start with 1 2 3 which are basically just three numbers

13:54:41then i'm going to say do for every single time echo welcome to code dam your number

13:54:50is for example i right so you can see i'm using i variable within the string and you can do that if

13:54:56you're using double quotes and then done so if you do this what's going to happen if you run

13:55:02bash script you can see we get the output as your number is one two three and three statements right

13:55:07away similarly you can go ahead and increment this as much as you want and it's just gonna work

13:55:15uh just like that right now the next thing is that instead of numbers you can also use strings here

13:55:22right so you should be able to see that the way it is actually working

13:55:29is that it sort of works on the space of the thing right so if you take a look you can see that we

13:55:37got a space here then we got a space here then we got a you know nothing else so it's basically

13:55:42just picking up every element then looking for a space then picking up every other element then

13:55:46looking for a space and so on so if i go ahead and probably try to include a space like this

13:55:52then this should not break because it should respect the codes right so

13:55:57you can see it respects the quotes but if i go ahead and remove the quotes from all the blocks

13:56:03then it's probably not going to respect the quotes because now it's just just splitting up on the

13:56:09spaces right so let's try this now and you can see that we get four statements now instead of three

13:56:15now this is particularly not very useful if you think about it if you do it in terms of numbers

13:56:22so bash actually allows you to specify a range as well so instead of like writing 1 200 here

13:56:29what you can really do is specify for i in range one and then two dots and then hundred

13:56:35if you write an expression like this inside curly braces what's gonna happen is that it's gonna just

13:56:42create your range for you and it's gonna trade like this you can see we got all the way from 1

13:56:48200 right all right so this is one way another way to use the same range

13:56:55is to actually go ahead and specify how many numbers you want to skip so for example if i

13:57:01just want the multiple of tens or maybe not really multiple of tens but multiples of tens plus one

13:57:08so if you do that you can see i only get 10 statements here starting from 1 to 91 and on the

13:57:17uh we are just skipping 10 numbers every time so this how you're gonna work with for loops

13:57:23for the most part right just like i showed you in if you're not working with ranges it's just gonna

13:57:30uh take up basically anything which is separated by spaces so if for example if i have something

13:57:35like file 1 and file 2 here and if i do something like or actually let me just go ahead and

13:57:44uh form a very uh smart sort of example let's go ahead and do this so i'm gonna say

13:57:51instead of specifying a static thing here i'm gonna open read files right so read files would be

13:57:59a file and then i'm gonna say echo reading read or maybe like i or maybe we can just change this to

13:58:10f for example for file and then i can say cat if right so what's going to happen let's go ahead

13:58:18and see what's actually inside script we can see we have to read a file called read files so

13:58:23let's create a file called read files now and i'm going to specify file 1 file 2 and file 3

13:58:28here and let's just go ahead and create file 1 which is just a regular file 1. similarly we're

13:58:37gonna do the same thing with file two contents and finally we're gonna do the same thing oops

13:58:47the same thing with file three contents right so now if we take a look inside the read files we

13:58:56have this file one is this file two is this and file three is this right and our script contains

13:59:04this thing so if i go ahead and run the script now you're going to see what happens

13:59:08is this statement right here this evaluates to this expression which is then fed in the bash

13:59:16loop which then iterates on the space and then you can read individual files like this right

13:59:22pretty cool feature that's how you're going to use loops in bash and yeah that's how this whole

13:59:29thing is going to work out so yeah that's pretty much it for this video that's pretty much how

13:59:35you can use loops there are other ways as well but we are not going to get into them

13:59:40just yet because i believe that for the basics part this should be fine so that's all for this

13:59:45video i'm gonna see you in the next one really soon welcome back and in this video what i want

13:59:52to do is just tell you about functions in bash so functions in bash is a pretty interesting concept

13:59:59because if you know any other programming language you're going to very soon realize that functions

14:00:03in bash are nothing like other programming languages right now what do i mean by that

14:00:09that means that in regular languages for the most part you are able to return certain values from

14:00:17functions right but in bash that is not possible so let me just go ahead and do a real quick

14:00:24demonstration here so how you create a function in bash and function for those of you who are

14:00:29clueless is basically a block of statements which you can run again and again depending on where you

14:00:35like it is different from loop because loop has to run a certain number of times but a function

14:00:41only runs whenever you want to call it so i'm going to say function let's say greet user and

14:00:51create a file right that's it so you're going to start function like this you're going to have a

14:00:57function keyword then you're going to have the name of the function two parentheses like this

14:01:02curly braces and curly braces end and whatever you write inside this it's gonna execute so i'm gonna

14:01:08say echo greeting user now right i'm going to say sleep 2 sleep is a command in bash which just

14:01:17pauses the execution of your code so 2 here means for 2 seconds then i'm gonna say echo hello mehul

14:01:26right you can write anything here sleep 2 echo creating file slash or maybe like dot slash

14:01:35greeting i don't know i'm just doing this just for the sake of doing something and i can say say

14:01:44file created right and i'm just gonna say touch greeting and touch is just a command in bash

14:01:51which is just gonna create a simple new file and it's not gonna add anything to that file

14:01:57it's just like creating an empty file so we can go ahead and save this and i can take a look here

14:02:06but in order to call it what we're gonna do is we're gonna use this as create user and create

14:02:13a file that's it we're not gonna call it like this now if you're coming from a different programming

14:02:19language this might seem a little bit weird but in bash think of functions like a command

14:02:25right in bash functions are not behaving to be honest like a regular function you're going to see

14:02:31in a different language it is more like a command so this is actually a command and now you can pass

14:02:37certain arguments to this we're going to come to arguments later on but this is what it is right

14:02:43so let's just go ahead and run this command first of all and you can see we get a greeting user now

14:02:48then we get hello mayhew for after two seconds and then we get creating file and file created

14:02:52and once you do that you can see we got a greeting file and it is empty just like i said because it

14:02:58would not contain anything because it has been created by the touch command now let's just go

14:03:03ahead and remove this or maybe not really remove this but actually create a different

14:03:11instance or not really a different instance but let's just talk about arguments of a particular

14:03:17function so how do you accept arguments in a bash function well you might be thinking something like

14:03:23argument r2 which is something which i thought when i was first learning bash but this is not

14:03:28how you do in bash at all in as a matter of fact you do not write anything in these curly braces

14:03:35at all so how do you get arguments well we have talked about how we get arguments in a script

14:03:42right we use dollar one dollar too right you use the similar thing with functions so what i'm

14:03:50going to do here is i'm going to say i'm going to replace this hello from mehul to 1 and just like i

14:03:55said function is sort of a command in bash so now if you pass mehul right here you're gonna see that

14:04:03this mayhew value right here this value actually gets passed on as a particular argument to that

14:04:10particular function which is present inside that dollar one sign right so oops uh there we

14:04:19go so let's just go ahead and run this bash script again and you can see that i still get hello mehul

14:04:26because that was passed as an argument i could probably just go ahead and change this to mehul 2

14:04:33and you're going to see the same output again but this time we have not touched the main function

14:04:37body just the argument being passed so yeah that's pretty much how the functions are going to work

14:04:45and one thing you might have seen is that there is no return value why because the return which

14:04:52you write here is going to be the exit code of that particular function again acting as a

14:04:58command how do i know that let's see so if i say something like 32 and just go ahead and do this

14:05:08right let's just execute this now you're not going to see 32 anywhere on the std out nothing is going

14:05:13to happen but what is really going to happen is the exit code of this command has been set to 32

14:05:21and we know we have talked about exit codes what they are so you should be

14:05:25familiar with that let's probably let's just go ahead and change this to um i don't know

14:05:33let's say 20 000 and it is not gonna work now the reason it is not gonna work is because

14:05:43exit codes are not okay let's see so this might be a happy accident but i don't really think so oops

14:05:56let's run the bash script again because exit codes have a certain finite range a certain small range

14:06:02right so if i go ahead and do echo this you can see we get a 64 now which is basically um a value

14:06:09which might have been rounded off to 64. right so we did not get um this 20 000 or whatever we wrote

14:06:17so this is this is the deal right the exit codes in bash are basically

14:06:22between 0 and 255 both included so if you try to return a negative one it's just not going to work

14:06:29because negative exit codes negative status do not exist right these numbers exist and they would be

14:06:37tried to map into the memory but they would be interpreted in a different way so it's sort

14:06:42of really useless to return anything from bash scripts because you can just return a number from

14:06:470 to 255 and that is also the exit code which is not the intended behavior of a return call

14:06:54so yeah that's pretty much it for this video i'm going to see you in the next one really soon

14:07:00hey everyone welcome back and in this video let's just go ahead and talk a little bit about package

14:07:05managers in a linux distribution so package managers is just a small software which allows you

14:07:13to install manage remove all these external softwares which you install from internet right

14:07:20so first things first let me just go ahead and exit this container and you can see i'm back into

14:07:25my mac os so i'm gonna run this container again and you can see inside this i see that nano is

14:07:32not installed by default which we have been using so far as our editor so how do we install nano

14:07:39first of all what i'm going to do is i'm going to say app get update right or simply apt update

14:07:47apt update is a new version of apt-get it's not really version but it's just a new way of updating

14:07:53packages this command basically tells ubuntu in our case it is ubuntu it tells ubuntu to hey go

14:08:00ahead and update your sources for getting all the new packages right so there are certain sources

14:08:08which are going to look at when it's trying to install a package from command line and if those

14:08:13sources are outdated you're going to not get packages or you're going to get old versions

14:08:18now once you do app update inside your terminal you might need sudo in front of it if you are not

14:08:24already root right so you might need a command like sudo apt update and sudo basically means

14:08:30run whatever command i'm running in front of as root user right because we are already

14:08:37root we do not need sudo so once you're done with app update what we need to do is say at install

14:08:44nano and hit enter so that's that's basically it it's just gonna take care of where nano is

14:08:51what are the other dependencies which nano requires if any and it's just gonna install

14:08:56the editor inside your bin directory which is already inside your path of the environment

14:09:03and it's just gonna work right away right just like this that's how it's going to work

14:09:09so package managers in linux allow you to install manage remove packages from internet and not have

14:09:17any hassle of working with those dependencies and compiling and building stuff you can also remove

14:09:24a package by saying apt remove nano for example and once you do that it's just gonna be removed

14:09:30it's just gonna ask you for a confirmation and that's it now you cannot use nano anymore right

14:09:36so yeah that's that's pretty much it for the package manager thing that's how

14:09:41it works if you are using centos you have yum as the package manager if you are using ubuntu or

14:09:46any debian based installation you have apt as the package manager right so these just these are just

14:09:52simple handy tools which ease your job which is your life a lot so yeah that's that's it for this

14:09:58video i'm gonna see you in the next one really soon hey everyone welcome back and in this video

14:10:04let's just take a look at bash rc so bash rc is a file in your shell which is the file which runs

14:10:12when you start your shell now what do i mean by that i mean if i go ahead and take a look at lsl

14:10:21a which a this a right here denotes that you should show hidden files as well right so

14:10:27hidden files in bash are basically the files which start with a dot and these files which

14:10:32start with the dot would not show when you do ls or lsl you have to do lsl a in order to show them

14:10:39so once you do that what's gonna happen is you can see that we have got this bash rc file so let

14:10:45me just go ahead and open this right here and see what's going on or i think we do not have

14:10:52installed nano so let's just go ahead and do that first of all and then i'm gonna

14:10:55open bash rc so it looks like a lot of code but in a nutshell it's just initializing your shell

14:11:01with a bunch of options so what do i mean by that if i go ahead and write echo say starting

14:11:10shell and save this what's going to happen if i run bash again i get the starting shell

14:11:17message right because we are starting a new bash process my writing bash so

14:11:21whenever you log in into your shell bash would automatically run this file called as bash rc

14:11:29and it's gonna be um you know it's just gonna run directly all the commands inside your particular

14:11:37uh file so let's just go ahead and edit this and i'm gonna say this has set a variable called my

14:11:45custom variable is equal to some number and now if i run bash you're gonna see it saves me starting

14:11:53shell but now i can use this my custom variable right so you see that it's variable value would

14:12:01already be set automatically now instead of like just writing bash every time to get this there's

14:12:09a much better way to do refresh these changes and i'm just going to show you that so let's say if

14:12:14i change this to 99999 you're going to see that now if i do this it's not going to work right it

14:12:22still shows me the old value why is that because the bash rc for this shell has already ran so

14:12:29whenever you make a change in the bash rc command rc file either you can just log out or log in into

14:12:36your shell again that is just closing the window and opening it again or what you can do is just

14:12:42go ahead and say source then the path of the bash rc that is this right so you can see once i source

14:12:50this file i still get the starting shell again but we are not we have not created a new shell right

14:12:57i can now go ahead and say my custom variable and you can see we get the new updated value

14:13:03so yeah that's that's how you're gonna work with bash rc file for the most part you can

14:13:08go ahead and write your initializing scripts and everything into the bashrc file directly

14:13:13and that's all for this video i'm gonna see you in the next one really soon everyone welcome

14:13:19back and in this video let me just go ahead and talk about top command which is sort of useful

14:13:25to you if you are somebody who wants to see all the processes which are running right now

14:13:30on your system so you just write top and hit enter and you see all the processes in this case

14:13:35only two the first one is bash which was the shell and the second one is the top command itself right

14:13:41so let's just go ahead and start some processes let's say i have a script

14:13:48oops let's just add update and app install nano let's just add nano real quick i'm going to create

14:13:56a script which just sleeps for a long time so that it shows us in the running processes right

14:14:04and i'm gonna send it to background as well so let's just go ahead and create a script let

14:14:07me just go back into my home directory i'm gonna say script and i'm gonna say

14:14:12sleep for a long time right and i'm going to start this bash script but i'm going to

14:14:18put an ampersand sign right here in order to run this inside background

14:14:24so you see once i run this inside background it is still running but i cannot can no longer see it

14:14:29so how do i see it is by saying top and you can see this sleep right here which is running

14:14:35right and we also see another bash shell which is running because we executed the command using that

14:14:42so this is how this sleep command is running right now you can see there's a bunch of information

14:14:49about this command and the most useful one is the process id and the user basically which is

14:14:56running it we also have cpu and memory usage and it does not use a lot of memory so that's fine

14:15:01but you get the idea how top works now to exit the top you just press the q key but a really cool

14:15:09sort of addition to top is the etch top it's top command right and it's stopped by default

14:15:15is not installed so what you have to do is just say apt install h-top on a debian distribution

14:15:21and it's a lightweight program but it's much more beautiful and gives you much more insight into the

14:15:27actual thing what is happening so you see that we actually get the amount of memory which is

14:15:32used as well at the moment we get the cpus which are being used we get the swap space and we get

14:15:39all the things we already got in top right so we get what things are actually executing right now

14:15:45so this is this is basically what's happening right now and it is basically a fairly advanced

14:15:52tool to be honest you can set the nice values of processes and everything

14:15:56and to actually understand what nice values are you actually have to understand what processes are

14:16:01in linux but we are not going to go into that rabbit hole just yet because we want to just

14:16:06focus on basics of cli so edge top is a good tool you can edit exit edge top again using the q key

14:16:13and top is basically a very slim trimmed down version of edge top right so yeah this is a pretty

14:16:20cool command that's all for this video i'm gonna see you in the next one with an even cool command

14:16:27hey everyone welcome back and in this video let's just quickly talk about the kill command

14:16:31which you're gonna be using a lot of times if you have a shell which is stuck or a process

14:16:35which is stuck and you want to just remove that instead of just restarting your whole machine

14:16:40so kill command allows you to kill a process obviously but it also has a lot of other use

14:16:44cases as well in sending signals to a process but one such signal is actually killing the process

14:16:51and there are multiple other signals like resuming a process pausing a process you basically have to

14:16:57understand the whole process linux uh cycle in order to truly appreciate what what kill can do

14:17:04but yeah for the most part we're just going to be focusing on killing the process using

14:17:07sick kill now sick kill is just a signal right similarly control c is also a signal

14:17:14right so let's just go ahead and do that first of all let me just go ahead and open this script

14:17:20you can see this is a long running script so let's just run this inside background

14:17:24with a command like this bash script and then an ampersand sign so if i go ahead and do h

14:17:29top now you can see we have been running bash script and which is in further running sleep 100

14:17:343000 right so this is what is happening now let's just go ahead and kill this pid 297 which is

14:17:41oops 297 which is this sleep 100 so i'm gonna say kill dash nine this dash nine basically means that

14:17:49send a sig kill which is an immediate kill signal to this process and that was 296 right and hit

14:17:55enter and you can see we get killed this as the message now if i go ahead and write edge top

14:18:01you can see that we have killed the bash script but this command is still running so let's just

14:18:06go ahead and kill this as well so i'm going to say kill 9 uh 297 hit enter and that there

14:18:12we go now both of the commands are killed and we have a nice little uh two commands

14:18:18left with us right and you can obviously not go ahead and kill any other command any other pid

14:18:24that process id has to actually exist as well so what you have to do is just follow along

14:18:29and find the process id of the process which is bothering you and write kill nine in front of the

14:18:35pid right and kill it using that so it's gonna save you a bunch of time when you're working with

14:18:42stuck processors just like i said so that's why i thought you should know about this so yeah that's

14:18:46pretty much it for this video i'm gonna see you in the next one really soon hey everyone welcome back

14:18:54and in this final video we're going to be talking about what should be your next step now once you

14:18:58have done with the linux cli fundamentals you should move on to the next technology which you're

14:19:05learning whatever you are learning that is and start with that so in case of for example if you

14:19:11are going through the node.js back in developer learning path the next technology will obviously

14:19:16be nodejs basics if you're learning python then choose that but yeah follow your learning path and

14:19:23move on to the next technology you are well enough well equipped with the linux fundamental basics

14:19:30everything else which has been missed out or you think has not been covered yet

14:19:35would be covered in the whole learning paths later on learning path modules learning path

14:19:40nodes later on so do not worry just keep on moving and all the best for your future

14:19:46courses for your future videos on code dam i'm gonna see you in some other course really soon

14:19:52hey everyone my name is mahul and welcome to a brand new course on node.js fundamentals this is a

14:20:00course of the back-end development learning path for nodejs and i hope you have been following

14:20:04along from the starting if you want to become a back-end developer we discuss a little bit about

14:20:09how internet works then we get to know the basics of front-end where javascript is very

14:20:14important because of node.js because node.js is literally just javascript running on the server

14:20:20then we move on to the linux basics where i teach you how you can work with terminals and

14:20:26simple commands and basically to get you familiar with linux in general

14:20:31now we are on the node.js basics so let's start with this this is going to be a fun course where

14:20:37you will be actually learning practical hands-on nodejs we'll be creating all sorts of applications

14:20:42deploying servers we'll be learning about things and once we are done we'll be moving along our

14:20:47way on our no chairs back in learning path so yeah pretty excited to start this course

14:20:53with you guys that is all for the intro video i'm gonna see you in the next one really soon

14:20:59all right guys welcome back and in this video let's just go ahead and start with the basics

Learn Node.js 17 From Scratch

14:21:04of nodejs now i'm gonna be in this whole course i'm gonna be using the node playground from code

14:21:09dam if you're watching this on code dam itself go to the code down playground section from your

14:21:15dashboard and you should see this node playground if you're watching this from somewhere else you

14:21:20should find the link in a relevant place which is basically codedum.com slash playground slash node

14:21:26once you do that you're going to be presented with a screen like this where you might also have a

14:21:32browser window waiting for you so for the purposes of learning right now i'm

14:21:36just going to make terminal as full screen because we'll be working with terminal for

14:21:40the most part in our initial course and you're also going to see a file named index.js right

14:21:46now this file contains a lot of stuff so first of all let's just get rid of this so what is node.js

14:21:52first of all let me just clear that so what is nodejs nodejs is basically the javascript

14:21:59which you have learnt in the front-end courses in the front-end learning path or whatever you took

14:22:04and we took that javascript from the browser that is which runs in the browser and took it to an

14:22:10actual environment an actual computer environment you see in browser your javascript is actually

14:22:16running in a sandboxed mode under the browser process that is the javascript engine which is

14:22:23v8 in chrome but what happens on server on a real computer is that your javascript still runs in v8

14:22:31but it has a lot more permissions it has a lot more flexibility it has got a lot more power

14:22:38to work with for example your websites whenever you visit a website you can see that a website

14:22:43cannot really just upload a file on from your system to their websites you know because just

14:22:50they wanted they have to ask you first then you select the file yourself and then you upload it

14:22:54right similarly they cannot really download anything anywhere on your file system you have to

14:23:00explicitly tell them where you want the file to be downloaded with the save as dialog box similarly

14:23:07node.js allows you to do all the good things in javascript but it also gives you more

14:23:11power and more functionality because now you are running it as a scripting language on the server

14:23:17what does that mean that means that node.js can now interact with your file system node.js can now

14:23:23interact with your networks that is it can see it can listen to the ports it can probably see other

14:23:30applications running on your computer it basically got all that power which uh javascript got all

14:23:35that power which other languages had so node.js is that and we're gonna be learning about node.js for

14:23:41the most part how it differs from javascript that would be the case so if you're somebody

14:23:46who's new to javascript in general this course is probably not for you you are way too soon in the

14:23:52back end development learning path on code damn i would say go ahead and finish the javascript

14:23:58section of the backend development learning path if you are new to javascript otherwise

14:24:03let's start with this course so i'm going to just start with a typical hello world here

14:24:08which is you know a tradition so if i click on run code you can see what's happening in terminal

14:24:14is when i click on run code nothing is happening except we are executing node space index.js so

14:24:21node is a program which runs this particular file which takes in this particular file

14:24:27just like we know from our bash tutorials that cat takes a file like this and echoes out the content

14:24:33node is a binary again which needs to be installed we'll see how to install node later on but in this

14:24:39environment you'll automatically get that and it takes in a javascript file and processes it just

14:24:45to see what has to be done and then it goes out the output so as cool as that right so yeah this

14:24:51was a hello world program in node.js hopefully you understood this video if yes let's move on to

14:24:58the next one and we'll be diving into deep of uh node.js basics and uh getting familiar with most

14:25:05of them so that is all for this video i'm gonna see you in the next video really soon hey everyone

14:25:12welcome back and in this video let's just quickly talk about dino which is a very common alternative

14:25:18which has been popping up these days compared to node so dino just like node is a run time for

14:25:25javascript and by runtime i just mean that it is a sort of software which took up javascript from the

14:25:32browser and placed it on a server on a computer just like whatnot did but with a couple of things

14:25:39first of all dino supports typescript out of the box that is number one thing then it also gets

14:25:45security inbuilt with some sort of network file environment restrictions and access depending on

14:25:51how you configure it and it has got a bunch of more features like it can ship a single

14:25:56executable binary it has got a bunch of built-in tools and so on so as a beginner what should you

14:26:02learn should you learn dino or should you learn node well you see that on a fundamental level

14:26:08what dino does node can do that too right so dino is not superior in terms of functionality which

14:26:18a javascript runtime can provide you it might be superior in terms of features

14:26:23but node has been around for about 10 years and it is still very well maintained and it's it is still

14:26:29growing dino is a new competitor it has um you know a long way to go for the most part right now

14:26:38and no major company as far as i know right now is using dino in production so if you are somebody

14:26:44who's trying to learn node and if you're confused of tino would be better choice compared to node

14:26:50the first thing is that most of the knowledge which you're gonna get from the node.js course

14:26:55will be transferable directly into the dino world as well why because at the end of the day both are

14:27:01executing javascript and you will be learning the syntax of the javascript which node.js supports

14:27:08which is pretty much what dino does as well for the most part and secondly node.js is more popular

14:27:15right now compared to dino both in terms of usability and in terms of

14:27:21i would say general awareness as well so a lot of people would know about node compared to dino

14:27:27so if you are starting to learn node.js trust me it's absolutely fine you can go ahead and start

14:27:32with that node is not going anywhere anytime soon so yeah that was a quick video just to

14:27:38clear off um if you are stuck in that particular dilemma that should you opt in for node or dino

14:27:44and hopefully this has been useful let's start with the node.js development from the next

14:27:49video hey everyone welcome back and in this video this is just a quick reminder that you

14:27:56need a bunch of javascript knowledge so you can see that on our front-end developer learning path

14:28:01we already have javascript as one of the nodes that is one of the nodes in this graph and if you

14:28:07click on this you're going to have a bunch of courses to learn about javascript right

14:28:12my favorite approach is to start with javascript basics like this and this course is going to take

14:28:17you through all the basics which are needed in order to learn javascript on the browser

14:28:22the browser-based javascript then i would say just go ahead and move on to do a particular

14:28:28project maybe you want to do a tetris game or if you want to build 10 plus projects in javascript

14:28:33to solidify your learning go ahead and learn about them once you are comfortable with syntax

14:28:39then i would say you can come back to the backend developer learning path which is the node shares

14:28:44and we can start right here right so the reason i'm doing this is because it becomes very very

14:28:51easy for you to work with full stack once you are done with the front-end javascript as well

14:28:58and when you're starting off with node.js with a little bit of knowledge about html css as well

14:29:03so yeah just a quick reminder if you have absolutely no prior background with javascript

14:29:10this back-end development node.js course should be the number two course the number one course for

14:29:15you right now should be javascript basics which you get from the front-end developer learning path

14:29:21as well as from uh in the backend itself so if you are skipping sections just don't because

14:29:27sort of javascript sort of would be required what with what content we are working on

14:29:32in this whole course so yeah just a quick video that's all for this one i'm gonna see you in the

14:29:37next one really quick hey everyone welcome back and in this video let's just go ahead and start

14:29:43with module system in nodejs so what i'm gonna do is tell you quickly about what are the common

14:29:49way to create modules in nodejs so i'm gonna start off by creating a simple index.js file

14:29:56now in node.js there are basically two ways to create modules the first one is common js

14:30:02and the second one is es6 import syntax right in both system or whatever you want to write

14:30:11so common js is basically the most used module import system in nodejs because it comes

14:30:18in baked into nodejs itself and es6 import syntax is something which has recently been

14:30:25uh promoted a lot because of you know browser support and a better specification and a better

14:30:32nice looking nice looking um syntax as well plus it supports a bunch of new features like tree

14:30:39shaking becomes easier and so on so we're going to be taking a look at es6 later on

14:30:44let's start with the common js syntax so the common js imports and dax basically means that

14:30:50you have to make use of this word called require now require basically allows you to require any

14:30:57other file inside your file system now this can be used to require known modules as well as this can

14:31:04be used to require local files so let's start with the local file let's say i have this util.js or in

14:31:11common js we can just drop the dot js i want to get this util and i'm going to store this result

14:31:17in util analysis console.log what we get back from util right i'm going to go ahead and create a new

14:31:23file let's say util.js and what we're going to do is inside of this file we're going to be creating

14:31:33let's say a simple function add numbers a b and i just return a plus b

14:31:40right and finally i want to make this function available to this particular file because right

14:31:48now if i go ahead and run this you're going to see nodeindex.js gives me an empty object that means

14:31:53nothing is being exported from this particular file how do we export something well in common js

14:32:00if you are using common js what you can do is directly go ahead and make use of something known

14:32:05as module dot exports now this module dot exports is a special this exports is a special property

14:32:13is a special object on which you can attach pretty much anything and it will be available

14:32:19as an exported value so now if i go ahead and probably run index.js again you can see

14:32:25i see a 100 as the value and this value could be pretty much anything right it could be numbers

14:32:32it could be strings it could be my function as well so you can also have sort of functions

14:32:39attached here so if i go ahead and pretty much just try to run this what you're going to see

14:32:46is that we get all the relevant output just like that so you see that you have basically

14:32:54an object on which you can attach any sort of property and it will just work out of the box

14:33:01now what we can do if you can think about it is i'm just gonna go ahead and attach add numbers

14:33:06and say add numbers like that so what this means is that add numbers is going to be a

14:33:11property on this object which i can then go ahead and make use of in files like index.js so if i do

14:33:18util.add numbers you can clearly see that we have a particular property which is available to us

14:33:25for that particular thing so let's just go ahead and try to run this and you can see that we

14:33:31in fact have this as a function and if i try to call this with let's say 5 2 and try to

14:33:37run it right here you can see we get the sum of these numbers as 7. so require is a very

14:33:45simple syntax a very you know nothing fancy is going on here whatever you write to module.export

14:33:52is going to be available as a particular value from that function and you can get the whole

14:33:57thing out of it the whole module.exports object from this required call and store it in any other

14:34:04variable which you want and you can access it just like you want now a couple of things here

14:34:09is that a lot of times what you're going to see is a lot of people drop this module

14:34:14so what you're going to see is that if i go ahead and remove this module and just to exports.abb

14:34:20you know stuff like this this is also fine because if i go ahead and show you if i run nodeindex.js

14:34:27we still get seven right and just to verify that we are on the same page you can see on the server

14:34:34we also have export study same file now this is completely fine and you know it just works as well

14:34:42so why did i just tell you to use module.exports well this is because when your module when your

14:34:50single module like util is called you can imagine something like this is happening so somewhere

14:34:57somewhere unaccessible by you right so this is a section which is not accessible by the

14:35:04regular code you can think about node calling your code something like this so it has a

14:35:09bunch of parameters i don't really remember the exact syntax this is an actual thing actually

14:35:13so you have a bunch of parameters and then you have module and exports available to you

14:35:19and yeah around this your code resides so you see that we were adding module dot exports

14:35:26not property and this was available to other guys right similarly exports is

14:35:31also available right here for you to attach properties but this would fail if you try to

14:35:38do something like this if you try to just let me just go ahead and remove this first of all

14:35:46so if you try to go ahead and do something like this where you say a hundred bb

14:35:53something else right and let's just remove everything else so if we have something like

14:35:58this we see cat utils.ts and if i try to run probably just this thing right so if we try to

14:36:06run this particular code what's going to happen is we get an empty object even though we have

14:36:10some exports specified why is that because now you are overwriting the actual exports

14:36:15object which was available as something where you can attach the property so this is a new

14:36:21completely new object however this thing would work absolutely fine if you use module.exports

14:36:27so if i run this now you're gonna see oops not the util the index file so if i run this you're

14:36:34gonna see that we get the correct output again just to reiterate why is that think of module

14:36:40as an object which has got an exposed property right and think of uh think of exports

14:36:48as a variable which is something like this now if you try to do exports is equal to a10 what you

14:36:57are really doing is that you are overwriting this exports variable right so it no longer

14:37:02no longer points to this particular object but it is a completely new object but if you do

14:37:07module dot exports then you're still pointing to this particular object and that is fine

14:37:14so this works this fails and you know what else would work is if you just go ahead and directly

14:37:23do exports dot a is equal to 100 why because you can see it still points to module.exports you're

14:37:29not changing the reference of the exports object so this is fine that is why it works

14:37:34right so hopefully this gave you a little bit of more insight into how common js module system

14:37:41works in nodejs and this is like really all about it right unless you are trying to get into the

14:37:48resolution system this is all you need to know for the most part when you're working with common js

14:37:53that you require the module like this you get a full object if you want you can destructure

14:37:59the particular property that's just fine but this is just an es6 syntax it's not a common js syntax

14:38:04you can destructure stuff and from the module if you want to export something you just go ahead and

14:38:10use module.exports so that is all for this video i'm gonna see you in the next one really soon hey

14:38:18everyone welcome back and in this video let's just go ahead and take a look at the file system module

14:38:24in nodejs now fs module is super interesting because it allows you to work with the file system

14:38:30in general so you can create remove add edit files append to files with the help of this particular

14:38:37module so you require it with the required syntax which we discussed in the common js video

14:38:43but you can see it clearly that i'm not really specifying any dot slash or dot here because

14:38:48you can see that node would otherwise recognize this as something which you want to import from

14:38:54your local file system right but we know that fs is installed by default it comes bundled with node

14:39:00so you can just go ahead and use it as it is so the first thing is let's just go ahead and

14:39:05create a function called create file fs has got a bunch of utilities and functions inbuilt

14:39:12so i'm going to say create file name and i'm just going to say fs dot you can see that we have a

14:39:18bunch of functions we can access so what i want to do is create or not really create i want to

14:39:25write file so let's just get let's just make this as contents and i want to write file and

14:39:33what i want to do is i want to say that hey the name of the file the name of the file should be

14:39:41this particular name which i am passing and the contents would be basically the contents which

14:39:46i'm passing right so you can see the arguments basically mean that the first argument is the path

14:39:52which is the name of the file or basically the path of the whole file but in our case

14:39:56we just want it to be a local file so we just give it a name and the second one is contents

14:40:02now with fs what you're gonna realize is that there are basically two types of functions the

14:40:08first one is the uh you know asynchronous versions and the second one is the synchronous version what

14:40:15is the difference well the asynchronous version for example if you use this particular thing

14:40:22and if you try to say file written and if you try to read read it oops read it right here you might

14:40:35fail that means it might happen that this file has not been written to the file system yet so this

14:40:42is asynchronous that means node.js will do it later on it schedules it in a queue but the

14:40:48write file sync guarantees you that if you are here and if no error is thrown that the file is

14:40:54written that means your this file written code will only work um when this is complete now you

14:41:01might be thinking that hey then why do we you know anyway prefer right file what is the advantage

14:41:07well the advantage is that when you are working with asynchronous operations

14:41:12a lot of times what happens is that a lot of stuff like you know checking for the hard disk

14:41:18space or maybe allocating a new buffer for writing this file a lot a lot of this thing

14:41:24can be offloaded to the operating system itself which is not exactly what node.js would work on

14:41:31so what happens for example is let's let's compare this right file with the http request

14:41:38because that might be easier to explain so let's say if you're trying to make an http request

14:41:43right and you have two ways the first one is async way just like we have right fill with write file

14:41:50and then we have a sync way which is you know http sync async is just http

14:41:57so if you do an async method what's going to happen is that node can work on other things

14:42:04while os waits for the network request right makes sense i guess whereas if you are using a sync way

14:42:16node and os both are waiting for the request the so what happens is that you basically waste the

14:42:24computation time which node can use to do maybe some other tasks like maybe serving another user

14:42:30because it's a single threaded thing and if you are blocking the event loop like this with the

14:42:35right file sync um you're basically blocking the whole program so this was a quick little um

14:42:42i hope the knowledge and analogy you were able to grasp but anyway we're going to be using right

14:42:48file sync here because it makes things a little bit easier and predictable if you do not want

14:42:52to have callback functions or promises so let's just say i want exports export start uh create

14:43:00or maybe let's just do module dot xpose anyway and just expose the create file thing right now let's

14:43:08just go ahead and say i am just getting create file and i just go ahead and say create file

14:43:17test.txt and i say hello world right now we have this code if i try to run this code

14:43:25we can see we get the file written and you can see that we also get test.txt here which just says

14:43:30hello world as simple as that right so yeah this is how you're going to make a very simple function

14:43:37fs has got a bunch of more functions i would say read more about the documentations

14:43:42you can also list the directories so i can say for example let me just go ahead

14:43:47and import the fs directly here because why we should go

14:43:53and make use of all those utility functions again and again so let me just go ahead and say

14:43:58fs dot read directory you can again see we have two possible functions that read directory and

14:44:07read directory sync i'm going to go with the sync one because it immediately gives us the output but

14:44:12probably if you are you know going on production or want to have a better performance you want the

14:44:18asynchronous versions so if you do something like this and run the code again you can see that right

14:44:25here in the output we have the files of this particular directory which is the dot which is

14:44:30the current directory so we have three files we got three results now i think fs also supports

14:44:38promises so if you do a required fs and if you say fs promises or maybe we should do something like

14:44:45this fs and then fs is fs dot not really fs dot promises what this is is that it is basically all

14:44:56these things which are you know the asynchronous versions of fs but instead of having callbacks

14:45:03they are not promises so if i try to do fs dot dot well we do not have an auto complete on that but

14:45:11what i mean by that is if i do fs dot read directory what you're gonna see now is that

14:45:17it is an async function but let's let's do a two string it is an async function but you can see

14:45:26you can see first of all it says me that is an async function so we can use our weight on that

14:45:31and there is no callback option right so we have to really await for this particular operation so

14:45:38let's see if i do an async function like this we're going to be covering async

14:45:41functions as well i think we covered it in the javascript part also but nonetheless

14:45:48so if i do something like await fs.redirectory and if i call it like this what you're going to

14:45:55see is that now although this function is going to be asynchronous it would be just working just

14:46:02like uh you know a previous one where we had read directory sync so yeah i mean just i just

14:46:09wanted to put out the word that promises also exist as a set of functions on the fs system

14:46:16and you can use them but for the most part fs is going to be good for us right so yeah that's

14:46:22pretty much it for working with file system just like i said there are a bunch of methods if you

14:46:27just go ahead and console.log fs here you're going to be listing a bunch of them actually

14:46:32and yeah you can see we have a pen file we have exist which checks if the file exists and for

14:46:38the most of the methods we also have a synchronous version then we have some file modifiers if stats

14:46:44f-stat gives us the information about a file when it was created when it was modified stuff

14:46:49like that we have uh let's see we have read file obviously so if for example if you want to read

14:46:55the own source code of a file what you're going to do is just say fs.read file sync and i'm just

14:47:02going to say this is going to be indexed.js so this is a program which can read itself

14:47:08so you can see that we get a buffer and what you want to do to convert this buffer into a string

14:47:14is specify an encoding as the second option so we want a utf-8 encoding and if i go ahead and

14:47:20run this you can see we are actually reading our own source code right so the most sophisticated i

14:47:28think i'm not really i have not really tried it but the most sophisticated infinite loop would

14:47:33be to eval this thing now because you are reading you're executing you're reading you're executing

14:47:39again and again because i don't want to crash the container i'm not going to do it but just an idea

14:47:46so yeah that's pretty much it for this video in the next one we're going to be

14:47:49covering more about file systems not really file system the module system

14:47:54and how you can work with them so that is all i'm going to see you in the next one

14:47:59hey everyone welcome back and in this video we're going to be taking a look at the import export

14:48:04syntax in node.js which is basically the esm that is the ecmascript modules now this is going to be

14:48:10the future of the module system in node.js so this is a must you should know about how this all works

14:48:18so first things first the import syntax is not gonna work if you try to work with

14:48:24dot js extension so let's just go ahead and create two files common.js and es6.js

14:48:31so in ecommon.js let's just go ahead and write a quick program just like we wrote the last time

14:48:37and i'm going to say fs.readfilesync command.js right every file would read um themselves so

14:48:45let's just console.log this thing and there we go nothing fancy nothing happening here

14:48:51now if i go ahead and run this common.js you're going to see oops we need an utf 8 encoding here

14:48:59so if i go ahead and run this file you're gonna see that we get the text just like we

14:49:03did but if i try to copy this program and paste it inside es6.js but let's just go ahead and do

14:49:10one small change let's just change this from required base syntax to the new syntax right

14:49:17and let's just try to run this same program but with es6 now you're going to see that

14:49:24we get an error which says cannot use import statement outside of a module now what does that

14:49:30mean this basically means that import is something which is used as a es6 module resolution system

14:49:37we're going to learn about this but this keyword this format is not possible to use right now

14:49:43inside.js files so how you can use them you can use them inside dot mjs files right so you have

14:49:50to rename from es6.js to es6.mjs you see this m this just tells note that hey this is going to be

14:49:58a module file so you can use this is going to be a es6 module file so you can go ahead and use the

14:50:04common uh syntax here so once we have renamed it and now if i open this and if i ls this here you

14:50:10can see we have a es6.mjs file and now let's just go ahead and run this es6.mjs and there we go one

14:50:18super important thing here is make sure that your version for node is above 14. if it is like 12 or

14:50:2613 you need an experimental flag in order to run this so you have to do something like experimental

14:50:33uh i don't really remember the flag completely but experimental mode or something like this

14:50:38but if you're running node 14 and above you can safely just go ahead and use es6.mj statically

14:50:44and uh i think we did not change this so let's change this to es6.mjs

14:50:50and once we do that once you run this you're going to realize that now we are talking so we

14:50:56are echoing out the same file but we are using the es6 module system do not worry if you do not

14:51:01understand this yet we are going to be learning about this whole thing how this works very soon

14:51:06so let's start with the es6 module system from the next video and we're going to be taking a look at

14:51:12common ways you can import export from files like these hey everyone welcome back and in this video

14:51:18let's just discuss about es6 module syntax now this is super important so make sure you pay

14:51:27very close attention to this video and subsequent videos which follow because this is gonna be a

14:51:32game changer for you if you can really understand how import export syntax and things work with es6

14:51:38because to be honest you're going to be using es6 module system all the time when you're working on

14:51:43front end or back end because even though they are still experimental this is basically just

14:51:49used with all the tools with back babel so all these tools take care of that so let's

14:51:54start i'm going to create another file called module.mjs which is going to hold our utilities

14:52:01inside obviously inside the es6 version so let's just go ahead and create a function called add

14:52:07which is or maybe not really add just square which accepts a number and returns us the square

14:52:14of the number right and now i want to export this function with common js what we're going to do is

14:52:22we're going to just say export module dot exports and i'm just going to save for example square

14:52:29right but this is not how es6 works with es6 what you have to do is say export which is a keyword

14:52:38and then you want to specify how this object how this function should be exported the first way

14:52:46to export is to have a default export right so i can say export default square and stick with

14:52:52me here i'm just going to tell you what this means so what does export default square mean

14:52:58this thing right here means that this particular module will be available

14:53:05directly from you know if i do something like import if i do something like import

14:53:13square from module so what's going to happen is that if this is a default export i can use

14:53:22something like this directly now why i'm saying directly i'm going to show you in a minute what

14:53:28i can do now is just say console log square of 5. so if i just go ahead and run this code right here

14:53:36we get an error that we cannot find in this module let's see if everything's fine module

14:53:45yeah so we need a module.mjs here because we need to specify the full path inside the es6 syntax

14:53:52esx module syntax why is that i'll just tell you that in a bit

14:53:57the reason uh javascript people who are developing javascript chose to have a full syntax

14:54:04is because traditionally when you're working with html what we do is we specify script src file.js

14:54:12completely right whenever you're loading a script on the front end you never do something like

14:54:17script src file or script src file.js and it's not like both of them are equivalent so we are trying

14:54:24to bridge that gap between browser and servers or running node traditionally so in this case

14:54:30if you are importing it from a module based thing you have to use the full name this is number one

14:54:36number two this is not the only way to export things right this is the first way

14:54:43another way is to export multiple things now how do you want to export multiple things because

14:54:50you can only have one default export per module and if you think about it it makes sense as

14:54:58well right because if you could have multiple default exports then how you're going to expo

14:55:03import those particular things because just like i told you this is the only syntax you get for a

14:55:08default export so if you want to export multiple things for example let's say if i have a function

14:55:15called cube with a num and i return num times 3 that is not really times but yeah

14:55:25so let's just go ahead and take a look at a different export syntax this is going to be

14:55:31not a default export now this is gonna be something like this export square

14:55:37and cube now what is happening here well obviously if you know javascript you understand that this

14:55:44looks sort of like an object syntax but trust me do not think that this is a regular object

14:55:51this might behave like a regular object you might think but this is something completely different

14:55:58what do i mean by that let's first of all take a look at this so you export a sort of like

14:56:02object looking i'm gonna say this is object looking right but this is not an object

14:56:10but you export it like this and inside your for example inside your es6 file instead of

14:56:16importing it like this now what you have to do is you have to use the similar syntax to get

14:56:22only the things which you want for example if i just want to get cube out of this what i'm

14:56:27going to say is i'm going to say import cube like this you see i'm using these parentheses

14:56:33this means that i'm trying to get an object which is i'm trying to get a function which is not a

14:56:39default export this is very important the moment you write these curly braces this means that

14:56:44you are never going to import the default object number two is that the name of that object which

14:56:50was exported was cube right and this is important because this cube right here should match this

14:56:57cube right here so if i change this from square to cube and if i try to run this now what we

14:57:02are what we are going to see is that instead of 25 we now get 125 which is perfectly fine

14:57:08but you understand that now i'm just getting cube now what if i want to change the name of this

14:57:15particular export right here for example this is for example this is something like internal cube

14:57:23and now i want to export this as the name cube now if you think this is sort of an

14:57:28object what you might think is we can just go ahead and do something like this

14:57:33right but straightforward you can see that it tells us that this is an error with export and

14:57:39yeah things would go wrong so what you really want to do if you want to change the name of

14:57:43the exports is you want this thing to be first and then you have to say export this particular thing

14:57:51as cube now this might be the moment when you realize that hey this is not a javascript object

14:57:57this is something else right because we do not have an as keyword inside a javascript

14:58:01object so this as just means that you want to change the name of the exported thing

14:58:07so if i do this and if i try to pretty much run this again you can see nothing really changes

14:58:13because well we had this internal cube named as this but it is at the end of the day exported as q

14:58:21if i change this to cube 6 for example then things are gonna take a turn why because now i actually

14:58:27have to rename this from q to cube six and if i go ahead and run this now then you can see it still

14:58:34works but if i just keep it at a cube we're going to get a nasty error that there is no um export

14:58:43named cube right so this is how things are working this is how the export side of the

14:58:48things work this is all for this video in the next one let's just discuss about the import side of

14:58:54things as well and then let's just take out some time to discuss about the default exports thing

14:58:59as well so that's all for this video i'm gonna see you in the next one really soon hey everyone

14:59:06welcome back and in this video let's just go ahead and take a look at the import side of things right

14:59:11so what you're gonna realize very soon is that export and import are very very similar just like

14:59:17you can rename and export like this you can also rename an import so for example you can see right

14:59:24here we have this let's say this is cube only for example we have something like this and right here

14:59:29if i try to rename this to something else so for example i just want to say this cube this number

14:59:36then what i can do is just go ahead and use this like cube this number and i would not have access

14:59:41to cube right here now this is not destructuring i'm telling you again and again this is not a

14:59:47regular object because in a regular object you might do something like this this is something

14:59:53else this is es6 import syntax that works in a special way so once you do run it you're gonna

15:00:00see you get still the correct output because this right here is a different syntax altogether right

15:00:07so once you have this particular thing done what we want to do next is learn a little bit about all

15:00:15these expo things right so there are a bunch of ways to there are a bunch of more ways to export

15:00:21things so the first one we discussed the export default we're gonna get more into that later on

15:00:26the second one is this object looking syntax right which is again pretty cool the third one

15:00:32is just exporting things as you define them so for example if you have this function you want

15:00:38to export it so you just say export function this particular thing right anything you do not export

15:00:43would not be available outside this module so i cannot just go ahead and make use of square right

15:00:49here but i can go ahead and make use of cube so if i do cube here i'm going to get an error because

15:00:54i do not have square with me so you can see we get an error that square is uh you know it's not

15:01:03something which is available in that particular module because it has not been exported the

15:01:07moment i export this and then if i run this program you're going to see that it works

15:01:12just fine because now this was exported as well so this is another way to export things

15:01:19now if you want to get all these exports for example let's say if i have a

15:01:2450 exports right here and if i want to get all of them well this is a cumbersome way to you

15:01:29know just go ahead and list all the exports right here right so what you can do if you want all the

15:01:36exports inside your program is you can say import star as util or maybe anything which you want

15:01:45any name would be fine here any name which is a valid variable name so let's name this as util

15:01:52from module.mjs now what has happened you see we were importing things like

15:01:59using the object looking notation but when you do import star as util what's going to happen

15:02:05is that it's going to take all these exports which are individual exports for example if i do x

15:02:10for example if this is const num is equal to 5 and if i want to export this i export it like

15:02:16this what we have is in a nutshell we have this module which when imported sort of looks like this

15:02:24square is a function you know cube is a function and num is a function uh num is a number

15:02:32right now you can either go ahead and individually import them just like we did in the last uh in the

15:02:39last demo or you can import them all together like this so now if i go ahead and console.log the util

15:02:44object what we're going to see is something like this you can see we got a cube which is a function

15:02:50num which is a number and square which is a function so now you can probably just fall

15:02:55back to your uh what we did in the common js thing that util.cube and then hundred

15:03:01and once you go ahead and run this you pretty much get what you were expecting for

15:03:07so yeah i mean this is how the import sort of thing works there is a similar syntax for export

15:03:13as well and we're going to be finally taking a look at default exports as well in the next video

15:03:18that is all for this one i'm gonna see you in the next one really soon hey everyone welcome back and

15:03:25in this video let's just take a look at the syntax which i was telling you about this import star ass

15:03:30syntax but on the export side of things so let's just go ahead and quickly create another module

15:03:37so i'm going to say this is module 2.mjs and what's going to happen is in this particular

15:03:43file let's just go ahead and copy these things and what i'm gonna do is right here

15:03:50i'm gonna let's see i'm gonna remove all the content and let's say this has got export function

15:03:59um powerful right because i cannot really think of anything at all so this is num power 4 and we have

15:04:08got num here now my question to you is how would you make um you know something like this possible

15:04:18or can you make something like this possible so if i want to import square and power 4 from module

15:04:32dot mjs can we make something like this possible where we are getting square as well as power four

15:04:38well you see that we are already exporting the function power 4 from this module.mjs the next

15:04:45thing we can do is probably you if you think about this i can say import square from module 2 dot

15:04:54njs and then i can say export square right just like we did with the previous functions

15:05:03well this is one way but this is a boring way but nonetheless it would

15:05:07work so let's just try this out let's just say i have square and power four

15:05:14just as a console.log statement so let's just say and say node es6.mjs and we get that power

15:05:214 does not exist well that is because we named it as power 4 not pow4 so once we do that let's

15:05:30just run this again and you can see that both of these functions are fine square and power 4.

15:05:35just like i said it works but it does not cool so how do we make this cool with export you get that

15:05:42similar power of exporting something directly from a file so what i can say square from module2.mjs

15:05:57so what's happening here and this is basically this should be inside

15:06:01the uh these curly braces which is again object life but not object so what's happening here

15:06:08well you see that instead of like importing it first and then exporting it like that

15:06:13i can directly export it from a file as well and if i try to run my code again

15:06:18you're gonna see that it does not make any difference in fact what you can do

15:06:22is probably go inside this file change the name this square underscore underscore which means now

15:06:27this is not a valid uh you know export right here but i can say export square underscore underscore

15:06:34as a square export right and this renaming works directly we do not have to import it first and

15:06:41then export it like that and it's just gonna work so far so cool how about import star ass syntax

15:06:48where we get all the files all the imports first of all and then export it right and then in use it

15:06:54you can pretty much do the similar thing here as well so i can say export star

15:06:58basically get all the imports from this file first of all get all the exports from this file

15:07:04as and then you can name this as a particular variable which you want so i can say

15:07:10m2 here and then i'm saying from this module 2. now what does this mean is that if i go ahead and

15:07:17log m2 here what's going to happen is we're going to get an object which is going to contain all the

15:07:24functions which we have right here and this const as well so let's just go ahead and run this and we

15:07:31do not have square now which is strange because i do not want this anyway so let's just remove this

15:07:40and let's just try to run this again so you can see the first one uh this is basically a

15:07:46module which is which is what appearing which is what is appearing and the second thing is sort

15:07:51of again like object like thing not really an object but with the right properties right so

15:07:57square underscore underscore is a function q is a you know it's a function again a num is a number

15:08:03so this is how you're gonna just make things right so so yeah this is how you're gonna export

15:08:10all the things right away right so this is how in a nutshell the es6 module system works let's just

15:08:17talk a little bit more about the default exports because i think we did not give a lot of time on

15:08:22that so default exports are basically simple right what you have to do is just export a particular

15:08:28value so i can say export default my name you see that i'm not using const or anything right here

15:08:34you just have to give it a value right no names no identifiers nothing similarly if you want a

15:08:40function to be exported you can rename this to a function if you want a variable to be exported

15:08:46you can rename this to a variable and it's just gonna work fine and you are gonna get the default

15:08:52export directly that means you do not have to write anything right here what you have to do

15:08:59is just write my default export or anything which you want right here and it is gonna work like a

15:09:08default export for you so if i go ahead and remove this bad boy right here and by the way this would

15:09:13work just fine as well so you just just so you know you can import a default export add a comma

15:09:18and then add your uh other regular exports as well so if you do something like this try to run this

15:09:26you can see we get function power 4 which is you know i imported this as a default export you can

15:09:32see that default export does not has any name of its own it just has the value so i'm not really

15:09:38doing export default constant x is equal to five this is wrong i'm just doing export default five

15:09:45right this would be fine if i do not use the default keyword then i would be using you know

15:09:52import x from module.mjs or um you know if there's any other thing which you want to do

15:10:00so yeah i mean this was a pretty much uh sort of a basic burn down of things you will

15:10:07need from the es6 module system and that is all basically that i think i have covered

15:10:13everything which is really really necessary if there's any edge case or anything like that

15:10:18that's basically you're not gonna need that for the most part when you're working with

15:10:22real projects but yeah that's pretty much it for this video i'm gonna see you in the next

15:10:27one really soon hey everyone welcome back and in this video let's just learn about the http module

15:10:35how it works and how you can create a server in nodejs now we have been uh you know just going

15:10:43ahead and ignoring this thing for a while but let's just make a use of this now so what i'm

15:10:48gonna do is let's just remove index.js file right now and let's just touch a server.js file instead

15:10:54so let's just open this and what i'm gonna do is i'm gonna start by importing the http module from

15:11:01node.js so you know we have talked about that we have a fs module here we also have a bunch

15:11:07of other modules which i did not really cover a lot os fs you know we have i think path module we

15:11:14have url module so all of these things are there but the most common one is gonna be fs for you in

15:11:21a lot of operations you are not going to be using os modules as far as i can i can tell you unless

15:11:28you are building uh systems only applications with node.js and if you are using http server

15:11:34you might be tempted to use http but we're going to be learning about express in the next section

15:11:39so wait for that so anyway let's start with a simple very simple http server a raw http server

15:11:46and let's say http.createserver this is basically uh first thing you can notice is we are again

15:11:53using the common js syntax just because i prefer the dot js extension right now you can use the

15:11:59es6 syntax as well it's not a problem the http.createserver means that we want to open

15:12:06a specific port for listening and what we want to do is we want this particular port to listen to

15:12:15incoming connections and by incoming connections what i mean is for example if you visit google.com

15:12:20that is an incoming connection so once there is a connection established to a server you can pretty

15:12:25much do two things with this you can either go ahead and read what the request was that is what

15:12:32the client said or you can go ahead and either set up how the response to the client should look like

15:12:37right so you have two options and what we're going to do is say for example we do not want

15:12:42to worry about what the client said i just want to say rest.right and i want to say let's say

15:12:48hello client over there and yeah that's pretty much it i want to end the response right here

15:12:57once we have this server with us i'm going to store this inside our server variable once we

15:13:03have the server with us what i'm going to say is say server dot listen and then we're going

15:13:08to specify a particular port for this thing by a port i mean we're going to just say

15:13:14which port you want to listen to now if you are working on local that is on your local pc that

15:13:20is inside your file system with vs code and everything whatever you specify here you can

15:13:25go in the browser and open this but because this is a browser environment the code down playground

15:13:30if you are using this just use the port called 1337 or better just go ahead and use process

15:13:39dot env dot public underscore port right now this is three three seven but if you want to

15:13:46change this later on it would not be a problem for you so if you just go ahead

15:13:51and console.log this thing you're gonna see we get one three three seven so i want to listen on this

15:13:55port which is defined within this container if you do echo public port you're going to get 1337

15:14:03right but once we do that what we want to do once the server is up and listening i want to say

15:14:10hey we are ready to take requests right and yeah that's pretty much it for a very simple server

15:14:19so let's just go ahead and write node server.js and you can see we get 1337 from the statement

15:14:24and we immediately get that hey we are ready to take some requests so once we do that give

15:14:31it a couple of seconds and you can see that this changes to a ngrok url here and you get the hello

15:14:36client over there you can basically go ahead and open this in a new tab as well if you want

15:14:41to have a full screen for yourself and this is an actual response from a node server right so

15:14:46let's just go ahead and just modify this with a bunch of exclamation marks and once we do that

15:14:52we have to restart the server as well so we're gonna run this command again and if i go back

15:14:58refresh this we get our updated response right here so this is how we're gonna create a pretty

15:15:04uh small server in node.js and we're not gonna be using http module for creating servers why because

15:15:14you're gonna soon realize that if you want to for example uh just determine that if the user is on

15:15:22slash admin right so if the user is on slash admin you want to serve him different content so you

15:15:28have to do this by request dot path or request or something else which which is a sort of a property

15:15:34on the request object and you have to do a lot of manual work yourself so instead of doing that

15:15:40what we can do is make use of libraries like express which simplify all this work for us

15:15:46and helps us create better and efficient not really efficient but better and easy to look

15:15:51servers right away so yeah that's pretty much it for this video in the next one you're going to

15:15:57be learning about express servo how we can set up all that stuff and create a create some websites

15:16:03with no chairs so that's all for this video i'm gonna see you in the next one really soon

15:16:10hey everyone welcome back and in this video let's just learn about the http module how it works and

15:16:17how you can create a server in nodejs now we have been uh you know just going ahead and ignoring

15:16:25this thing for a while but let's just make a use of this now so what i'm gonna do is let's

15:16:30just remove index.js file right now and let's just touch a server.js file instead so let's just open

15:16:36this and what i'm going to do is i'm going to start by importing the http module from node.js

15:16:42so you know we have talked about that we have a fs module here we also have a bunch of other modules

15:16:49which i did not really cover a lot os fs you know we have i think path module we have url module so

15:16:57all of these things are there but the most common one is gonna be fs for you in a lot of operations

15:17:03you are not going to be using os modules as far as i can i can tell you unless you are building uh

15:17:10systems only applications with node.js and if you are using http server you might be tempted to use

15:17:16http but we're going to be learning about express in the next section so wait for that so anyway

15:17:22let's start with a simple very simple http server a raw http server and let's say http.createserver

15:17:29this is basically uh first thing you can notice is we are again using the common js syntax just

15:17:36because i prefer the dot js extension right now you can use the uh es6 syntax as well it's not

15:17:41a problem the http http.createserver means that we want to open a specific port for listening and

15:17:50what we want to do is we want this particular port to listen to incoming connections and by incoming

15:17:58connections what i mean is for example if you visit google.com that is an incoming connection

15:18:02so once there is a connection established to a server you can pretty much do two things

15:18:07with this you can either go ahead and read what the request was that is what the client said

15:18:14or you can go ahead and either set up how the response to the client should look like right

15:18:18so you have two options and what we're gonna do is say for example we do not want to worry about what

15:18:24the client said i just want to say rest.right and i want to say let's say hello client over there

15:18:33and yeah that's pretty much it i want to end the response right here

15:18:38once we have this server with us i'm going to store this inside a server variable once we have

15:18:44the server with us what i'm going to say is say server dot listen and then we're going to specify

15:18:50a particular port for this thing by a port i mean we're gonna just say which port you want to listen

15:18:56to now if you are working on local that is on your local pc that is inside your file system

15:19:02with vs code and everything whatever you specify here you can go in the browser and open this

15:19:08but because this is a browser environment the code down playground if you're using this just

15:19:13use the port called 1337 or better just go ahead and use process dot env dot public underscore port

15:19:24right now this is one three three seven but if you want to change this later on it would not

15:19:28be a problem for you so if you just go ahead and console.log this thing you're gonna see we get one

15:19:34three three seven so i want to listen on this port which is defined within this container if you do

15:19:39echo public port you're gonna get one three three seven right but once we do that what we want to

15:19:47do once the server is up and listening i want to say hey we are ready to take requests right

15:19:58and yeah that's pretty much it for a very simple server so let's just go ahead and

15:20:01write node server.js and you can see we get 1337 from the statement and we immediately get that hey

15:20:07we are ready to take some requests so once we do that give it a couple of seconds and you can

15:20:13see that this changes to a ngrok url here and you get the hello client over there you can basically

15:20:19go ahead and open this in a new tab as well if you want to have a full screen for yourself and

15:20:23this is an actual response from a node server right so let's just go ahead and uh modify this

15:20:30with a bunch of exclamation marks and once we do that we have to restart the server as well

15:20:36so we're going to run this command again and if i go back refresh this we get our updated response

15:20:42right here so this is how we're going to create a pretty small server in node.js and we're not going

15:20:50to be using http module for creating servers why because you're going to soon realize that if you

15:20:57want to for example uh just determine that if the user is on slash admin right so if the user

15:21:06is on slash admin you want to serve him different content so you have to do this by request dot path

15:21:11or request or something else which which is a sort of a property on the request object and you have

15:21:16to do a lot of manual work yourself so instead of doing that what we can do is make use of libraries

15:21:23like express which simplify all this work for us and helps us create better and efficient not

15:21:29really efficient but better and easy to look servers right away so yeah that's pretty much

15:21:35it for this video in the next one we're gonna be learning about express servo how we can set up all

15:21:40that stuff and create a create some websites with no chairs so that's all for this video i'm gonna

15:21:46see you in the next one really soon hey everyone welcome back and in this video let's just discuss

15:21:53a little bit about how this get thing works and what this really means and this path as well

15:21:59so let's just take a little bit of detour to the networking part of things and to be honest

15:22:05if you're following the back and learning path of code damn this is the very first thing which

15:22:10we really do right so if you're following this all the way from internet to node.js basics right here

15:22:15you should have this understanding but still let's just go ahead and do it really quick so you can

15:22:21see that right here our request url is something like this right which is a just a slash basically

15:22:28nothing is written in the path you see the request method is get so our browser when you refresh a

15:22:34page or when you visit any page what happens is the request method whenever you write something

15:22:40like google.com and hit enter is always get by default there are a bunch of other methods in

15:22:46http uh standard not really standard in the in the sort of rest convention which are post there is

15:22:55also put there is also patch there is also delete but the most common ones are the get and the post

15:23:04right so these are the two most common methods you're gonna see all the time so with express

15:23:10what you can do is you can define certain behavior on certain parts depending on what the method is

15:23:16so you can say that hey i want to have a get certain behavior on something and probably

15:23:24let me just go ahead and copy this thing and i can say hey something's somethings here right

15:23:38so once we do that let me just go ahead and actually restart this over here real quick once we

15:23:43do that and visit slash something now what you're going to see is that hey something's here is what

15:23:49we get so this was defined as defaulting for the get behavior right here right i can do a similar

15:23:58thing for a post behavior so i can do on a similar path but this time i want that hey if something is

15:24:05being sent as a post thing that is this right here is a post method then this should be this

15:24:14is usually not visible right and let's just go ahead and start this over again i might just go

15:24:21ahead and do a nodemon here instead but anyway so if i refresh this you can see that hey something

15:24:28there here is still what we see but we never see this is usually not visible so how do we make sure

15:24:33that we see this thing well in order to see this thing what we have to do is we have to perform

15:24:39this request with the help of a method of post right so i'm using fetch api to basically let me

15:24:48just go ahead and remove this as well so let's say i want to perform a fetch api request to the sport

15:24:54uh this post and i want to wait for the response of this particular thing as well yeah rest.txt

15:25:04right so this is a little bit of front-end stuff and you can see that we get this is not usually

15:25:08this is usually not visible now if i go to the networks tab you can see we see two requests the

15:25:13first one is the get which was our initial paid load uh page reload and the second one had a post

15:25:19method in the post method the server said this is usually not visible right why did it say that

15:25:25because first we had we are using a post request here and second we are using a post sort of

15:25:34catch here for the route as well so we know if the post request is coming we have to handle it

15:25:39using this function what if you try to send a post request to home page which does not has any uh

15:25:46handlers so if i do that you can see we get a 404 which is basically not found right so you can see

15:25:54express sees us that hey you cannot really post on this domain because nothing is available similarly

15:25:59if you try to visit any broken url you can see you get an error that cannot get this particular

15:26:05thing because your method was get similarly if you try to have maybe a put method here you can see

15:26:13we see an error cannot put which is basically the method name if you try to do a patch here

15:26:19you get cannot patch right here right and all of these which are common http

15:26:25uh request methods you can define them with express so you can say instead of get you

15:26:30want to have this thing on the patch right now if you go ahead and restart the server what's really

15:26:36going to happen is now if you go ahead and send a patch request you see hello world and if you

15:26:43try to refresh this right here without uh anything you get cannot get right so that's how things work

15:26:50in the rest world and in the web world basically you use this particular identifier to define what

15:26:57sort of method you want this particular function to be called on you use this argument to define

15:27:03what path you want this method to be called on and you use this rest object right here to send

15:27:09response right so i hope this gave you a little bit of understanding of how different methods work

15:27:15and how you can make use of express to set up all sorts of things on same paths as well so you can

15:27:21have a get method a post method a put method a patch method everything on the same path as well

15:27:27right so yeah that's pretty much it for this video i'm gonna see you in the next one really soon

15:27:35hey everyone welcome back and in this video let's just see how we can send some static data

15:27:40to the front end basically instead of like sending this hello world or stuff like this

15:27:45i really want to send a html file right so what we are going to do for that is first of all we

15:27:51are going to import another module called path so i'm going to save path from required path

15:27:57oops and this is an internal node module you do not really have to install it next thing

15:28:02is instead of patch obviously we want kit and instead of rest.send i want to say rest.send file

15:28:09right because this would allow us to send an actual file to the server and what we can do

15:28:14is i can just go ahead and say path dot resolve and right here i'm gonna write dir name and let

15:28:21me just go ahead and finish this first of all and then i'm gonna explain you in a much better way

15:28:28so we have path dot resolve set to public index.html which basically means what's gonna

15:28:34do is in the current directory it's gonna look for a folder with the name public right and it's

15:28:41going to look for a file named index.html inside this particular folder right so we have a public

15:28:48index.html file with us let's just go ahead and copy paste this uh sort of a template which i

15:28:54got from the bootstrap docs so here we are inside this index.html let's paste this right so this is

15:29:02a not a very fancy template just some uh just some regular html right here with some bootstrap loaded

15:29:11so you can see that there are some links which are going to break once we try to do this like this

15:29:16pricing is not available with us we even do not even have the bootstrap all these things available

15:29:22so we're going to fix them later on but for now let's just take a look at this

15:29:26so once we have done that you can see that if i try to restart the server

15:29:31and reload this you can see that we get this html file delivered to us although it is broken at the

15:29:38moment but you still get the idea right that it is sort of working so this is how you can

15:29:43send static files not really static files this is how you can send any regular file using rest.send

15:29:49file as a response right you can even send javascript file or maybe a css file if you want

15:29:55but we have a better method of serving those we're going to take a look at that later on but this is

15:30:00how essentially we're going to start building a very simple sort of thing which is delivered by

15:30:06node at the back end so that's all for this video i'm gonna see you in the next one hey everyone

15:30:12welcome back and in this video let's just take a look at how we can send static assets to the front

15:30:20end as well so what happens that a lot of times you don't really want to have individual routes

15:30:27or maybe it's impossible to have individual routes like right so for example if i want to serve uh

15:30:34let's see if i want to serve this pricing.css do you really think i should just go ahead and write

15:30:39app.getpricing.css and then request response i should write this whole thing again

15:30:47now technically i can do that and it will work as well but this is just unnecessary right because a

15:30:53lot of times a lot of websites use a lot of static assets so what we have with express is a better

15:30:59way of using these particular static assets right and that is by just saying app.use and then we

15:31:07can use express dot static and this function right here allows us to tell that hey where do you want

15:31:16to serve or which directory do you want yourself to serve your static assets from so i'm just

15:31:23going to say part.resolve dir name dir name is basically just the current working directory name

15:31:30and then i'm gonna say this would be public right so we just want our public folder

15:31:37to be statically delivered every time and one quick thing is that you want this static asset to

15:31:46be delivered on let's say the root of the domain or let's say i want this to be on static right now

15:31:51just to make things simpler so right so i have this thing that means i want to use whenever

15:31:57i'm using static this particular thing should handle what should happen to this particular path

15:32:04and what should really happen to this particular path is that express should look inside the public

15:32:10folder to check if there's a file depending on where the user what the user has requested

15:32:16and if there is then just deliver that particular file so let's just restart the terminal one

15:32:21more time and let's just take this url and open this in a new tab

15:32:27so you see we still get the html which is fine but if i go to like slash static and if i'll hit

15:32:35static slash index.html you see we get this same html again right but there's a difference the

15:32:42difference is this time this is solved by this particular route if i go ahead and remove this

15:32:48and restart it if i refresh this you can see this thing still works but this would not work

15:32:56because of obviously that this path no longer points to any particular uh file or any particular

15:33:04function which can handle that let's do one more thing let me just go ahead and add a

15:33:10secret dot txt file here and we're going to create let's say this is a super secret file

15:33:17don't tell anybody about this right and we will be making sure that this is inside public folder

15:33:25you can see it's inside public folder and we are not adding anything here at all but because we are

15:33:30serving all the files from the static thing what we can do is just go ahead right here

15:33:35and say inside static i want to visit this secret dot txt and hit enter and you can see that we get

15:33:42this this is a super super secret file right out of the box so this is how static works

15:33:49in express it is very useful for static assets like images css you know javascript if you have

15:33:56on your website and that is how you can serve them whether you know you can just go ahead and

15:34:02create a folder public static here and point this like that so that's how you're gonna do it that's

15:34:07how it works and that is all really for this video i'm gonna see you in the next one really

15:34:13soon hey everyone welcome back and in this video let's just go ahead and take a look at how you can

15:34:20accept data from front end to back end with no chairs by accepting what i mean is it could be

15:34:27any form submission it could be any field which you want to get it could be any sort of behavior

15:34:33right so first things first let me just go ahead and quickly create that particular interface so

15:34:38i'm just gonna have a really simple html body you know nothing fancy although i should go ahead and

15:34:47head here as well but yeah that's pretty much it so let's just create a simple

15:34:52input type text and i'm gonna say this has an id of username and this would be password

15:35:04and that's it button id summit and i'm going to say summit right nothing really fancy let's just

15:35:15go ahead and yeah of course this will not work because we are not serving static assets from here

15:35:20let's serve the static assets from the root of the path right that is the root domain so

15:35:26that we get all the benefits of getting index html right away on this right so we have this

15:35:33nice little form with us and yeah you can also just go ahead and say auto complete

15:35:41off if you don't really want to bother your users right refresh there you go

15:35:49so the next thing is that we want to receive whatever the user is writing when i click on

15:35:54summit i want to receive it on the backend so let's just add a quick script here i'm going

15:35:59to say this is script.js and i can do that by placing the script.js inside our public folder

15:36:06itself because this script this whole folder is actually being served as a static thing

15:36:11over this whole domain sort of thing so let's just go ahead and quickly add a couple of eventlessness

15:36:18on these buttons and things so this is first of all summit so i'm going to say document.getelement

15:36:23by id summit on click i should get the username would be document.getelementbyid username i guess

15:36:33we can just check and then password would be password like this right so what should happen

15:36:40is once i click this once we have the values this this input right here should go to our server

15:36:47so the next thing is actually defining a route for that so i want to say data

15:36:52and then i'm gonna define request response and i'm just gonna say response

15:36:56dot send okay you can also use json here to send a json response and say

15:37:02status okay something like that which is just a fancy way but either one of them would work

15:37:08and right here what i want to do is i just want to console.log request.body

15:37:13because this is the place where our information would be stored information would be available

15:37:18for us to parse right so we once we have this route let's just go ahead and restart the server

15:37:23here real quick and inside our index dot or really script.js file what i'm gonna do next is let's see

15:37:33is i want to have a ajax call made which is using fetch so i'm going to say data right here

15:37:42i'm going to specify the method would be post the body is going to be json.string

15:37:49efi stri ngi fy username and password right so this should be our body and one quick thing is the

15:38:00content type of the thing which we are sending is json so i want to say this is application

15:38:07json from front end so once we do that this should be more than enough for getting

15:38:13a response i want to say response.json we are expecting a json response from server because

15:38:20you can see that inside our server.js we wrote this particular block right so we are getting

15:38:26a json response from server as well so there's that and then finally i just want to console.log

15:38:35console.log what we really got that is the data right so so much going on here on the front end

15:38:44i hope there's no confusion here because we are not really learning front end uh right now so

15:38:50once we do that on the back end what's gonna happen is we're just gonna get a console log

15:38:54of request on body so if i go ahead and submit this or maybe just refresh this first of all

15:39:00and go ahead and submit this you can see that we get our request.body as undefined right now

15:39:07why is that you see express by itself does not contain the parsed body and anything like that

15:39:14but you can extend the functionality of express to do that and how you do that is by installing

15:39:19another package known as body parser so go ahead and install npm install body parcel

15:39:25and right here this package is going to allow you to pass the body which is coming

15:39:30so i'm going to go ahead and import this first of all i'm going to say body parser is required body

15:39:38parser and then just before our post request i'm going to say app.use and you just have to

15:39:44do it once just like we have done it for static ones so i'm going to say app.use

15:39:49bodyparser.json right and that's it this would make sure that the request or body inside of our

15:39:58express contains the relevant parts to json if it is coming as a json object so let's just go

15:40:05ahead and do npm or really notes over.js and refresh this try to submit it one more time

15:40:12and you're going to see that now we get username as an empty object and password is an empty object

15:40:18because this should be dot value right not the node itself so let's just do it

15:40:26one more time and submit it and you can see now we get the correct username and password

15:40:31and just so you know that it's different you can see it's a different password right

15:40:38so yeah this is how you're gonna receive and send response to the back end using body parser

15:40:44in express that is all for this video i'm gonna see you in the next one really soon

Learn Next.js 11 - Build Modern Next.js

15:40:51so what is going on everybody welcome to the very first video for our next js course and

15:40:57in this course in this whole web series we're going to be working a lot with next years we'll

15:41:02be developing a lot of projects on the way we'll be learning the ins and out of the framework so

15:41:08if you're watching this course on code damn you are going to be

15:41:13updated with the latest next year's frame books as they roll out currently it's 9.5 and

15:41:19yeah if you're watching this on codedumb.com and if there's any significant change the contents

15:41:24would be added again to the framework if not to the to the learning path if not then please go

15:41:30ahead and sign up on codedown.com for watching the same content all right with that being said

15:41:37we're going to be exploring a lot just like i said in this in this whole web series but starting off

15:41:42with some prerequisites some requirements i would say you must have for this um next year's course

15:41:52uh obviously the first thing is that you know if you are a react developer please and please

15:41:58only then follow along with the course this course is not for people who are extremely

15:42:03new to react or who are extremely new to html or css and you probably know this if you have

15:42:08been following the next year's road map on code dam which you can see right here with us so we

15:42:14on the uh next year's roadmap we actually start with the basic html and css skills then we build

15:42:20some javascript skills then react fundamentals and then we come to next js so this is very important

15:42:26you must have basic html css javascript and react fundamentals with you before you start working

15:42:33with nextgs because for the most part nexus is going to contain a lot of react code a lot of

15:42:40best practices of react code a lot of react so this is one thing i want to just put out there

15:42:46if you do not have access to uh if you do not have knowledge for the html css and react

15:42:52you can always go to the next js mastery learning path you can find all the links

15:42:57and get started with those topics first so yep that's what that would be all uh for the learning

15:43:05path at least and for this whole course we're gonna be building just like i said a lot of things

15:43:10along the way so i'm pretty excited to start this course i hopefully i hope that you are excited as

15:43:17well so let's get into it and we're going to be learning a lot of things in this whole web series

15:43:23everyone welcome back and in this video let's just go ahead and go over what next js really

15:43:28is and why it is needed so next chase is a wrapper to speak as of you know in in the in the simplest

15:43:37terms i would say next years is a wrapper around react framework which enables your react code to

15:43:44pre-render which enables your react code to run on the server what do i mean by that well

15:43:50you see when you're working with the react website which is just the client-side javascript code what

15:43:56happens the process is that firstly your client with down will download the code from the server

15:44:02then that javascript code would be executed by the browser and then you're going to see

15:44:07the actual output on the screen the actual html elements and divs and all that but if you take a

15:44:13look at sites which are built with next shares what you're going to see is that if you go to

15:44:17view source you could pretty much see all the content within the html document itself right

15:44:23for example i can just search this text pre-rendering right here and this is the

15:44:29h3 tag which we are seeing right now right this is statically generated and server-side

15:44:33rendered react applications and this is what we are seeing so you see that in this case in the

15:44:39case of nexus the server is actually sending you the html itself but in case of react applications

15:44:47the server sends you javascript bundles which is then executed by the browsers and then the

15:44:55the output is displayed to the user now this is one of the many benefits next year springs in but

15:45:02this is the most important one right everything else you know zero configuration fully extensible

15:45:09static exporting let's just leave that because that is also sort of pre-rendering only

15:45:13css and js ready for production all these are actually possible with just react as well but

15:45:20with nexus with these two features basically the pre-rendering one because this is just a

15:45:27side effect of that but because of pre-rendering it opens a lot of doors for performance for seo

15:45:35for caching stuff like that and it is it is awesome the only thing which nexus truly

15:45:42does which which makes all the difference is this thing that is server side rendering of react code

15:45:48on the server so that your server actually sends html instead of javascript bundles on your screen

15:45:55so this is what next.js is about in a nutshell and yeah that is that's why i wanted you to have

15:46:03a basic understanding of react because in next we'll be following certain practices said by the

15:46:09framework we'll be following certain patterns certain design patterns but for the most part

15:46:15because we are writing react code itself the principles the underlying principles remain same

15:46:22so yeah that's pretty much it for this video hopefully you understood the difference between

15:46:28next and react and why it is needed we'll come to performance benefits seo

15:46:34you know stuff like that later on in the series because that's technically not related to

15:46:38the coding part directly it's more about the user experience and the marketing side of the things

15:46:44but that is very important as well so anyway that's all for this video if you liked it

15:46:50let's just move on to the next one really quick so what is going on everybody welcome back to another

15:46:57video in which we'll be starting off by setting our next chairs project so first things first

15:47:03what we're gonna do is on your systems go on your systems and make sure that you have node and npm

15:47:10installed and i'm assuming that you are a react developer you have some sort of experience with

15:47:15react so you should have that by default once you do have that just go ahead and write npx create

15:47:22next app and just go ahead and write the name of your project in our case it would be hello

15:47:29next you could have any name here you want and the next thing is i'm gonna pass in a flag called dash

15:47:37dash use npm now the reason i'm passing this flag is because i have both yarn and npm on my systems

15:47:44so i want to use npm that is why i'm using this thing and for the matter of fact what this npx is

15:47:51how this all is working if you want to dive deep into this we have a dedicated course for

15:47:57npm mastery as well on code dam hopefully you're watching this on goddamn.com so you can go ahead

15:48:03and check that out as well if you want to learn more about how npx and everything works

15:48:08so once you have that just go ahead and hit enter and it should be up and ready in a

15:48:14couple of minutes now mind you that we would be using typescript in this whole um course because

15:48:22typescript is a production ready technology it enables you to write high quality code while

15:48:28suppressing a lot of errors which might just slip in so you get all those benefits of static type

15:48:34checking and auto completion and jumping in code here and there and refactoring and all that stuff

15:48:39so it's a pretty decent deal so once we have done that once the project is initialized

15:48:46let's just go ahead inside the folder hello next and let's see what's going on here

15:48:52so if we take a look inside the files section okay i think we did not really open that correctly

15:48:59if we take a look inside the files section

15:49:04all right so you can see right here that we have some js files and not a lot of activity going on

15:49:10right we have some regular package json files and everything and i'm gonna get to the whole

15:49:14directory structure later on in some in the next video but for now just stick along with me

15:49:20and let's just go ahead and convert these into typescript so it's as easy as doing this

15:49:26with nextgs right just make sure your extension is tsx for the files which actually use

15:49:33jsx and you could go ahead and keep it dot ts for the files which are you know just pure typescript

15:49:40or just pure javascript right once you do this it should be enough now if you're coming from a

15:49:46typescript background you're gonna immediately notice that we do not have a dsconfig.json here

15:49:52but the thing is that next.js can automatically take care of that

15:49:56how awesome is that so i'm just going to go ahead and create a file called tsconfig.json

15:50:00i'm going to keep it empty this would be handled by next js we don't have to really

15:50:05mess around with initially at least and what i'm going to do is we can see that we just have three

15:50:11dependencies at the moment next react and react on so what i'm going to do is i'm going to install

15:50:16a couple of mores which would enable us the type support and all the nice features of typescript

15:50:22so i'm going to install typescript right here i'm going to install the node types which is going to

15:50:29enable us to write server side code and i'm going to install the react types which is going to give

15:50:34us autocomplete on the client side code for react and i'm going to say this as save diff because

15:50:41these are dependencies which we don't really want on production because on the production nexus

15:50:46would automatically be you know compiled down to javascript and all that good stuff so once you do

15:50:52that we are basically done to see our hello world now you might see some of these errors but don't

15:50:57worry about them these are all false positives they would be all rectified once we fill up this

15:51:02ts config so to do that we're going to go ahead and write npm run div which in turn is going to

15:51:10go to package.json and see that we have a dev script which is going to run next if and next

15:51:16f is magic it is going to take care of the server initialization compiling your typescript you know

15:51:22how to auto reloading hot reloading of code fast refresh all that stuff all that good stuff out of

15:51:28the box it's just magic so we go ahead and run this and you can see that it says to me that we

15:51:36detected typescript in your project and created a ts config json file for you so that's very nice

15:51:41of next js right and you can see that we get a nice little populated tsconfig.json file with us

15:51:50plus a next.enb ts file which is a typed file but we don't really need to worry a lot about this

15:51:56but for the most part you can see that our code base is purely in typescript we don't have any

15:52:01javascript yet but we can still go ahead and visit this url that is localhost 3000

15:52:09and we're going to see that we get a nice little page creating us welcome to nextjs

15:52:13we can in fact go ahead to index.tsx and change this from next shares to next ts because why the

15:52:20hell not and you can see without even reloading with the help of fast refresh we get immediate

15:52:26update to our page so we're gonna explore a lot about what these technologies uh what what sort of

15:52:34architecture next year's follows and uh what's actually happening in the main app itself but for

15:52:40this video i think this should be enough to get you started with next year's hopefully you were

15:52:44able to follow along till now if not let me know in the discussions below i'm gonna get back to

15:52:50you if you are stuck anywhere that's all for this one i'm gonna see you very soon in the next video

15:52:58hey everyone welcome back and in this video let's just go ahead and explore our project a little bit

15:53:03because we haven't really seen what's going on here so i'm just gonna minimize the terminal for

15:53:09you and i'm gonna close these files now what we see it on our left that is the file structure it's

15:53:15pretty interesting now the reason it is laid down in the following sense is because nexus requires

15:53:23a specific file structure which is not a lot of technologies which is not what a lot of

15:53:28technologies do outside there and it's sort of you know some people like it some people don't like it

15:53:35but this is what it is at least for now with next years so what's going on well first things first

15:53:43you see this public folder right whatever you put it in the public folder is going to be directly

15:53:49accessible on your root domain in our case you can see we have two files that is favicon and versal

15:53:57so if i go ahead let me just go ahead and bring this right here if i go ahead and just go to

15:54:05versel.svg in my url you can see right here i get the versa because this file was put right here

15:54:12right similarly for fabricon if i go to that url you're gonna see we get our favicon right here if

15:54:20you could just see it in the dark if i create a file let's say robots.txt and if i say hello

15:54:28robots you know stuff like that save that file go to robots.txt what you're going to see is we get

15:54:36the same file so it's basically a directory which next chase uses internally to serve off files as

15:54:44it is now if you create an index.js or anything it would not be processed by nexus it would not be

15:54:51executed as a node command by next year's it would be served as it is right so you have to be careful

15:54:58about this whatever you put inside the public directory is directly accessible by anyone right

15:55:04as as the raw source thing and a good thing is it does not matter where your contents is as long as

15:55:13it is in public directory so you can have a bunch of folders for example a b then you can have c

15:55:20dot txt and you can say hello there and how it would be accessible is pretty much a b c dot txt

15:55:31just like that right so it's just going to follow the whole direct directory path and reach out to

15:55:38that particular file just like it would work on a file system so it's pretty neat because you know

15:55:43now you have a one-on-one pairing on how you are storing your files and how they are served right

15:55:49most of the frameworks like express provide that as well with the static express.static middleware

15:55:56but the nexus provides that out of the box without you writing any code or any configuration so this

15:56:02is about the public folder in nextgs there's another interesting folder you can see pages

15:56:09which is basically the heart of our application which is basically our source code would live

15:56:15right so we're going to discuss a lot more about pages um as we go on because this is

15:56:21like the central part of the routing system as well but for the most part this styles folder

15:56:28is not really required so you can go ahead and move the styles folder inside public as well i

15:56:33mean that would just make your styles accessible through a url instead of like bun link but

15:56:40it won't really matter right because your css is visible anyway so you can or you if you can if

15:56:47you want you can keep the styles in a separate folder or you can move them inside the pages

15:56:53folder itself right so if you do that what's going to happen is you can delete this styles folder

15:57:01so to just get rid of a new folder and right here instead of importing it like this now because you

15:57:07have deleted it just import it like this right and inside index.tsx as well just import the

15:57:14home.css style directly so if you do that and if you go ahead and go back on the page you're

15:57:21going to see it pretty much looks just like before right and yep that's basically it for the whole

15:57:28structure so now you more or less have only two folders pages and public which are a must to have

15:57:37in a similar way well actually there's one way to have pages as well so you can create an src folder

15:57:44and then throw in pages inside that that would also work just like it is working right now

15:57:49but i'm not really getting into that so i'm just gonna remove my src folder for now but the idea is

15:57:56you must have two folders the first one is public for static assets and the pages folder for your

15:58:03source code which is responsible for running the node code and rendering your react code on

15:58:08the page as well we're going to discuss what this api is later on it is something special

15:58:14not really related to the rendering part but yeah it is special so that would be all for this video

15:58:21i hope you liked it i'm gonna see you pretty soon in the next one let's get there

15:58:28so what is going on everybody welcome back and in this video let's just go ahead and explore

15:58:33the pages directory a little bit now we are not really going to explore all the routing part

15:58:40just yet but pages provide a very powerful yet simple to maintain routing mechanism

15:58:47in next year's so what happens with pages is that whatever file next js finds ends with dot ts dot

15:58:57tsx dot js.jsx inside the next js folder inside this pages folder it would create a path of that

15:59:07or to or to speak in the in the reverse way whenever you visit something which is

15:59:14like yourwebsite.com my page next js is going to find mypage.tsx basically resolve

15:59:22that my page module inside the pages folder and it's going to return that component

15:59:28that react component to the browser enough of talking let's actually see what i'm saying

15:59:35there's just one exception to that and that is the index.tsx that is index.tsx is actually available

15:59:43on your root domain and not on slash index right so if you go to slash index you're going to get

15:59:48404 but if you're on your root domain that is where index.tsx is actually displayed

15:59:55so what we want to do really is let me just go ahead and trim this down real quick because we

16:00:01have a lot of code right here and i'm just gonna actually just get rid of this as well i'm just

16:00:07gonna say we have h1 hello world right here and maybe i can just even get rid of that so we have

16:00:15a very very small and very simple react component with us here and if we go on the page you're gonna

16:00:20see that is exactly what we get but hold on if we go ahead and take a look at the view page source

16:00:27you can actually see hello world written in the html itself now this is not something that happens

16:00:36when you're using react right just go ahead and try out an application with create react app

16:00:41create a component which says hello world and display it and go to the page source and you're

16:00:46never gonna find this h1 hello world tag there so what really happened here is that this page

16:00:54this component was actually rendered on the server by next years and it was you know

16:01:01crunched into the html and returned to the client this way this has multiple benefits

16:01:07in terms of seo and performance but the most notable benefit you can see is the client

16:01:13now when the when the page is loaded is never waiting for any sort of javascript to execute

16:01:19for displaying the content which increases performance a lot for the client side right

16:01:25so yep that's that's basically how the pages thing work so if i go ahead and create a nice page dot

16:01:34tsx for myself and if i just go ahead and copy paste this whole thing and i say let's see this

16:01:42is a super nice page hit save and if i go ahead on nice what was that nice page here nice page

16:01:52you can see i get it this is a super nice page right out the bar out of the box i had to do

16:01:58no routing i had to you know just write nowhere i have to write like if i go to slash nice page

16:02:04this should execute it is automatically handled by next js and this is some sort of behavior

16:02:10you cannot really change at the moment so you know you just have to return a component here

16:02:16you cannot just just return for example you cannot just return to here because if you do that

16:02:21you're going to see you get an error that the export is not a react component so the default

16:02:28export from your any file inside this pages folder just ignore the api folder for now any file inside

16:02:35this pages folder which is a javascript file should export a react component right

16:02:41as a default export and once you do that it's just going to work just like that right

16:02:48you can create as many pages as you want nice page 2 dot tsx this is

16:02:56also a super nice page right and if i go to that we get this is also super nice page all

16:03:02rendered on the server side this is also you can also see this it is available in the source code

16:03:08and as we create more and more complicated apps you're gonna realize the importance and benefits

16:03:12of this plus the fact that you do not have to customize anything out of the box is just

16:03:20mind-blowing i mean this the setup works right off the out of the box it is typescript react jsx

16:03:28webpack babel everything hidden away from you nothing is available right so nothing is

16:03:35actually visible but you can actually get finding control of everything if you want by a file called

16:03:42next.config.js which we're going to discuss later on but you know this is this is something i love

16:03:47about nexus it's simplicity to start and it can grow as complex as you want when you want it

16:03:54right just like it just like every framework should be so this is all about pages introduction

16:04:01to pages we're gonna learn a lot about pages and routing and everything in the routing section but

16:04:06that's all for this video i'm gonna see you pretty soon in the next one hey everyone welcome back

16:04:14and in this video we're gonna be taking a look at a special file known as underscore document.tsx

16:04:20now this is a special file because just like i said when we create it it's not going to be

16:04:25available at slash document.tsx but in fact it is the file which is responsible for all the

16:04:32other things in your document right so you see that we wrote this here this h1 here inside our

16:04:40index.dsx with a div but we did not really write all this other things stock type html html head

16:04:47you know all these scripts and everything we did not write that so how did this came as a response

16:04:54well that is precisely what document.tsx allows us to control but for the most part we don't really

16:05:01want to mess up we don't really want to you know just just mess up with the next js things

16:05:07document.tsx is used for um you know injecting our own custom code injecting our own custom

16:05:14scripts which we want to be available for the whole application so what we want to do is just

16:05:22go ahead oops inside pages create a file called as underscore document.tsx and first of all just

16:05:30like i said we don't want to mess up with nextjs so what we're going to do is we're going to import

16:05:35certain things i'm going to import html head main and next script this is um i think what is

16:05:44required from next slash document and what we're going to do is we're going to actually export a

16:05:52class this time not a function now bear with me we're going to export a class custom document

16:06:00why we are doing this instead of a functional component is because we have to extend

16:06:05our original document and why is that because it implements certain methods certain certain

16:06:12functionalities which are important for the next js to actually use right i'm sure there's a way

16:06:20in functional components as well where we can assign this document somewhere in the prototype

16:06:25chain but the best way the cleanest way is to just make use of class based component

16:06:30in a single file you know just just bite the bullet and use it for once in your whole

16:06:36application because document.tsx would honestly be a very small file even after you customize it

16:06:44so what we want again with class based components we just need to have a single render function

16:06:49and what we want to return is basically the whole structure right so we want head right there don't

16:06:57really focus a lot on these tags right now we're gonna be making use of head again somewhere in the

16:07:02next videos but i don't really want you to get confused with this head right here so i'm gonna

16:07:08keep that blank we're gonna write main and finally we're gonna write the next script as well right

16:07:16and actually the main should really go inside the body which is a re regular html tag you know and

16:07:25let's just restart the server once because it does not really capture changes for a document and app

16:07:33and if we reload now you're gonna see nothing really changes but what we can do now is

16:07:38that we can go ahead and inject something like meta property custom and then value

16:07:49i don't know yolo something like that right and it's i don't know what's what's the

16:07:57content yeah so here we have it refresh you can see now that we have a meta property custom and

16:08:06content yellow right now the point is that this is actually available on every page

16:08:12even on pages which are 404 right so you can see that we get 404 this page cannot be found

16:08:18but we still have the yolo property available for us because this is the absolute base template

16:08:24which is used by nextgs for rendering things for rendering your page right so a bunch of things

16:08:34use this file as minimal as you can number one because this is a root file this is

16:08:41something which can control your whole application so you never really want to

16:08:45mess a lot with the global files so just just you know use this file if you want to

16:08:52probably inject some sort of metadata which is for verification purposes of your website

16:08:57or i don't know just just keep the usage of this file to minimal because for the most part you

16:09:01will be able to customize all the titles all the head stuff everything using um the actual you know

16:09:12the actual pages which are available right here so you can do all that stuff from here as well so you

16:09:19know if you want to inject a particular script you can use that this would be available then

16:09:24throughout the web pages throughout the website some analytics scripts anything you can do that

16:09:31so yeah i mean that would be pretty much it for this video and in the next one we're going to be

16:09:37exploring another file called as underscoreapp.tsx which is slightly different than this one

16:09:44and we're going to be understanding how's that so that's all for this one and i'm gonna see you

16:09:49in the next video hey everyone welcome back and in this video let's just go ahead and take a look

16:09:56at app.tsx file in next.js so again just like document.tsx underscore app.tsx is also a special

16:10:04file so i'm going to go ahead and create that but it's a little bit different than document.tsx and

16:10:10a little bit simple as well to set up the first reason is obviously because you can go ahead

16:10:17and export a function directly out of it so what should you write here well let's just go ahead

16:10:24and try to return h1 hello from here right and let's just start our server so we have a server

16:10:32running on port 3000 and if we reload the page we get hello hmm something's not right if we go ahead

16:10:40on our index.ts6 page what we could see is that actually let's just go ahead and rename this as

16:10:47app so that we don't get really don't really get that warnings but we see that we have here

16:10:54on the index page so you know i am index page and not hello if i write that hit save refresh

16:11:03but we still get hello that's strange if i go ahead and write here i am page 1

16:11:11and if i go to slash page 1 we still get hello if i go to 404 which is no page we still get hello

16:11:19so what's happening well if you could guess this app.ts6 is actually responsible for rendering

16:11:26all of your pages right so when you are returning a constant component that is just a single file

16:11:32what's really happening is that you are you are executing none of the pages here

16:11:37so how do we execute pages well next js actually passes two things here the first one is component

16:11:45and next the second one is page props that is the props passed to the component to this component

16:11:52by next js internally right and because this is rendering right now we can just go ahead and do

16:11:59something like this so we're gonna write component right here and i'm gonna just destructure these

16:12:04page props now if we go ahead and take a look you can see that we get the correct 404 page

16:12:11as well as if i go to home page we get i am index page and not hello

16:12:15and everything is just working fine right so basically this is the end point for

16:12:22you know just just just updating the pages in a way you want before they are rendered

16:12:30now this is a little bit different than the actual um you know the actual document.tsx page we have

16:12:39and how is that different i'm going to show you let's just write a very simple console.log

16:12:44statement here which says hello from underscore app right and what i'm going to do is save this

16:12:51and go ahead and refresh the page so when i refresh this you can see that in a node

16:12:57console we got an event that is a console which says hello from app right that means that this

16:13:05code this function was actually executed on the server as well right this is the node process

16:13:13this is executed we see this console that means node somehow executed this right

16:13:19at the same time if i go ahead and take a look in the console on the browser we get hello from

16:13:25app here as well that means this is executed this component this code is actually executed on this

16:13:34on the client as well irrespective of i am page one being on the page itself right so what we are

16:13:42what you're really seeing here is one of the core fundamental concepts of server side rendering that

16:13:48is the content is available as plain html as well as as soon as the javascript of that particular

16:13:55page is ready in our case the javascript which is of the component the hooks and event listeners

16:14:01and everything when they are ready they are automatically attached to your page right so

16:14:07for example if i have something like you know h1 on click alert hello if i have something like this

16:14:16now if i go ahead and refresh this page you can see if i click on this i get a hello alert

16:14:22but if i go to the page source you're going to see i get no such information inside javascript right

16:14:29here right it's just a regular h1 so what happens initially is that i'm displayed i am page one

16:14:35and then when the javascript is downloaded and rendered completely event listeners and

16:14:41everything is attached to it that is why we get an alert now if i disable my javascript

16:14:46and run this i'm still gonna see on page one but there would no there would be no interactivity

16:14:53so what's really happening here is that this code this function is being executed both on the server

16:15:00obviously for server side rendering and on the client as well with document.tsx what's happening

16:15:08is that things really execute just on the server right so if i go ahead and write here

16:15:18hello from document.ts hit save you're gonna see that if i go ahead and reload this

16:15:27we get hello from document.tsx but we get nothing such message from on our console

16:15:34why because you can clearly see that document.tsx although it returns a react component although

16:15:42agreed that it returns a react component but it is actually forming the page structure the overall

16:15:50page structure right so that means it is only rendered on the server to create those html and

16:15:58head and you know those those those custom next year scripts and hooking everything in nicely

16:16:05but it would not execute any javascript which is available inside this page right away right

16:16:11so if you have you know um component mount or anything like that that is not really going

16:16:17to happen because this is not a component this is your actual root document which is being rendered

16:16:25through this component file right so it's sort of a uh i don't know it's sort of a lie as to say

16:16:33that it is a component it is not a component it is your actual document which is being rendered

16:16:38so it won't really make a lot of sense if you have component in mount here and there

16:16:43right here because they are more suited toward pages toward individual pages in our case it

16:16:49could be index.tsx where you can have a use effect which is you know once the page is ready that is

16:16:56once the page is mounted you can just say hello hello right or maybe you can just you know if

16:17:04you go back to index you're gonna get that hello right here or you can just go ahead and you know

16:17:09just override that behavior for all the pages right here so the fundamental difference being

16:17:15between app.tsx and document is that this file is used to create the overall structure and the code

16:17:22in this file is never executed the javascript code on this file is never executed on the client side

16:17:28whatever you know the html string and everything which we get from this file is put as it is

16:17:35on the source code and it is not executed as per say on the client side end so we have some uses

16:17:44for app.tsx which we're going to discover as we move on but that was mostly it for this video

16:17:51and if you like this we have a lot of things coming up so just hold on so that would be

16:17:56all for this video i'm gonna see you pretty soon in the next one hi everyone welcome back

16:18:03to another section this is our styling section for next year so we're gonna learn a bit about

16:18:08how we can use css and sas in this section and ways to implement styling with next js so it's

16:18:15going to be interesting let's just stick along and see whatever we can do with nextgs in this

16:18:21video okay so we are in our index.tsx page which is our main page for next js this one right here

16:18:31right and what we are what we want to do is we want to add some styles and effects and everything

16:18:36to the page so first things first let's just go ahead and actually remove

16:18:41all the styles from our application and i'm gonna for the moment i'm gonna actually let's

16:18:46just go ahead and see i'm gonna actually remove our app.tsx file as well because this one is a

16:18:52special file we're gonna get to that later on and there we go right so we just have let's just go

16:18:59ahead and remove these two pages as well because well they're just trash so here we are now we have

16:19:07just have a single page right here and actually we might need a server restart maybe because of that

16:19:16and let's see if we are ready to go and yes we are so now we have a very

16:19:24basic hello world with us no styles nothing at all if we just take a look at the source code as well

16:19:31we have some javascript and everything but when you're gonna compile it

16:19:34you're gonna see for production you're gonna see that all this javascript is also removed right so

16:19:41what we really want to do is try out the jsx that is styled jsx in nexus which means css njs now

16:19:51personally speaking i don't really like this very much but i'm gonna still explain to you but i

16:19:58won't really recommend as a person who has used react to go ahead and follow this because um we

16:20:04are already mixing the html sort of thing that is you know the jsx part with the logic in our

16:20:11react components the least we can do is keep css separate in a separate files and given that nexus

16:20:17actually has first class support for that as well i'm going to recommend not to do that but anyway

16:20:22let's just go ahead and start so i'm going to say this is a simple div for us and i'm just gonna

16:20:29write a real style jsx tag right here which means that whatever i write inside this now is going to

16:20:38be our css for this particular component right so what i can say is i can just give it a class name

16:20:45of title and i can say title has color of red right hit save and you can see that our title

16:20:54turns red but this is special because if i go ahead and i'm not really sure if i can

16:21:03just show it to you yeah maybe i can so let's just go ahead and create a function

16:21:10um let's say heading right and i just return h1 props dot heading right here and i'm gonna

16:21:22have props right here and instead of this i'm gonna say heading um heading is hitting well

16:21:32a lot of heading right there but what i'm gonna do is just go ahead and move it

16:21:39right there oops i think i lost my uh copy paste because of that but anyway that wasn't

16:21:47a lot of code anyway so h1 color red there we go so what i'm trying to show you here

16:21:54is that this is still the same but if i try to use h1 here now what you're gonna see is that it's

16:22:01black it's not red whereas we specifically told the h1 to be red here right so how does that work

16:22:10well you see whenever you're using these style jsx styles it's going to be component level styles

16:22:18right so nexus is going to make sure that whatever you write inside this is just limited in scope to

16:22:25your component it does not matter if you're using classes or does not matter even if you're using

16:22:31you know direct style elements and how does it do that well you can obviously always go ahead and

16:22:37inspect this bad boy with the chrome inspector and you can see immediately that actually next js is

16:22:46going to add a class to every element inside that particular component and instead of targeting h1

16:22:52directly it's actually targeting h1.jsx and that id of that particular um heading and then it's

16:22:58saying color rate right so what happens with this one well obviously you might have guessed it does

16:23:05not have any class at all so it's just black just regular you can go ahead and make this global by

16:23:12saying global right here and if you do that and if you refresh now you're gonna see that we have um

16:23:20a global h1 as the color right so what just next is what it just did is that now it's not really

16:23:27modifying our styles it's just putting them as it is on the page well this is all about you

16:23:34know style jsx for the most part there could be a bunch of things as well you can for the most part

16:23:40it is used by people who want to have variables with javascript inside css so now you can have

16:23:47um you know just just red so you can say if math dot random is greater than 0.5 then you want red

16:23:55otherwise you want blue and once you do that you know whenever you are refreshing it you're either

16:24:02getting a red heading or a blue heading depending on how the math not random plays out right

16:24:08so that's that's the idea that you can go ahead and use javascript variables inside css

16:24:13but for the most part you never really need to do that at all because css support is in itself very

16:24:18good these days so personally speaking i won't really recommend anyone to use style jsx that is

16:24:26you know um css inside javascript unless you want to use that and you have a legacy code base which

16:24:33uses it but if you are somebody new just go ahead and watch the next videos next few videos on how

16:24:40to actually implement same functionality that is component level um module based resolution but

16:24:46using much better approach much cleaner approach in which you can keep your components separate

16:24:51so that would be all for this video i'm going to see you very soon in the next one so what is

16:24:58going on everybody welcome back and in this video let's just go ahead and take a look at a cleaner

16:25:03much better approach on adding global styles and actually styles in general in this section

16:25:09to our next js application now for doing that we need to create at least for the global file

16:25:15global styles we need to create a file called as underscoreapp.tsx we discussed that in the

16:25:21previous sections so it should not be a problem so this application this app.tsx is a very simple

16:25:27um you know non-customized app at the moment but what we really want to do is just import our

16:25:35global dot css right here now the naming convention is again a little bit important here

16:25:42first things first it is not necessary you name it global.css you can name it main.css as well it's

16:25:49just going to work just fine right so you can see that we have a dot red class which gives a

16:25:54color of red and inside our index page we have a class name red assigned to a heading and we have

16:25:59a heading right here so if we go ahead and restart the server just restart the page and just refresh

16:26:05the page we're gonna see that we get our heading in red and that is because of the red class which

16:26:12we have inside our main.css file right so this is how the global styles are going to be applied

16:26:19now you might ask me that what would happen if you just go ahead and you know just just throw it

16:26:24right here shouldn't that really work not really because the way how next js guys came up with

16:26:31you're gonna get this error it would say that global css cannot be imported from other files

16:26:36other than your custom app so what's happening is that next.js is considering this import as a

16:26:43global import it is it is considering that hey if you want to import this as it is that means

16:26:49you want to apply the styles everywhere and it does not really let you do that because you know

16:26:55components styles can overlap with each other if you have overlapping classes

16:27:00so it throws you an error and you cannot just view your application so with that being out

16:27:06that means that you know just importing css like this importing main.css or style.cssl

16:27:12you know anything like that dot css it's just possible in dot underscore app.dsx but hang on

16:27:18we're gonna see another way in the next video but for this video what we have right here is that

16:27:26you can go ahead and make use of the global styles using a css import inside underscoreapp.tsx

16:27:35only it would not work in a page it would not work in any other file if it is not underscore

16:27:41dsx so this is how you're gonna make use of you know global styles and you can just go ahead and

16:27:46play around with anything you like here it would be available as a global style so that would be

16:27:51all for this video i'm gonna see you pretty soon in the next one hey everyone welcome back and in

16:27:57this video let's just go ahead and explore how you can import component styles um in your pages by

16:28:04that what i mean is that whatever styles we import are available only to your component so the first

16:28:11thing first um we have seen that you know main.css does not really work very nicely because we get

16:28:18this error so what's happening is that nextgs has actually created a way to import the files the

16:28:25css files inside your typescript or javascript components and that is only when your file name

16:28:32ends with dot module dot css so you have to make sure that you name your file as main.module.css if

16:28:43you want your file to be available only to a particular component the your global file

16:28:49would still remain um you know just just the main.css or global.css or whatever you want

16:28:55but anything which you import in your component in your page should be like this it should be

16:29:02whatever the name for example in our case it would be index which i'm just going to create

16:29:07index.module.css right so that's what we are doing now so i'm going to say red again just

16:29:16give it a more specificity just a little bit of css weight and i'm gonna make this color

16:29:23green right hit save and if i go ahead and just do that what's going to happen is that if i go ahead

16:29:34and refresh what we're gonna see is we don't really get anything because because by default

16:29:42you have to import it as like this now you can go ahead and make use of styles dot red

16:29:51like that right so now if you go ahead and see you're gonna see that you actually get

16:29:56the green color and you can see that it has actually bound your style to a specific class

16:30:03so how you have to use this is by using um class name and then writing styles which is

16:30:10what you imported from the css file and then the name of the class which you're using right

16:30:15in our case it is dot red there's a way to make it work like this and like this as well

16:30:25but it is not available natively inside next js as of now so if you want to do something like that

16:30:33you have to write custom configuration inside next.config.js and we have some videos at the

16:30:40end which are like covering the advanced aspect of nexus which go over that aspect so if you're

16:30:48somebody who's migrating this is especially useful for somebody who's migrating existing code base

16:30:53to have this feature you know just having an import style which should be local to your module

16:30:59to your component and this should work right away so this involves the use of a babel plugin but

16:31:04yeah that is possible but is available at the end of the section end of this whole course basically

16:31:12so yeah i mean for the most part this is how you're gonna make sure you work with

16:31:19um the css modules the css components in nexus just import them like that and you're good to go

16:31:26so that would be all for this video i'm gonna see you pretty soon in the next one so what is going

16:31:34on everybody welcome back and in this video let's just take a look at how we can use sas inside next

16:31:40chase and sas is basically for those of you who don't really know it's sort of uh you know just

16:31:47like how typescript is for javascript sas also adds a lot of power to css and compiles down to

16:31:53css only so next year supports sas natively you just have to go ahead and you know just rename

16:32:02we're not going to rename the global file we just can rename the component one and what i'm going

16:32:07to do is import it just like this and that's it that's all we need really need to do i guess if

16:32:14we could just refresh restart the server once that would be awesome and if we go ahead and refresh it

16:32:22we are probably gonna see i think we have yeah i guess we need to install sas first

16:32:29that's that's the only thing we need to do because next year's won't really ship with sas

16:32:35and i'm just gonna save it as a development binary also because we don't really need sas

16:32:40on production anyway so once we have that i can run dev again and we should be up and running in

16:32:48no time so if you go ahead and refresh it now you can see that we get still the same behavior but

16:32:54now with the scss that is a sas file the benefit of this well to start with you can now nest

16:33:01the styles so i can say this is color red and if i go ahead and write a span here and i say i am red

16:33:12and c so we can get red here and heading like that and it just nicely compiles down to our css

16:33:20but it is much more maintainable when you're using sas while you get support for everything now the

16:33:26sas variables um you know if you want to create some sort of duplicate styles over and over so

16:33:33you can write a function in sas you can loop over stuff so all that stuff but for the most

16:33:38part you're just gonna make use of the nesting a lot so that is that is what it is sas ships out of

16:33:45the box as well sas support shifts out of the box as well with next js you just need to install the

16:33:50sas package and you are done so that's that's pretty much it for adding the sas support to

16:33:57our applications as far as i'm concerned because next js other than that inside of the css moduling

16:34:04system follows the same thing as inside the sas moduling system follows the same thing as css1

16:34:10that is you need to make use of you need to end your css files with dot.module.scss and so on and

16:34:17so forth so that would be all for this video i'm gonna see you pretty soon in the next one

16:34:24hey everyone welcome back and in this video i just want to take a little bit of time to just

16:34:29tell you how you can organize your pages in next chase so that you don't have a lot of clutter here

16:34:37so how you should technically create things is that inside pages just create a new folder

16:34:43actually inside pages create a new folder with whatever page you have for example this is my

16:34:48page one right and now inside this page one create an index.tsx file when you do that what's going

16:34:56to happen is that your page contents are still accessible on your domain.com page one but now

16:35:05all the contents all the relevant contents in our case it would be just tsx file and the styles file

16:35:10would be available inside this page one only so we can have a style start

16:35:15module.scss right here and i can just go ahead and say that you know red is a color red right and now

16:35:26i can go ahead and just say export default function page one is uh you know return h1

16:35:36class name oops and then style start red and let's just go ahead and import the styles from our

16:35:48styles.module.scss file right so this is all we need and now we have a nice little page with us

16:35:57which has the the view and the logic and the styles part separated so if you go ahead and

16:36:03view page one right here what you're gonna see is that nothing happens because we have no content

16:36:10there but once i write hello there we get hello in red so that was just a quick little you know

16:36:15instruction on how you can organize things i prefer folders and actually folders would be

16:36:20very helpful as well when you're creating dynamic routes and stuff so just keep that practice with

16:36:25you when you're starting off so that would be all for this video i'm gonna see you pretty soon

16:36:30in the next one so what is going on everybody welcome back and in this section we are going

16:36:37we're going to be exploring the api section of nextgs learn about what that is how you can work

16:36:43with that why is that useful and maybe just create a little bit of small application around that as

16:36:50well so pretty excited to start this section and yeah let's just do it i'm gonna see you

16:36:57super quick in the next video all right so when we started the project you must have observed that

16:37:04we have a api folder as well inside pages which looks something like this now what does that mean

16:37:11why is it different let's just discuss that in this video so this api folder is special in the

16:37:19sense that the files you create the typescript or javascript files you create in this folder

16:37:26should not return should not export a react component what do i mean by that

16:37:33let's say let's see so if i have of let's say a file name that's randomnumber.ts right

16:37:40what i have to do is just export default function and here it should not be a react component

16:37:52because for react components we have pages right but for the files inside api folder this is

16:38:01basically a rest api endpoint which you can use to return um responses like json response for example

16:38:10so what i'm gonna do is i'm gonna get two parameters right here the first one is going

16:38:16to be next api request type and the second one is going to be next api response type

16:38:25response right so we can get those types from our next package and if you're familiar with

16:38:33express you know what this request and response are next js sort of also follows

16:38:38a similar pattern but the thing is you have to export a single function from a single file and

16:38:44this this end point right here is automatically available on you know for us at least it is http

16:38:51localhost 3000 slash api slash random number right so this is for us if you're running on a

16:39:00different port that's a different story for you so if i go ahead and save this file you're gonna see

16:39:05nothing really happens because i think we don't have the server running

16:39:09so that's my bad but anyway if we refresh this you're gonna see that it keeps on loading

16:39:15now the reason it keeps on loading is because we are not really returning any response at all

16:39:20from this function right so let's just do us do this page a favor and say rest.json

16:39:27which is going to return a json response i'm just going to say you know status okay

16:39:33and if we take a look now refresh this you can see we get a nice little status okay response from us

16:39:40this is something which we cannot do with pages right if you try to you know there's just not

16:39:46any rest or request or rest here we cannot really do restart rest.json even if you try

16:39:54to do that i'm just showing you that this won't work because inside pages

16:40:01the next.js actually you know expects you to return a component not just any api call so

16:40:08this won't work inside pages but this would work brilliantly when you are inside the api folder

16:40:14so when you say rest or json again this would look familiar to express guys

16:40:19it could return a json response to you automatically by just taking care of the content

16:40:25type and the status score status scores would be 200 in this case so this should not be a problem

16:40:32so once we have that in place um i think this is a pretty solid intro to the api and uh what

16:40:43we can do is just go ahead and instead of status okay i can say number is math dot random times 10

16:40:53and this would give us a number between um zero to nine if i just flow it down that is right

16:41:02so now whenever i refresh you're gonna see that we get a random number every time um one three five

16:41:10eight stuff like that so this is a random api which is just returning us a random number inside

16:41:16of a json response and yeah that's that's how you're going to create a very simple api with next

16:41:22js so it could have a lot of uses for example if you're using jwt authentication in xjs you can use

16:41:29an api endpoint you can deploy these individual functions as lambda functions as well so they

16:41:34can upscale and down scale independently right so this is also one important benefit we can have you

16:41:42can use the lambda functions for oauth login as well for example sign in with google sign in with

16:41:48facebook apple stuff like that so there are a lot of good use cases uh i use these um on code dam

16:41:57as well um for the oath login especially so yeah that's all for this video i'm gonna see you pretty

16:42:05soon in the next one we are we are gonna be using this in a much more sort of organized way in some

16:42:12sort of application so that's all for here and i'm gonna see you pretty soon in the next video

16:42:20hey everyone welcome back and in this video let's just go ahead and explore the request and response

16:42:26objects a little bit more because i don't think we have done um enough research on them

16:42:31yet so because we are using typescript we can get all the benefits of autocomplete right at

16:42:36our disposal so if i try to write request dot you're going to see we have a bunch of

16:42:43methods and properties enabled for us but some of the interesting properties let's

16:42:48just go over through them so the first thing is request.body obviously because

16:42:53you know if you are trying to let's just say if i console.log request.body right here and let's say

16:43:00request body is something like this so if you open this and if we go ahead and if i try to copy this

16:43:09api and let me just go ahead and fetch this real quick with a method of post and body

16:43:17of you know hello something like that right and hit enter so you can see right here i received

16:43:25on my node end the request body hello now this is actually beneficial in the case that i'm sending

16:43:33json data as the body so we'll have more tutorials on that in terms of authentication and everything

16:43:39but i'm just giving you an idea here stringify and i have you know something as

16:43:46username is admin and password is admin right and if i just do one more thing that is just

16:43:59just setting up the headers as well so that oops so that we have the content type

16:44:09content type as application json because that's what we want to receive at the back end

16:44:16and hit enter what you're going to see is that at the back end instead of getting a string which is

16:44:22what we are sending inside the body we actually get a parsed down object from the actual request

16:44:30request.body so i can literally just go ahead and say requestedbody.username and if i perform the

16:44:36same request one more time it's going to give me admin just like that which was the username

16:44:43so this is the request.body we have a little bit of other things as well so you have let's see

16:44:51request dot cookies which might be important when we are dealing with cookies so we'll we'll just

16:44:57take a look at that request.headers is also interesting if you are trying to get custom

16:45:02headers out of a particular request then let's see what we have request.query is also interesting

16:45:11so if we have just like there and if i try to do q is equal to one here what we're going to see is

16:45:17in our request query this should be query obviously so our query is q equal to one and

16:45:23it is automatically parsed as an object for you so you don't have to really parse it yourself right

16:45:29then there are um for the most part this is what you're gonna use requested url is something you

16:45:34can use as well but for the most part that's not that's all you're gonna make use of right so this

16:45:40is how the request object looks like let's just take a look at response object now real quick so

16:45:46response we obviously have seen the json part with this thing so it allows you to send json responses

16:45:52but we have a lot of interesting things apart from that as well let's start that so we have let's see

16:46:03we have json obviously we have rest.send in case you want to send um you know any other data which

16:46:15is not json right so if you want to send something like this instead of you know just json response

16:46:23you can use this so rest.send is going to take care of that again it's an abstraction over all

16:46:30the real methods which we have but for the most part it just works so we get three or four because

16:46:36we have already loaded this page once but you know it's going to take care of all the things

16:46:42then let's just keep on moving um we have rest.header which is also also interesting so we

16:46:50can have you know x custom header and i don't know we are open to hire people something like that

16:47:00just to add a little bit of interest to your application and for the most part we can just

16:47:05use this refresh and if you take a look inside your response headers now you can see that you

16:47:10have a custom header now we are open to hire people right pretty cool you can also use the

16:47:16set header to actually set cookie so set cookie could also be something like that and we can say

16:47:23are you programmer equal to true right and if i go ahead and refresh this now you can see

16:47:31that it sets a cookie and now if i go ahead and take a look at document.cookie

16:47:37we actually get audio programmer as true as a cookie which is set by the inside the browser

16:47:44useful for authentication again all right let's just keep on moving let's see what else we got so

16:47:53we have obviously the status code with us so if you want to set status code at 404 and

16:48:00response you can do that so you can see inside networks now we get a 404 as the status code of

16:48:07our document you can basically do any status code you like obviously just make sure you are playing

16:48:12inside the rest status code so you can do 4013 i don't know if you can do some ridiculous status

16:48:19quotes yeah apparently you can but don't really go ahead and try those can we do one three three

16:48:26seven no not really well you can do uh i'm a teapot i don't remember its status code it

16:48:34was somewhere around 104 or something yeah no not really anyway i don't really want to blow this up

16:48:42so i'm just going to keep it a status code 200 which is 200 okay everyone knows that right so

16:48:48this is again one interesting property which you can set let's see what else is interesting here um

16:49:00there's also a method which i remember which is rest.end right so rest.n can be used to just

16:49:07you know it's pretty much like just just status rest. but rest end is more explicit that you are

16:49:14actually closing the response stream now hello how are you so if you do that and if you try

16:49:21to send more content down the line what's going to happen is that you're going to get an error

16:49:26from the server that cannot send set well you get this error but the actual idea is that you

16:49:31cannot really send any headers or body because the response stream has been ended so anyway

16:49:37that's pretty much it for how we're going to interact a little bit with the rest

16:49:42and request and response there's a lot more we can do when we introduce middlewares and cookies and

16:49:48stuff like that which would be very useful in authentication and stuff but for the most part

16:49:54this is how you can get started with the api's endpoint so that's all for this video i'm gonna

16:50:00see you pretty soon in the next one hey everyone welcome to a brand new section in next year's this

16:50:08is going to be a routing section in which we'll be seeing simple routing and complicated routing as

16:50:14well eventually as we go through and some of the new changes which nexus brings in to the framework

16:50:20so starting off this video would be on simple routing you can already see that i'm on localhost

16:50:25port 3000 and if i switch to my text editor you're going to see that we do not have a lot

16:50:30of files just the index.tsx and the underscore app dsx file so this is how it looks like as of now

16:50:39let's just go ahead and remove a bunch of these things except for let's say a single

16:50:46link right so i'm going to go ahead and remove all of this and i'm going to remove the footer as well

16:50:53and i'm just going to go ahead and change this indentation to tabs because that's what i use

16:51:01so here we are now we just have a single link with our on our website and that is also using you

16:51:08know just regular ah drift tags so first things first inside simple routing understand two things

16:51:16the first thing is that inside this pages folder right when you create any file that is

16:51:23a typescript or a javascript now if you're working in a typescript project that would end with a dot

16:51:28tsx or with a dot ts if it ends with dot tsx or dot ds and if it is a you know valid javascript

16:51:37file which is exporting a functional component next.js would automatically make it a page

16:51:43by that what i mean is that you can literally go ahead and write here mayhold.tsx and just export

16:51:50default a function which should be a react component should be a react component p-o-n-e-n-t

16:52:02i'm pretty sure i spelled it wrong but anyway anyway let's just proceed so by what i mean

16:52:08that it should be a react component that means that it should return some jsx expression right

16:52:15not really expression but a jsx element so as to speak it could be just like you know hello or as

16:52:22simple as just a string as well but it should not be returned undefined right it could be

16:52:29return null because null is a valid jsx element but it should not be returned undefined so as

16:52:35long as the default import in a file which is a valid typescript or javascript file depending

16:52:41on your project setup is returning a valid react component that is is returning a valid jsx element

16:52:49you have a page for yourself now once you have mayhew.tsx what you're going to see is that

16:52:55now if you go ahead and visit localhost 3000 slash mayhood it's going to say hello right so

16:53:04i can just say hello from mahul right so that we are clear that we are on mehul so you can see that

16:53:10it dynamically automatically generated it right it won't be mehul.tsx it would mean nothing like that

16:53:16on any other page you're going to get a 404 it would be just mehul without any extension anything

16:53:22at all so this is how simple routing in uh inside of this next js works that is you just go ahead

16:53:30create a file export a function which returns a react component and that's it you're done now

16:53:36you can go ahead and visit the slash whatever it is and it will automatically be there next year's

16:53:42actually borrowed this concept from php so if you have been a php developer back in the days you

16:53:48know that php works just like this you just create a file and you can directly go ahead and visit

16:53:53that file and it will be just you know the output would be served just out of the box so this is

16:53:59how nextgs works but anyway nonetheless routing is more complicated in than in php which has you know

16:54:08brings its own benefits so we're gonna take a look at that in the next video so that's all

16:54:13for this one i'm gonna see you in the next one hey everyone welcome back and in this video let's just

16:54:19take a look at the link component which you're going to be using all the time on your website

16:54:24why that is important and how it works so we have just like you see we have an index page

16:54:30and we have a mayhew page right so you can see that if i go to localhost 3000 we're going to get

16:54:35something like this and if i go to close 3000mah we get this content so far so good now obviously

16:54:43in every case you're going to need some links on your website so that people can navigate around

16:54:48right on different pages now one option is to have these ahrefs links like this but the

16:54:54disadvantage to this and let me just go ahead and show you if i have a link something like you know

16:55:01mayhew because that is that is where our page is located right so if i go to welcome to my blog if

16:55:08i do something like this go back and if i try to click on this pay close attention to what happens

16:55:13here you're gonna see that the page actually reloads right so you see that we have actually

16:55:19created a conventional website which is reloading when i click on a link right so it's fetching the

16:55:26document again from the server you know all that regular thing is happening but we can make use of

16:55:32the dynamic nature of react that is we can make use of the functionality that we do not have to

16:55:39fetch the whole html of the page by that what i mean is that internal routing could make sure

16:55:45that the experience of the user is very smooth between the pages in terms of page transitions so

16:55:51there's not a jump but in fact a smooth change of page which is which pretty much feels like native

16:55:57application so how do we do that well we cannot really do that with the regular anchor tag because

16:56:03nexus does not know about this any much but what we can make use of is something known as the link

16:56:09tag from next link right so you have to import it from next link and it's a default import

16:56:17as of now so what you've got what you have to do pretty much is just go ahead and wrap this

16:56:25tag inside a link and give it an hrif of same as you have in the a tag and remove the href from

16:56:34the attack now why do you remove this because next year's would automatically pass down this href to

16:56:40this anchor attack and that is it you do not have to pass any other tag and we're going to discuss

16:56:47this again in the in the complicated routing and that is like the nested routing but and the

16:56:53dynamic routing but earlier you also had to pass in something known as as which was your real link

16:57:00but with nexus 9.5.3 onwards you don't even have to do that the href would work just fine without

16:57:07any changes at all so now if we take a look at the the blog again the website again just pay

16:57:13close attention to the state of the page so if i click on this you can see it instantaneously

16:57:19loads and it is not reloaded right so you can see if i go back with my browser window browser button

16:57:27i can just click and you know go back click go back click go back it's instantaneous it's fast

16:57:33right and that is made possible with all the optimizations next year springs in like

16:57:37you know preloading and stuff so we can cover preloading a little bit but yeah i would really

16:57:43want to have that in a separate video anyway so yeah that was a quick little introduction to link

16:57:49and how you can do simple routing with it we're gonna make use of link again in complicated

16:57:54routing but that's all for this video i'm gonna see you in the next one hey everyone welcome back

16:58:00and in this video let's just go ahead and build a very very simple jwt based authentication

16:58:07inside next.js so first things first what i'm going to do is i'm going to go ahead

16:58:13and actually install i'm going to say npm install json web token right so because this is a this is

16:58:21a package which would enable us to actually do a lot of fun stuff with json web tokens

16:58:27so i'm gonna install the types for this as well as far as i remember they are available

16:58:34so let's just go ahead and do that because that would enrich our experience of working with the

16:58:39package and yep so here we are i'm just going to minimize this what i want to do is on let's

16:58:46get rid of the page one for now i'm gonna go ahead remove this and i'm gonna create a

16:58:53very very simple form back back in 80s like that input type text value admin let's just keep that

16:59:04and password has value admin as well right just give it a little br because i'm too lazy for

16:59:12um actual css and input type summit value login right we can give it a form method post

16:59:25and let's see i'm gonna say action is slash api slash login right so once we do that

16:59:36what we're gonna see is actually let me just get rid of these as well

16:59:41once we do that and go to our home page we get a nice little form with us which

16:59:47is absolutely destroyed by my password manager so

16:59:52let's just leave that but what's going to happen is if i go ahead and rename this to login.ts

16:59:58and if i go ahead and just do a console.log of request.body so as to see what we are

17:00:05getting let's just refresh this hit login and in the console we see we get nothing because i think

17:00:14i did not really save it let's just refresh this one more time and we still did not see

17:00:20anything but we were submitting i think have we are not really submitting anything as well

17:00:26so to do that we have to actually give the name as username and password right and now one more time

17:00:37if we try to login what we are going to see is username as admin and password as admin which

17:00:44is perfect right so what we really want to do is we want to extract out username and password

17:00:53from our request.body right first of all i'm just going to say if request.body

17:00:59is not available then i'm just going to say rest dot status code is 404 and rest dot end error

17:01:10rate and return because we don't want any further processing otherwise we are you know inside this

17:01:18then what i want to do is i just want to say that our token in this case is going to be jwt

17:01:28that is the package which we are going to import now so import jwt from json web token

17:01:35jwt dot sign and i'm going to say user name is whatever it is and i'm going to say it is admin

17:01:42or not on the basis of username is in fact equal to admin and password is in fact equal to admin

17:01:52right we're just gonna just set the admit field to true if that is a a fulfilled criteria

17:02:00otherwise not and for the key i'm just gonna go ahead and just you know be lazy about it

17:02:09and just write just smash my head on the keyboard so this way we are just creating

17:02:13a signed json token which we are returning using an api and yup if i refresh this you

17:02:22can see we get a nice little token for us which is which is a json web token and if i go ahead

17:02:28and copy this whole bad boy and go to jwt.io which can be used for decoding json web tokens

17:02:35which is basically a base64 only but you know it's still convenient so if i go ahead and paste

17:02:40it here you can see that this is the data which we have and in fact this is an admin because username

17:02:47and password were both admin but if we go ahead and try to log in with something else oops oh

17:02:58i think we made sure that this is always admin so this should be actually default value not value

17:03:06add main one two three and log in and then if we go ahead and take a look at this

17:03:14what we're going to see is that this is admin false right and we cannot really change it on

17:03:20the client side because jwt tokens are secure so first things first let's just

17:03:28move from 1980s to 2020 so i'm going to say that on click let's just make this a button first of

17:03:36all on click i'm going to say summit form and what this summit form is is that it's going to perform

17:03:44a request to our backend server so i'm going to say my response from the api is fetch api

17:03:52and what do we have login right i'm gonna say method is post our body is json.stringify

17:04:01username password and again because we are in 2020 now let's make use of the react

17:04:09state with us right so i'm going to say a similar thing for password set password

17:04:17and let's just import this bad boy and finally we can switch back to value one more time this

17:04:26is username and this says password nice and easy right one last thing which you want to do is say

17:04:34on change the event should set user name to e.target.value and a similar thing should happen

17:04:46for password as well that is set password awesome so now once we have the response from the server

17:04:55we want to convert it into json response because our server is also responding us inside json and

17:05:03then we can finally take out the token by saying rest.token because that is essentially what we

17:05:09get back from the server but an object which has a key which is the token for us right so i can just

17:05:16go ahead and say that if we have in fact a token what we what we can do is we can just go ahead and

17:05:26update the message message set message is used for you state a string which is uh empty message

17:05:36you are not logged in and i can just go ahead and say we have a message in terms of h1 at the top

17:05:47right and once we have set message with us what i can do is i can

17:05:54first of all go ahead and import jwt from json web token again because we can use a single package on

17:06:02server and client as well why shouldn't we so i'm going to say my json is json jwt dot decode

17:06:13my token right and i'm going to say json i'm going to just say welcome to json.username

17:06:23and ur and i'm going to just say json dot um let's see i think we need to wait for this oh not really

17:06:35this is synchronous as well but we can just uh you know return it as a combination of object

17:06:45whose key is string and the value is also string so yeah actually let me just go ahead and remove

17:06:50this welcome json.username and you are and we're just gonna check json.admin is true an admin

17:07:03otherwise not an admin that's it right else set message something went wrong whatever all

17:07:16right so once we have that in place let's just go ahead and take a look at our homepage now

17:07:23so we are we have a message you are not logged in let's just try admin admin as the combination

17:07:28we get welcome undefined and you are not an admin fair enough so lets us first of all console.log

17:07:37our json what we are getting and let's just move to console lists oops

17:07:45console click on login and we get admin as false and that is the case i think

17:07:55yeah that is because we are not really setting the headers um to content type

17:08:03application json right here because we are transmitting json data right so we need to

17:08:08make sure the backend knows that now if i click on login yeah that's the right response now so

17:08:14we see welcome admin and you are an admin right however if i try to do something like username

17:08:21something login we get welcome username something and you are not an admin similarly if i have admin

17:08:29here but the password is incorrect we have welcome admin and you are not an admin but once we do

17:08:35admin admin we are an admin right so again very simple dumb example of jwt tokens with next.js

17:08:44api um just showing you a simple use case of that because you know you cannot really fake the

17:08:52integrity of jwt tokens unless you don't really have the key from the server and because

17:08:56the key is on the server you cannot change response now on the basis of this what you can do

17:09:03is for example you can have a secret dot ts key and what we can just do is say export default

17:09:09function right here i can say const token from request.body request is next api request

17:09:20request and responses next api response

17:09:27right and i can say you know just take out the admin field out of jwt dot verify

17:09:36import jwt from json web token i can say token and key right and we can just for the time being

17:09:47being lazy we can just import it like that and i can just say as an object which is having

17:09:58gas keys and string gas values right so i can just say or rather

17:10:04boolean as the value right in our case so i'm just gonna say if admin is true rest.json

17:10:13secret admin code 12345 right else rest.json admin false

17:10:25so once we have that in place what we can do is we can go ahead and on the client

17:10:31we can just implement um a secret like um the following so again we can have a secret message

17:10:43set secret and we can just make sure this is empty at the moment and finally what we can do

17:10:50is if we have a token obviously we can say await

17:11:00again this whole thing actually so i'm just going to copy this

17:11:05but this time this should be secret we have a application json and now we are just passing in

17:11:10the token for the further request so this would be our token because we already have access

17:11:16to the token and then i can say if rest dot secret is available to us secret admin code actually

17:11:27i can just say set secret as rest dot secret admin code

17:11:35else said secret nothing available

17:11:40right and i can just say secret as secret

17:11:47all right so now if i go ahead and try to log in with admin admin hit login you're going to

17:11:52see we get welcome admin and you are an admin and i guess secret one two three four five but if i

17:11:57make a mistake you're gonna see that we do not have anything available as a secret so you can

17:12:04basically just go ahead and store this json token json web token and use it for further requests

17:12:09um you know a very popular approach for authentication stuff like that

17:12:13so yeah i mean that's that's pretty much it for this quick little demonstration

17:12:17hopefully this would be useful this is not really a nexus project we have next year's projects later

17:12:23on down the line if you are watching this course on code dam where we'll create e-commerce and you

17:12:27know all those blogs and fun stuff but yeah this is just a quick dirty implementation of something

17:12:33with next js and next year's api routes so that you get a idea about how things are working

17:12:40and of course you might have seen that you know most of the thing is

17:12:43react only even with year's plus the only added advantage uh the actual good advantage is that

17:12:50you know you get all these all this html right off the box from next year's framework so yeah

17:12:57that's pretty much it for this video i'm gonna see you pretty soon in the next one

17:13:04hey everyone welcome back and in this video let's just take a look at nested routing which means

17:13:09that not only you can just send people on slash mehul but you can also send people on slash mayhew

17:13:16activities activities right so how do you do that well you see that um the basic instinct would be

17:13:27that if meihul.tsx gets us to mahul then you know maybe mayhew activities.tsx would get us there

17:13:35well it's partly right but the thing is instead of having a slash in the file name

17:13:40what we're going to do is we're going to create a folder named mehul

17:13:44right and i'm going to move this mayhold.tsx file inside this major so now what's happening

17:13:51is that whenever i access slash mahul we would be inside this folder right and any file

17:13:58that is present inside this folder would act something like you know as the

17:14:02just like which is acting inside this pages folder by that what i mean is can you guess what's going

17:14:08to happen or maybe can you guess how i can access this major file on the browser well yeah i mean

17:14:15to access this first of all i have to get inside the folder which is you know this mayhew folder

17:14:20and then because this file itself is named mehul what i have to do is write mahul one more time

17:14:26now when i do that then i can only get access to you know this thing so i'm basically doing

17:14:33localhost 3000 slash mail slash mail to get to this particular file now how do i get it on just

17:14:41but with you know as the folder structure well i can just go ahead and rename that to index right

17:14:47and now if i go ahead and take a look and just go to slash mehul that is what you're gonna get

17:14:54a default file just like earlier but inside a folder this time now what advantage does it

17:14:59give us over a single file the advantage now we have is that we can have nested routes right so

17:15:05now i can create activities.tsx i can just borrow this from here and i can say my whole activities

17:15:13and what i can go ahead and do is say that you know we have this as activities

17:15:21and i can go back on the home page and click on this and you can see that we are now inside the

17:15:28activities page right directly inside activities page which is you know just sitting with our index

17:15:34page as well so that's how nested routes would work and basically you can nest it to any depth

17:15:40which you want but for the most part you're not going to need more than maybe four or five levels

17:15:46of depth that's that's the max you're gonna go for a medium to large size projects as well

17:15:52so yeah that's how nested routing would work there's also something known as dynamic

17:15:56routing which we're gonna cover next because dynamic routing is more fun than nested routing

17:16:02because you get access to a number of routes without actually caring about them

17:16:07so that's all for this video i'm gonna see you pretty soon in the next one hey everyone welcome

17:16:12back and in this video we're gonna take a look at how we can create dynamic routes in next chase and

17:16:18how we can just go ahead and work with that so we have seen how to work with nested routes but what

17:16:25if you want to have a dynamic route for example let's say you have a blog on built on next year's

17:16:31which we're going to create later on so there's a dedicated section where we create an actual blog

17:16:36built with nexus so in cases like those you don't really know um the later on slug for the blog

17:16:44post right it could be anything so how do you deal with that well for that you have dynamic routes so

17:16:50let's just go ahead and let's just say i go ahead and delete this and i create a page called fruit

17:16:59right and right here what i want to do is in fact let me just go ahead and delete this as a folder

17:17:06or yeah let's just keep that so anyway because we'll need that will make things a little bit

17:17:11more clear so we have a fruit folder and now what i want is anyone who visits something like

17:17:18you know localhost 3000 whatever then fruit then apple then this apple should be displayed on the

17:17:25screen or maybe we just want to do something with this apple but i don't really want to

17:17:29hard code all the fruits with all the files because that would be waste of resources right

17:17:35so to deal with that what we have to do is we have to create a special file in next chase which

17:17:41starts with a bracket with a square bracket to be more precise right and ends with a square bracket

17:17:47so here i'm gonna write something like name dot dsx and this could be anything in between the

17:17:52brackets right it does not really matter what matters is that you create this file with the

17:17:58opening square bracket and a closing square bracket that is very very important and this

17:18:04should be just you know before the dot tsx you don't have to you know enclose the whole file name

17:18:09in square brackets just the uh the part of the file before the extension in square brackets so

17:18:16once you have that in place let's go ahead and you know just go ahead and export a regular component

17:18:24nothing fancy here i'm just going to say h1 hello right but what's interesting

17:18:30about this is once you have this in place what this means literally is that go ahead

17:18:38on fruit that is fruit and capture anything else you write and send it to this particular file

17:18:45right by that what i mean is that for example this url which you're seeing right now and this url you

17:18:53know which is anything random are going to point at this particular file only next yes is going to

17:19:01use the logic from this file for serving both of these routes and in reality all of the routes

17:19:07like this what nextgs would not serve however is just the fruit route right so if you just go to

17:19:15the fruit route it's going to send in a 404 so if you want to make it serve that route as well you

17:19:20can just go ahead and create index.tsx file or you can maybe just try to catch all the routes

17:19:26which you're going to see in the next video but

17:19:30yeah for this video what we have in place is you you have a dynamic section of uh

17:19:36routing in place and mind you that this would work works this would also works but this right here

17:19:47abc section 1 and abc would not work why is that because you see now you have actually you have

17:19:56two segments not one and you're just listening for the one segment with the square brackets

17:20:01right so if you go ahead and take a look at abc and one two three here you're gonna see we get

17:20:07a 404 we get a 404 on this page again this is because two segments of url and would not work

17:20:18right so how would you make um you know how would you catch this thing well what you can

17:20:24do is instead of creating this as a file let me just go ahead and or maybe just keep it right

17:20:29like that let me just go ahead and create a folder which is name now now again just

17:20:35like i said this could be anything and inside this i create another thing which is

17:20:42something like sub name now what's going to happen is now we're going to start catching these guys

17:20:48right because now we have a dynamic segment we have first of all we have fruit then we have a

17:20:55part of dynamic segment then we have another part of dynamic segment which we can now catch so if i

17:21:00go ahead and refresh it now you're going to see we are able to catch it now but what this would have

17:21:04resulted in is that we would have lost the ability to catch the first dynamic segment now so anything

17:21:10on the first dynamic segment stops working so how do you make that work as well well all you

17:21:17have to do is just create an index.tsx file here because remember when you're accessing just this

17:21:24name segment what next is looking for is basically the index.dsx file either a name.tsx file which is

17:21:32not really there because now we have a folder or this index.tsx file which we looked in the

17:21:38last video as well how the routing really worked so once we have this index.tsx file you can see

17:21:45when i go to fruit name that's it just the namepad that is the first dynamic segment

17:21:50it's going to fall back to the index.dsx file so now if i go ahead and you know hello from

17:21:56first segment and if i go ahead and pick this first url

17:22:03hit it you're gonna see we get hello from first segment however if i pick this url with two

17:22:08segments we're gonna get just hello which is the message from our sub name component right

17:22:16now what's the essence of this name and sub name and why do we have named it like that

17:22:23well it does not really matter but the essence for the names is that you can use these properties

17:22:30you can use these names to extract out the route you are accessing that is these values

17:22:36jd sfh whatever that is section 1 abc so you can have name as section 1 in your code and sub name

17:22:44as abc in your code right we're going to take a look at how we can do that with the use router

17:22:49hook but that's that's the essence of the name that's why i wanted to tell you that

17:22:55so yeah i mean that's pretty much it for the dynamic part that's um as much you're going to

17:23:00need for the most part this is what you're gonna need for dynamic things right because

17:23:05you won't be going a lot beyond this unless you have very special use cases this covers

17:23:10almost everything you're gonna need with next js routing so that's all for this video i'm gonna

17:23:16see you pretty soon in the next one hey everyone welcome back and in this video let's just take a

17:23:22look at the used router hook which i was talking about in the last one and this hook is basically

17:23:30you can think of something which you can use to programmatically control

17:23:34navigation and access these parameters stuff like that in nexus right so what you have to do

17:23:42is just go ahead and write const router is use router oops not use reducer but use router

17:23:48and i have no idea why the hell autocomplete doesn't work for next js modules but that's

17:23:56uh all we have and this is you're gonna import it like this right so once you have the router with

17:24:02you what's going to happen is that this router contains a bunch of useful things right so if you

17:24:09just go ahead and console log this router object right here what you're gonna see is that if i go

17:24:14to we are on the sub name right so if i go to the console now what's going to happen is that we get

17:24:21this object twice because you know it might have rendered twice that's why we have two console lock

17:24:26statements but that does not really matter a lot so you see that this is this is what this router

17:24:32object contains so it contains aspart which is our real path of the location we have the back

17:24:38which is which could be used to programmatically send the user back in history we also have base

17:24:44path you know some common things um we also have components which is not you know something which

17:24:50you should use directly but yeah it is there we have events we have the prefetch thing for

17:24:57pre-fetching the urls the interesting part is this thing we have the query object with us

17:25:04so you see next yes what's going to do it's going to split it's going to sort of explode your url

17:25:12your dynamic url on the basis of how and what were the dynamic paths so you see that we have a file

17:25:19structure of fruit then a folder named dynamically named name and then a dynamic file named sub name

17:25:26so next yes what it did is broke the query that is broker url into two parts the name is section one

17:25:34and some name is abc which it picked up from the url so if you go to abcd what's going to happen

17:25:40is you're going to get a similar thing in the query name section 1 and some name is abcd now

17:25:46right so you can pretty much go ahead and write here anything and that is what going

17:25:51to what's going to happen so what you can do essentially is you can just go ahead and print out

17:25:58router.query.name and router.query.subname right here and see that these this sub name

17:26:06matches with this that is the file name and this name matches with this right so you can name them

17:26:12anything else you can name it even name it mahul then you're going to write router.query.mehul here

17:26:17instead of subname so once you do that you can see pretty much we start getting our messages here so

17:26:23i can say hello to name and i can get hello hello abcd and i can also name you know hello

17:26:32there oops hello there there you are right so you see that then we get there later on so we

17:26:40have hello as the first and there as the next one so this is what the use router does right

17:26:47one thing which is very important for production level applications is that you use routers

17:26:54sometimes would not work as you would expect so you see that on its first render the query object

17:27:00is actually empty right the reason for that is that next.js next.js is going to make the query

17:27:11object empty if you do not have any prefetching conditions by prefetching conditions i mean that

17:27:18if you do not have any uh you know things like get server side props or get static props in place

17:27:26so we're gonna discuss about get static props and get server side props in the later section it is

17:27:32very important and very useful concept of next year's but let's not get ahead of ourselves um

17:27:39just just know how you're gonna fix that is you're gonna know that in the get static

17:27:44props video but yeah this is something which is easily fixable so anyway that's how you're gonna

17:27:51make use of use router now i can just go ahead and you know just create a button here on click

17:27:59which takes take me home which is something like this right and what i want to do is when i fire

17:28:07this when i click on this button router should go to the home page right so now you have a couple

17:28:15of ways to do that firstly you have a push and then you have a replace now let's just go ahead

17:28:21home and take a look at what both of them does let's just go ahead and take a look at push

17:28:26i'm going to give it just a slash because that's that's where we want to go right so router.push

17:28:32slash that's it so if i click on this you can see that we immediately go back to home now what push

17:28:39did is that it pushed the home on to the history of stack of history right by stack of history

17:28:46what i mean is that when i click on back button i'll go back to the page so if i click it again

17:28:53i'm on the homepage i click back i'm back to that page what replace would do however is it

17:28:59would replace that particular page from the stack history altogether by that what i mean is that now

17:29:05when i go ahead and click on this and if i try to click back i would not go back on the same page

17:29:11now you might think i'm there but let's just try this with something like um you know let me just

17:29:18go ahead and open this in a new tab and now let me just go ahead and click this so i'm at the home

17:29:23page we are using replace and if i click on this back you see i came back to my new tab and not

17:29:29the previous page because that previous page was replaced in the history with the home page so this

17:29:35is the difference between the router dot um you know router dot push and router dot replace pages

17:29:43so yeah that's pretty much it for what you're gonna need for use router that's all you're

17:29:47gonna need for the most part the router.query and the dynamic pushing of the routes here and there

17:29:54on buttons i would say personally try to use link component as much as you can because it's good

17:29:59for seo it's good for accessibility and people can actually see that there they are about to

17:30:05click a link but for places like where you need programmatic navigation router is unbeatable

17:30:12so yeah that's pretty much it for this video i'm gonna see you pretty soon in the next one

17:30:17hey everyone welcome back and in this video let's just take a look at

17:30:21catch all routes in next year's now just like i told you how you can create you know just the

17:30:27name and sub name and all that thing you can have hello there just like that now how about

17:30:33you want to go three levels deep right so you can easily see that if you are doing it in the file

17:30:38structure it can get a little bit messy as you create more and more folders you know especially

17:30:44in cases when you don't know the depth of the link so in that case you can literally never

17:30:50guess how many folders you need here so for that case what you have is you have something known as

17:30:56catch all routes by that what i mean is let me just go ahead and delete this whole name folder

17:31:04right and just create a single file inside this fruit which is again starting and ending with

17:31:11square bracket but this time it would be something like

17:31:15name but with three dots in front of it and if you observe it carefully it's sort of like how we

17:31:22um you know try to accept an number of arguments in a function as an array in javascript

17:31:30so if you have something like you know function sum and you do something like this console.log

17:31:38and if you just go ahead and call this as one two three four five what's going to happen

17:31:42is that it's going to console log this as something like this right so you have an

17:31:47array of values which were passed so anyway with this optional uh not really optional

17:31:56with the sketch all route system what you can do is you can just say export default function um

17:32:04my fruit anything does not really matter a lot what we can do is we can just go

17:32:10ahead and first of all make use of router so that we can actually see

17:32:16the routes which we are talking about so import use router from next router and then finally we

17:32:23can go here and just return h1 hello but what we want is we want to console log the router to it

17:32:33query right because this is where the magic would happen so once we have that in place

17:32:38let's just go back and try to refresh this page and you can see that we get hello even though

17:32:42we were three levels uh nested and in the console if we check the router.console you can see we got

17:32:49three values inside the name key now because name was our destructured uh you know how we

17:32:56destructure these values and we got hello there and dsfd whatever it was in the specific order of

17:33:02their occurrence right so the first one was hello the first element is hello and so on and so forth

17:33:08so i can go down and i can basically you know try one two three four five six seven eight nine

17:33:14ten and you're gonna see that you get pretty much the same thing all the way down right so you start

17:33:21with one and all the way to 10 in the specific order that is that is like important thing

17:33:27so yeah i mean this is how you're gonna catch all the routes in a particular directory

17:33:32or maybe you know if you are brave enough just place this inside your root directory

17:33:38the other thing is optionally catching all the routes by that what next js really means is that

17:33:44just like we saw that you know if you just go to slash food it's going to throw you 404

17:33:50but in a lot of cases you might just want this file to cover this use case as well instead of

17:33:55like manually creating index.jsx and then having the same code in place for that as well so for

17:34:02those cases what you can do is you can go ahead and have another set of brackets just like that

17:34:10once you have that in place if you go ahead and refresh this you're going to see that now next

17:34:16yes also catches the base of your um you know the base domain inside this particular file itself

17:34:25one very important thing to note here is that you can see this time the query object is empty

17:34:31it does not have the name key with an empty array the object itself is empty right so

17:34:37that is an important thing which you should remember when you are using optional catch all

17:34:42this might change this behavior might change in future but this is how it is right now

17:34:47so you can see now if you go to depth it starts working just like you're gonna expect it to

17:34:54so yeah i mean that's that's that's pretty much it so that's how you're going to create dynamically

17:35:01dynamic routes with optional path length and be done with it and with

17:35:07just have a single file to handle it i mean it could be very useful for a lot of things right

17:35:13so yeah that's pretty much it for this video i'm gonna see you pretty soon

17:35:17in the next one hey everyone welcome back and in this video let's just take a quick look at

17:35:22a 404 page you can create a next chase now there's whole other domain for custom pages as well but

17:35:29404 is the most common you know use case of error pages so right now you see that

17:35:35if i go to a domain or go to a path like this we get this page now obviously your business

17:35:41requirements might be different but to create a specific a different 404 page all you have

17:35:46to do is just go ahead and inside the directory create a 404.tsx file that is you know just 404.

17:35:54now remember this is this does not mean that you can create files for different status codes

17:35:59as well this 404.esx or 404.js whatever you are creating depending on your uh project structure

17:36:07this file name is actually hard coded into next.js right so you just cannot create you know 405 and

17:36:14if there's a 405 from error from the server that would be sub no that won't how it work

17:36:18so just go ahead and export default function uh my photo four and i'll just return h1 404 right

17:36:30simple as that now if i go ahead and refresh this you can see that now i get a different 404 that

17:36:35is something which i wrote simple as that you know just again yet another react component and

17:36:43yeah that's that's pretty much it for this video because i won't really board you with something

17:36:48which is not really required so that's all for this video i'm gonna see you in the next one

17:36:53hey everyone welcome back and in this video let's just finally start with one of the most important

17:36:58things in next year's that is the get static props function now what this function really

17:37:05is is to explain this i just have to go ahead and create let's say a file um i'm going to say

17:37:14maybe dynamic dot tsx why not let's just go ahead and create a function which is just dynamic and

17:37:24return h1 dynam nothing dynamic about that as of now but what we're going to do now is we're going

17:37:31to export another function from this file which is not going to be a default export because obviously

17:37:37we did export a default function but that is going to be a get static props function so i'm

17:37:45going to say export const get static props now you can type this if you want get static props

17:37:53if you want that's that's where the type would shine and it would just correct us with the

17:37:58things and you're gonna have something known as the context for this function right being passed

17:38:05to you now you can clearly see it throws me a warning an error whatever it is that we need

17:38:11to return an object from this particular function right so let's just go ahead and do that exactly

17:38:18i'm going to return an object but it needs more than an object it needs a props property

17:38:23which should be an object so for now i'm just going to say my favorite number is 4 like that

17:38:32right i'm not making use of this context doing nothing at all

17:38:36what this does however is before your function is executed nextgs is going to execute this function

17:38:43right here in terms of server right so this function executes on server you can think on

17:38:52execution on server right and this function right here is executed obviously on client as well as on

17:39:01server but for the most part you can think of this that next yes it's going to execute this on server

17:39:07take whatever the return value is take the props from that return value thing and inject that

17:39:13object as props inside your component right so now if you try to say dynamic number is you know

17:39:24props dot my fave number what's going to happen really is because this object has been dynamically

17:39:31inserted into this page you're going to see a 4 here so now if i go back and go to dynamic hit

17:39:39enter you can see dynamic number is 4. if i go ahead and change this to 5 and refresh you're

17:39:45going to see we get a dynamic number 5 right and you can clearly see that if i go to the page

17:39:51source dynamic number and you can see that this is this thing is actually present in the source code

17:39:58itself you can see the 5 is here right it's not injected on the client by some javascript magic

17:40:06it's actually rendered on the you know on the back end by next year's and is sent to the client but

17:40:15but you can see clearly that next year actually in checks my favorite number as five prop as well in

17:40:23the page now why is that well one of the reasons you can think of is that suppose if you are coming

17:40:30to this page from another page then what next chase really do

17:40:35is that um you know it just it instead of getting this whole html to to the client it will just get

17:40:43the updated props and the template for the page and would dynamically construct the page right

17:40:49because that is much cheaper than you know just completely navigating to a different page but for

17:40:55the most part what you have to remember is that you can see that the get static props is actually

17:41:01helping you to have dynamic content on your page now you might say that this is not really dynamic

17:41:07but what if i told you that you can actually require the file system here right which is

17:41:14the node thing right so if i have something like um i don't know let's just say we have a public

17:41:22robots.txt file right i am a file something like that now if i go ahead and say

17:41:30my favorite number is if it's fs dot read file sync that is synchronously read file

17:41:36and if i go back a directory into public robots.txt and i want to read it in udf mode

17:41:45and just do that what's going to happen if i refresh it now

17:41:50we get no file or folder because we might just need to have path here as well well

17:41:59things might get a little bit you know ugly for setting up the context but but don't join

17:42:10name i think it should not be directly named it should be process.cwd and once we do that

17:42:18what's going to happen is it's going to start from the root directory so we just need public and

17:42:25yeah things like that let me see what's really going wrong what we are missing path.join

17:42:33it's fine it's fine as well my favorite number is txt right so now you can directly see that

17:42:41i get imf file i can go ahead inside this i can edit add some more dots hit save refresh

17:42:48we get dynamic content again you might think that this is not truly dynamic and that's fine

17:42:55but what's fascinating about this is that just what i'm going to show you now

17:43:01with props it actually accepts a revalidate parameter as well that's it for this video

17:43:07in the next one we're gonna see a revalidate parameter which is extremely useful in next years

17:43:14and especially inside the get static props thing so that would be all i'm gonna see you pretty soon

17:43:20in the next one all right everyone now we're gonna take a look at the revalidate parameter

17:43:25in xjs and what this parameter is is that it allows you to do something amazing

17:43:32what happens when you use a page page like this what happens is that when you push it

17:43:38to production when you create the next shares build what's going to happen is that it's

17:43:43going to create a static it's going to create a static export of this particular page you know

17:43:50just like with the contents of this and be done with it right next year's now whenever you visit

17:43:55the slash dynamic it's just going to pick up that particular file which is it has statically created

17:44:01from the file system and throw it on you it does not bother what's in that file

17:44:05nothing at all but when you specify a special parameter called revalidate and with let's say 10

17:44:13what's going to happen is that things become interesting now in 10 seconds if there's a request

17:44:22to the server in every 10 seconds if there's a request to the server next yes is going to

17:44:28try it's not saying that it would it's going to try to recreate this page based on updated data

17:44:36by that what i mean is that it's going to run the get static props function on the server for this

17:44:43page and try to update the the static file which it has for this particular page and this only

17:44:51works on production so i cannot really show you on the local host for the demo because revalidate

17:44:58is useless on the local host because um you know get static props on local host always runs right

17:45:06just for you know development reasons because it would be very hard if it's just running once

17:45:12so on production let's just take a look at this this website this nice little website you can see

17:45:17i can refresh this as many times as i want and these numbers right here are not changing right

17:45:23because if you take a look inside the source as well you can see 448 is actually a written number

17:45:29right here inside html and it is actually stored on the as on the server as a static html file

17:45:36but let me just go ahead on this github issue now and focus on the 448 you can see that i have

17:45:44already given it a thumbs up let me go ahead and remove this so it's 447 now if i try to refresh it

17:45:50you can see it's not updating it's very important you see this this you can see that after some time

17:45:55it updates to match your number right and that is that is great because the guy who has actually

17:46:04created this page the repo when it was built next you do not have to redeploy it to update

17:46:10this number that is you do not have to recreate the whole static all the static files next js

17:46:15already did that on the basis of this revalidate parameter so this is what the revalidate parameter

17:46:21usually would do that is it would help you to refresh the pages which you think might change

17:46:30but not as frequent right the best example for this could be blog post so you might want to

17:46:36throw in a revalidate there but maybe of 60 minutes or two or three hours right because

17:46:43once you have the static built of the blog post it might probably won't really change especially

17:46:48if the blog is very old so yeah that's how the evaluated parameter works in a nutshell

17:46:54um and that's how it works really so that would be all for this video i'm gonna see you pretty

17:47:00soon in the next one hey everyone welcome back and in this video let's just take a look at

17:47:06another function which is very important which works very closely with get static props and that

17:47:11is get static parts now let's just go ahead inside this fruit and let me just go ahead and name it

17:47:19very simply just name and let me just go ahead and paste it right here um let's just get rid of this

17:47:28and let's just make this math.random why not right we have the props and we have let's say oops

17:47:41we have let's say hello props dot my favorite number nothing fancy the most boring application

17:47:50on the planet right now but what we are gonna learn about is not very boring because we're

17:47:57gonna export another function from this file that would be named get static paths and we can type

17:48:05it with get static parts right here right which is going to help us with some of the types so it

17:48:12returns an async function one more time and you can directly see it's complaining us with um you

17:48:18know a return type of something like this so what do we really have to return from this function

17:48:24is an object first things first this object should have paths within itself firstly

17:48:32so we have a parts which is an array we're gonna see what should go inside this array

17:48:37and then another another property a segment property which is a fallback right so i'm gonna

17:48:43specify the fallback to false first of all now there are a couple of things which we need to do

17:48:50first of all in this in this before we actually learn get static paths the first thing is that

17:48:56whenever you implement get static props inside a dynamic file that is you know a file with the

17:49:03square brackets around it you have to implement this function anyway get static parts right

17:49:09get static props would work fine on its own only inside a page like this which is a standalone page

17:49:17right dynamic.esx is a standalone page if you have a dynamic page you have to get

17:49:22you have to use get static parts and it will make sense why you need that

17:49:26you need this function because this function specifies when the static props should run right

17:49:34now first things first get static props runs at build time right it does not does not

17:49:47run at runtime by that what i mean is when you're gonna push this application to production

17:49:54before anyone sees your application live getstatic props would be run for all the pages and you know

17:50:02all the html files would be computed all the json files would be computed and they would be stored

17:50:08on the file system that is why it works perfectly fine for you know static files like this

17:50:15you know with with no square brackets with them but with files like these they have a problem

17:50:22because static props runs at build time you cannot create infinite number of files obviously

17:50:29right so the second solution is to specify to get static props that is is to specify to next js

17:50:37on which files you want to run this static props on right i hope this makes sense so far

17:50:45so how do you do that well get static parts exactly does that and it takes two values for this

17:50:53we're gonna ignore the fallback false for now just bear with me um this parts think what this is is

17:51:01it contains the information um on which particular routes you should run the static props on

17:51:11so what do i mean by that i'm going to say params is an object right which contains in our

17:51:19case it will just contain name because name is the dynamic part and i say that name is hello firstly

17:51:27another object is name is world and not really like this inside a different object itself right

17:51:37so you can clearly see what's happening here uh let me just go ahead and see if i can make some

17:51:46space i don't really think i can but anyway you can clearly see what's happening here i have an

17:51:52object params with a name of hello another object with the name of world and i have a fallback of

17:51:59false this is important to remember but you can forget about this for now so what would happen

17:52:05is that when you push it on production nexus is gonna visit these two particular urls it's gonna

17:52:11it's going to say let me just go ahead and fetch localhost 3000 fruit hello take the output

17:52:21store it on the disk and i'm going gonna go ahead and take the output world and store it on the disk

17:52:30and done that's it case closed start and done any other route any other route which is here

17:52:41it's it is going to be discarded as 404 let's see so now if i go to fruit and hello you can see it

17:52:51works fine if i go to world you can see it works fine but if i go to one you can see we get our

17:52:58404 which is the ugliest 404 ever but we can just delete it and if i refresh this you see we get 404

17:53:08on a page which was supposed to be dynamic right so how does how why did that happen let me just go

17:53:15you go through over this thing one more time why did that happen you can see that we are very well

17:53:21inside the dynamic segment itself our page file name is also dynamic so this should technically

17:53:26render this but it did not do that because we have a get static paths get static paths when

17:53:34has a fallback of false defines that this paths array would be the only thing that would be

17:53:44permissible so as to speak so if i go ahead and replace this hello with one now if i go ahead

17:53:50and try to visit this url what you're gonna see is this works now right because i just added it

17:53:56to be permissible but you're gonna ask me that hey mijo doesn't that really defeat the whole purpose

17:54:03of the dynamic thing well i mean it might for you but for some cases this is this is better right

17:54:12for example again here you can access access all the node stuff that is you can make db

17:54:19calls you can access file system you can do whatever you want to do and finally you can

17:54:25create this object on the build time to have a number of parameters have a number of things

17:54:30and they would all be fetched and dynamically their static equivalence would be created right

17:54:38but what i did not really tell you about is the fallback option as true by fallback true what's

17:54:46going to happen is that this thing is still going to happen you know when you're building

17:54:53build start when the build starts next yes is going to visit this hello right here

17:55:00next chest is going to visit this world right here but it will not be done right what's

17:55:06going to happen instead is that if you have a fallback of true here it is still open to

17:55:16to any other url as well right it is still open to any other url but it would not

17:55:26statically create the html content of it on the build time right so if you go ahead and visit

17:55:33this later on what's going to happen is that it's going to try to run this on the server now

17:55:40this is happening on the server now right this is not happening as static nothing is nothing

17:55:44happening on the static part this would run on the server that is inside the get static props

17:55:50it would fire this function for this particular um slug or whatever you want to call you can

17:55:57see in the context you can see that we have the params property which is containing the you know

17:56:05this particular thing so you can have context.params.name in our case and this would

17:56:09be name for us so you can fetch make a db call whatever it is and if the result is present you

17:56:15can return a valid object next chase wouldn't then use that get static props just like it has before

17:56:22to inject it and show the page so in this case it would be call the get static props on servo

17:56:34um you know render the page and then in background next js would add this to the paths list

17:56:44and would store it locally on the file system for faster access

17:56:53right by that what we mean is the next time the next time you visit this url right here

17:57:00the next time you visit this url right here what's going to happen is directly send the output

17:57:09from file because we have already done all of this and we have stored it on the file system

17:57:16for faster access only this particular specific page if you change another page

17:57:20if you change it to another page hold this whole of this thing repeats again

17:57:24right so yeah i mean that is how git static paths in next chase work that is how the

17:57:30paths property work that's how the fallback works one last thing if you have the fallback as true

17:57:37what's going to happen is that next js is not going to wait for this get static props to finish

17:57:45by that what i mean is if you are visiting this for the first time what's going to happen is next

17:57:50js is immediately going to serve you this page with the props being empty right and it's going to

17:57:57you know just just um fill this props object later on so how would you know that

17:58:05it is waiting for get static props to run on the server well you have to first of all

17:58:11import the router like this you have to say something like if router dot is fallback that

17:58:18is it is loading on the server you can just return h1 loading something like this right

17:58:24and be done with it so now if i go ahead and visit a page something like hellofroot1 you

17:58:31can see i get loading for a bunch of seconds for this page url as well for this page url as well

17:58:38for a bunch of second and then once the props are injected you know the props is available

17:58:45to us this is fallback property becomes false automatically next year's handles that for us and

17:58:52we render our actual component now when you are on production the first time you would visit this url

17:58:58you're gonna see loading and then hello but the subsequent refreshes you're gonna directly see

17:59:04hello right because next.js now has the output from the file system itself so you do not have

17:59:09to wait or you do not have to see loading again but in development you're going to see loading

17:59:14every time because just like i said in development next chairs for development purposes would fire

17:59:22get static props every single time right so that means that it would also become true every single

17:59:27time and you're gonna see loading every single time but don't worry about that in production

17:59:32you're just gonna see it for the first time and on the subsequent dynamic builds of this

17:59:37url you're just gonna see the page statically so yeah i mean that's pretty much it for get static

17:59:44parts that's all you really need to know about this know about this that the first thing is

17:59:49it is absolutely necessary when you're using dynamic routes the second thing is about the

17:59:55fallback property what false means what true means false really restricts your domain of this thing

18:00:01and true means that anything is allowed but that would have to go through to get static props

18:00:07and yeah i mean in case of false nexus would pre-render all these routes and you're gonna

18:00:15not get is fallback for the pre-rendered routes but for anything else it's going to you know just

18:00:23send it to the get static props and wait for it and if it is false that is the fallback is false

18:00:30that just means that you are fixed with the number of routes which you have here and this is fallback

18:00:34never run anyway for any route because if it is not present here then you're going to get a 404

18:00:40so yeah whoo that's basically all you need to know about get static paths get static props and

18:00:47dynamic files there's one more thing which is left that is the get server side props which is

18:00:52essentially having your own server call on every route and is usually said to be you know something

18:01:01of a not really a bad practice but something which you should avoid if you could avoid

18:01:06so yeah that's pretty much it for this video i'm gonna see you in the next one hey everyone welcome

18:01:12back and in this video what we're gonna take a look at is the get server side props now there's

18:01:19another function which is known as get server side props let me just go ahead back go back to

18:01:24the dynamic thing and i'm going to export const get server side props and get server side props

18:01:32is the type for this and again we have the context with us which you can monitor for more

18:01:38values right you can see we have a actually um interesting things this time with this but anyway

18:01:48what we have here is that again we have to return the actual props right and you could have pretty

18:01:57much my favorite number again as math.random it does not really matter the thing which matters is

18:02:05that get server-side props is going to run always right which is why it is usually um

18:02:15you know just said that if you can go ahead and make your code not use server side props that

18:02:22is better the reason for this is that get server side props is called always on every page request

18:02:35even on production right so just like we saw that next years could actually create static

18:02:42bundles out of these files stacktech.html pages that is not going to be possible when you're

18:02:48using it server side props on on a single page right so if you're using git server side props on

18:02:53this page next js is not going to create a static um dynamic.html file on its file system to serve

18:03:02it faster because you never know what you might return inside the props that is the whole purpose

18:03:09of get server side props it adds a layer of dynamic rendering on the on the react framework to

18:03:17be honest this is what we wanted this is what we always wanted with next years right that it allows

18:03:24you to render server side javascript dynamically this is the essence of server side javascript

18:03:32right but when we have finally discovered it i'm discouraging you to use it why is that because

18:03:39when you use get server side props you are calling a node server on every request that means you

18:03:45get no caching benefits that means your request would be slower to the clients because it has to

18:03:52uh you know go all the way back to your server to be executed so this is pretty much in cases where

18:04:01you absolutely cannot afford to have even the slightest delay like you know instead in

18:04:08um inside of get static props static props we can have a revalidate parameter here right revalidate1

18:04:15which is going to have some sort of static data but within a certain time frame it's going to

18:04:21update that but with get server side props we do not have anything like that so this is

18:04:27very much useful in case you want to create a real-time dashboard or stuff like that

18:04:31where latency would be absolutely disaster on page updates or page refreshes something like that

18:04:39so yeah i mean that is pretty much the whole purpose of get server side props

18:04:44i would say to almost always never use it unless you absolutely need it because you lose a lot of

18:04:53static optimization benefits when you use that so yeah it exists as a tool as a thing

18:05:00if you need it that is great but try to avoid this in your application logic try to figure out the

18:05:07logic where you can use this where you can avoid using this get static props is the best you know

18:05:15and you can even use it as a dynamic thing now with the revalidate parameters so that's awesome

18:05:20but yeah so that's pretty much it for this video i'm gonna see you pretty soon in the next one

Advanced Next.js Concepts

18:05:27hey everyone welcome to another next chairs course in this course we'll be learning about advanced

18:05:33sides of next year's so if you're somebody who's new to nexus and do not even know what next year

18:05:38says this is probably not the course for you you can start with next years by going to learning

18:05:45paths and opening the next year's mastery which is going to give you access to a complete breakdown

18:05:51of how to begin with next shares and spoiler alert next is almost like react right so if

18:05:57you have been a react developer you're good enough to start with next year's but again this is not a

18:06:03starting course this is more of an advanced side of course i'll be skipping over a lot of details

18:06:08which we have already covered in the basic courses so do not expect those details in this one so

18:06:15let's get started without wasting any time from the next video onwards we're going to be picking

18:06:20cherry picking some difficult to understand topics and i'm going to be breaking them into

18:06:27simpler concepts so that we are able to understand how that thing exactly works so that will be all

18:06:32for this video i'm gonna see you in the next one pretty soon hey everyone welcome back

18:06:37and in this video let us just go ahead and take a look at environment variables and how to manage

18:06:42them in next year's application i have already created an app so i'm assuming you already have

18:06:48you're already inside an application so this is a very simple application hello world you know the

18:06:54server is not running let's just do a yarn dev here real quick and if you go to localhost 3000

18:07:00you're going to see the website would work just fine now what do you want to do first of all is

18:07:06you want to understand what environment variables are exactly what happens now is that let's just

18:07:13take example of development and production right so if you are developing a particular application

18:07:21you would have a lot of software's either local or on an infrastructure which is not supposed to

18:07:29receive very high volume of traffic right we also call this sometimes a staging so development work

18:07:35happens either on either locally or on staging production work happens well on production servers

18:07:42which are you know uh configured for high loads and high availability and all that stuff

18:07:49often times when you are iterating and developing and doing all that stuff

18:07:54not only is it uh a better choice to have a separate server but sometimes it is actually

18:08:00impossible to have production server access because if they are guarded by uh firewalls

18:08:06or you know if uh your main application is part of a network which does not permit outside connection

18:08:12so there could be a lot of reason so the way you manage those external resources is that you keep

18:08:18your application stateless about them that means your application code this code right here

18:08:25does not matter if it's react or you know no chase logic or anything which we'll see in a couple of

18:08:29videos on server side props and all that stuff your application code should not be aware about

18:08:37where it is running right that is the goal and how do you make sure of that

18:08:42you abstract away the important details the important information of production or development

18:08:48in certain environment variables which come from the environment itself

18:08:53just like the name suggests that if you're running in a development environment

18:08:56that means if you're running on a local system or a less powered machine you're testing stuff

18:09:01the variables a few variables are filled in by the environment not by your code

18:09:06similarly for production so for production you might have a large i don't know like um 16 gb ram

18:09:171tb ssd mongodb i don't know if that is even a good configuration for a database

18:09:24like that but you can have an instance for that right on a development you might

18:09:31want because you know you know that traffic won't be a lot so you might have a 1gb

18:09:3850 gb ssd right so how do you convey the connection points that is the connection

18:09:46url because you know if you're connecting with [ __ ] you're gonna probably do

18:09:50something like mongoose.connect if you're using mongoose and then mongodb localhost

18:09:56and then the port number and then basically the you know the name of the database so how do you

18:10:03do this well you can see right here this is a stateful path that means your code should be aware

18:10:11it's it's not technically stateful i'm actually using the wrong word it's more about that your you

18:10:16have hard-coded uh your um you know environment sort of here so what you eventually want to do

18:10:24is you want this to bring you want to bring this from environment that is process.env and then you

18:10:32probably want something like um mongodb connection url right you want to do something like this

18:10:40so how do you make sure that when you ship this code on production when you ship this correctly

18:10:46this environment these environment variables are automatically populated so you do that with the

18:10:51help of next year's internal support for local and production and development environment and

18:10:58let's discuss all of that so i'm going to go ahead and explain that to you by starting off

18:11:03by creating.env.local file and the moment i do that you're gonna see if you're using vs code

18:11:09you're gonna see this gets dim and the reason it gets dim is because this is automatically added

18:11:14by next shares in the git ignore file and there's a good reason for this now i'm gonna come to the

18:11:22reason later on let's just discuss about what this thing does first of all so let's just

18:11:27say i'm gonna add a secret variable right and i'm gonna just put this value as codedam.com

18:11:37right so secret variable is now a code that holds a codename.com variable value but how do you

18:11:44access it well i actually just showed you how you access it so what you can do is uh right here you

18:11:52can say console.log or maybe let's not do here because that might confuse you so let's just do

18:12:01export function gets our site props and you can just return

18:12:11this has empty and you can just console.log

18:12:15dot process.enb.c variable right now if you go ahead and take a look at this actually if i go

18:12:21ahead and uh you know refresh this you're gonna see that you actually get undefined now the reason

18:12:28for that is because nextjs does not use javascript to include these files these variables they are

18:12:37done before next year starts the server which is a good thing why because well you know you

18:12:44remove the overhead of including the environment file with javascript so that means if anytime you

18:12:50are making a change to your environment file you gotta restart your server right

18:12:55so that's that's one thing so once you do that and refresh it then you're gonna see

18:13:00now you get coded.com as the console.log now remember that uh you know we are obviously

18:13:08working right now dot env dot local file but just a couple of quick points if you try to do it here

18:13:17a few observations you will be able to make so let's just do uh you know env value just to

18:13:26separate that and i'm going to do process dot env dot secret variable right now you know that

18:13:33because you're using next js this guy this function is going to run both on server and

18:13:39on client right why because servo means server side rendering and client well means hydration

18:13:46right because next react would try to hydrate the tree in order to have you know see if we

18:13:53have any event listeners or anything unless you of course opt out of that manually but right now it's

18:13:59enabled so what nextjs does is that technically on the browser you have nothing as such process

18:14:06but nexus would polyfill that for you and this would be available as an object however this

18:14:13value right here will not be accessible on browser of course of course you don't want this value to

18:14:19be accessible on browser right because we will be storing stuff like db host um you know production

18:14:27dot mongodb your whole string and then db username and db password so you of course don't want that

18:14:35to be available on the browser but anyway let's just confirm if that is the case or not so i'm

18:14:41going to go ahead and refresh it here you can see the env value which we get in the node terminal

18:14:48remember this is the node terminal this is the back end it's not the front end is correct

18:14:52coded.com but if you go to the console here on the front end i think i have some search term

18:15:00you can see on the front end it's undefined right if i refresh it again you're going to see back in

18:15:06gives us the correct value the front end does not so there's obviously just like i said a

18:15:11good explanation why nextgs will not pre-fill or you know just supply the variables to front-end

18:15:19now with that being done of course there could be times when you want uh variables to be available

18:15:26on front-end as well right because let's say you have a client-side api and you want to

18:15:32have a token or a secret key for example a common use case i can think of is recaptcha

18:15:37so the way you do that is you do include next underscore public right and i think that's it

18:15:47and then whatever you want to name this this is a mandatory syntax this is hard coded into

18:15:51next year's framework so you have to include that there is no uh you know magical reason for this

18:15:57you just need this because the framework says you to do that and i can say my first browser variable

18:16:07and you can give you know underscores there i just did not feel like that and you can say some value

18:16:16yeah i'm bad at not only just naming variables but putting values inside them as well so once you do

18:16:22that now you can do a process dot env dot this thing and of course just like i said you gotta

18:16:31restart the terminal because well nexus needs that and once you refresh this you're gonna see once

18:16:38the page compiles you get some value on server obviously because that's a environment variable

18:16:45but you also get some value on client right so that means whenever you prefix your variable

18:16:52with next underscore public underscore your variable gets exposed on the browser front

18:17:00so this is how you work with what this is basically the introduction to environment

18:17:05variables how you work with them in xjs and how the dot e and v dot local file populates

18:17:11variables inside your node process and inside the browser in the next video we're going to be

18:17:16seeing a little bit more on the management of the environment variables and some conventions

18:17:21you should keep in mind so that is all for this one i'm gonna see you in the next video

18:17:26hey everyone welcome back and in this video let's just go ahead and take a look at a little

18:17:31bit of management of this dot enb local file and a couple of other files which are interesting to us

18:17:37now what nexus does is that it comes hard coded with three files dot env.local.env.development

18:17:48development and dot env dot production

18:17:54now talking about the convention what you can think of is that these two files these files

18:18:02as templates right now these files can consist of you know non-secret variables as well if you want

18:18:10because you can ship them on um you know version control that is git or github whatever you want to

18:18:18you know do uh it's not like you you can ship obviously you can ship.env.local as well

18:18:26but the convention the good practice is to ship these two files and to have only

18:18:33the secrets which you know not are not really secrets but only the variables which you can

18:18:39afford to make public or to make accessible to anyone for example some stripe client key

18:18:47right which you can access both on server and on client on the browser so that could be

18:18:54inside this particular file this file however what next chase recommends is that you should have

18:19:01specific values and should be available only on your local systems for example database passwords

18:19:08right for example stripe secret key so stuff like this this should not be on the version control

18:19:17system this should not be uh you know in the pro in the deployment pipeline this file should

18:19:23be individually present on the production servers as well as you can create it for yourself on your

18:19:29local systems because you know when you're working on local just like i said in the last video

18:19:35your staging passwords would be different from production service passwords right and

18:19:39your uh for example stripe mode stripe would all obviously be operating into the development mode

18:19:45so you're gonna have a little bit of different values so that's better to have different value

18:19:51depending on different environments however let's talk about how next year streets

18:19:57if you have all these three files present so i'm gonna go ahead and create dot enb dot development

18:20:05and dot env oops dot env.production here and i'm gonna create a new variable i'm gonna say

18:20:14uh specificity check zero right dot local get zero development gets one and production gets two

18:20:27so if i go ahead and right now just to uh check here and say specificity check what do you think

18:20:37would console log zero one or two let's see so you know obviously you can make sense of that

18:20:46you won't really get the production console log because well we are not running it on production

18:20:51so it's it's more of a choice between 0 and 1. so if i refresh this page you're going to see that we

18:20:57get a value of 0 and why is that because whatever variables whatever values which are present in

18:21:05the dot env.local file will override anything else right they will override the development

18:21:14or production depending on where you're running it so of course if it does not has this dot env.local

18:21:21does not has this and if you refresh restart the server again and refresh the page you're gonna see

18:21:27that you get one which is the uh fallback value right so you get the one but the moment you add it

18:21:38something else it will fall back or it will consider enb.local as the primary store

18:21:44how you gonna ship this env.local to production you won't right you won't ship this file to

18:21:52production you would either just code it once and leave it right there on the production server and

18:21:59if you want to update it you have to manually update it or a better way for production is

18:22:05to you know probably not have dot env dot local at all and maybe use something like uh for example if

18:22:14you're running aws lambdas you know that you know you can specify environment variables

18:22:19directly from the interface so maybe you can use something like that it depends on how you want to

18:22:23execute it on production but on development well nexus is going to do that job for you

18:22:30so what about this dot erv dot production and development as you might have guessed by now

18:22:34next just detects what you are running where you are running next yes right now if it is

18:22:39development it's going to include this file if it is production it's going to include this file

18:22:43and how does it detect that well it uses process dot env.node enb variable which you can see in

18:22:50the source code of nexus as well i just open the node modules folder and just search for dot enb

18:22:57and you can you know i won't really want you to make sense of this but this is pretty much a place

18:23:03where i believe it's trying to figure out the name of the file right so what you can see is that it

18:23:10tries to play with the process.dnv.nodenv it might have set this variable value

18:23:17depending on how you are building the project as well right if you're building it in a production

18:23:22mode it's going to be set as production if you're building a development it might not be said at all

18:23:28so so on and so forth you don't really have to worry about that but yeah that's pretty much it

18:23:33on uh how you're gonna set some environments and get started with that stuff in next year's so that

18:23:40will be all for this video i'm gonna see you in the next one hey everyone welcome back and in this

18:23:47video let's just go ahead and take a look at and take a good look at actually what gets server side

18:23:53props is now we have uh you know you might have some experience some knowledge of gets oversight

18:24:00props what it does and all that stuff but let's just get into depth of what exactly this does

18:24:06so first things first what exactly this server side prop function is

18:24:13well you see that the architecture of next shares is as follows next year says that hey

18:24:20whatever page you want visible you want to live on your domain for example if you own codedam.com

18:24:28then if you want to have something which the user can see something meaningful which the user can

18:24:33see on abc and 123 or maybe like let's just keep it abcdef for now what you got to do is you got to

18:24:40go to pages directory and create a file called abcdef.jsx or js right now what happens when a

18:24:50person visits this url is that internally if this is not a static build assuming there's a next

18:24:58year server running if this is not a static build nextgs is going to check if this file

18:25:06if this file has a function called get server side props now this might be a little bit misleading

18:25:14because it does not check that for every single request when you're building your application

18:25:21it's going to mark certain routes which uh have this function right so when you're building an

18:25:27xjs app what's going to do it's going to see that okay abcdef uses this get server side props

18:25:34therefore i'm gonna be a little bit more careful whenever somebody visits this

18:25:39and how is next year's careful is that whenever somebody visits this it's gonna not immediately

18:25:47surf the html page to the user it's gonna first of all run this function whatever it

18:25:52this function includes whatever instructions this includes and then it's gonna render the page

18:25:58right i hope that's clear if you do not have this for example if we have a route let's say this was

18:26:07dynamic right and this is static if we have this route which has no get server side props

18:26:16so what's going to happen when you build the application nexus is going to mark as

18:26:24uh you know server side rendering it's going to mark the dynamic page a server-side rendering

18:26:29and it's gonna just say mark as uh static completely static completely static or you know

18:26:38i'm assuming that there is no get static props as well here so mark is completely static there

18:26:43we go so whenever somebody was a static nexus is gonna immediately throw uh the already generated

18:26:52page or already generated html file uh which your server already has right

18:26:57but with dynamic it's gonna say wait a minute we also have a javascript some node.js logic to run

18:27:04so let's run that first and then let's just go ahead and run the whole generation of the page

18:27:12again in javascript right so you are running a lot of lot of javascript when you are using it

18:27:17server side prompts on every single request so what happens exactly is that you always on a

18:27:25particular request on a dynamic request you always run javascript before actually rendering the page

18:27:33it's very similar to how you know back in the days php would work so if you have a php file

18:27:39what you're going to do is that you know you're going to have some php syntax like this and then

18:27:46maybe you can connect to db fetch rows and then display data right that's how you're going to

18:27:53do in php similarly if you want to do a similar behavior in next chairs what you can do is you can

18:28:02um you know right here inside kits oversight props you can have this function as async first of all

18:28:08and then you can say something like uh db is await connect to db

18:28:15right rows db.fetch rows whatever this is just dummy data and then finally you know

18:28:23send the rows to your react component as props then you receive the props right here and you

18:28:31know you destructure the rows from props and then maybe you map it and render it and all that stuff

18:28:38when that happens next js is gonna execute this particular javascript piece piece of javascript

18:28:46and it's gonna create static html out of it and then it's gonna send it to the client right on

18:28:52every single request this function is executing on every single one of them so that's that's that's

18:28:59powerful but that is also resource extensive right because now you are running node.js on every

18:29:07single request if you are uh you know coming from express background or express shares you know that

18:29:14what we do usually is express uh we usually throw express dot static and then you know

18:29:21just serve static files directly and then maybe if you have a api route for example app.app.post

18:29:32you know something like that then your application then these static files might be able to make a

18:29:37request to this particular api but next chase follows a little bit of different convention if

18:29:42you try to go with server side rendering and that is okay exactly the point of server-side rendering

18:29:47right that you render the output dynamically so you can get true server-side rendering with next

18:29:53shares truly in what that means by using get server-side props but again just like i said

18:29:59server-side rendering comes with its expense that it is in fact server-side rendering and nexus is

18:30:04gonna run this for every single request um unless of course you introduce your own caching layer in

18:30:11between for a cdn or something but that's that's a different story right uh but that's how it happens

18:30:18now the internals of how this happens we're going to be pretty much like seeing that from

18:30:24topic to topic that is what happens what is in the context variable but if you go ahead

18:30:31and just just try to explore this i think we won't really have a auto complete without typescript but

18:30:38uh let's just go ahead and console.log it right so that we can just see some common properties

18:30:48and if you go ahead and refresh this page now and we get serializing props returned

18:30:58yeah anyway so you can see we have a bunch of data with us but interestingly you're gonna see right

18:31:06here the first thing which we have is a request right so so yeah i want to dive a little bit

18:31:13deeper into these variables and the values so let's just keep it in the next video i'm going

18:31:18to see you in the next one really quick in which we're going to discuss about a little bit about

18:31:23these past values all right guys welcome back and in this video let's just take a look at

18:31:29what all information we are getting at with the get server side props and mind you that gets

18:31:35oversight props is like the most powerful function in xjs therefore you can pretty much expect

18:31:43this function right here to give you access to literally everything you can imagine on a single

18:31:48request right so let's see the first thing which we saw is the request variable which

18:31:54again is is a sort of an incoming this is an internal nodejs http.incoming message

18:32:01uh interface but you're gonna see that this pretty much follows a little bit of express shares

18:32:08pattern we're going to see that so everything you need about a request that is the url path

18:32:15for example the raw url the raw http information you know we can also see you have the socket

18:32:22right here if you want to send a reps response you have all the headers which the request url made

18:32:29you have raw header information which is also something and you have the method you

18:32:34have the url you have the you know connection upgrade all that stuff information as well

18:32:40so you have basically everything right here in terms of raw node.js request processing right

18:32:47so if if you try to do something like i don't know context dot request

18:32:52dot uh not really request we're gonna do it with response so let's just see that first of all

18:32:58so response is again something similar to um what you're gonna see inside of a typical nodejs server

18:33:06so if you are if you have ever ever created a http notice server you're gonna see the first

18:33:12two things you get is a request and response parameter right for every single request so

18:33:18if you try to do context.response.end like this and that's it if you try to go ahead and do that

18:33:26and if i refresh this page right here you're gonna see we pretty much get a very

18:33:31not so good request ending right so if i refresh this well we get 200 as the status

18:33:37code but that's pretty much it we don't really see anything else so you could pretty much just set a

18:33:43context.race.status as 403 as well refresh this and nope this should be status code not status

18:33:54refresh this and you can see you get a 403 right here you can set it to 418 that is i'm a teapot

18:34:03i like the status code but yeah you're going to get that so you can see this pretty much is an

18:34:09actual servo right this this you get a server level control inside this function it does not

18:34:16matter that you're running a react app below it right if you try to do uh you know nasty stuff

18:34:23here you can do as much as you want so you can even have a you know context.rest.json

18:34:31i don't think if they have a json let's just go ahead and try send json.stringify

18:34:39something cool right if you do something like this refresh uh not send is not a function

18:34:47so maybe like i don't know write not really send rest not right refresh and we have a fail request

18:35:01probably not i just restarted the server and now you can see

18:35:06it looks pretty much like a json response

18:35:09from the home page of a nexus application right so that might seem weird if you're if you had the

18:35:19next css just you can just send react as the stuff that's not true right you can

18:35:25use get server side props to truly um get a server like experience from nexus as well

18:35:34so anyway that is something some sort of fun which you can do with next year's parameters

18:35:39let's just keep going there's a lot of more stuff here which next year's brings us so idly

18:35:45if you think about it request and response are the only two things which you need right so if

18:35:51you console log the request you're gonna see you pretty much will have every single information

18:35:56every single thing you need so let me just go ahead and refresh this again real quick

18:36:01and you can see that you will have cookies you know you're going to have request.url right here

18:36:08you're going to have method you're going to have headers you're going to have everything

18:36:12but working with this in a raw fashion is a little bit cumbersome so what nextgs does is that it

18:36:20gives you access to a bunch of other things as well so the first thing let's just keep it to

18:36:29the you know this this sort of way as well because i will not be able to miss any property in this

18:36:37one so we have already covered request right and response which are the two biggest sort of objects

18:36:43on the screen right now but we also have a bunch of other things right so we have uh this query

18:36:50which is an interesting thing this query would be automatically populated by nextjs depending on how

18:36:58you are splitting your route right so let's see what let's let's take a look at what this means

18:37:04so i'm going to go ahead and rename this index.js to dynamic.js right and this dynamic word could

18:37:11literally be anything this could be code dam as well so i'm going to go ahead and take a

18:37:15look at code down just make sure this you know that this could be anything so once we do that

18:37:22what next chase is going to do is it's going to serve this particular file on every single

18:37:27route one level down right so i can have page one and that is served by this code down.js

18:37:33and the reason i hope you know is because this is a dynamic route because it's in square brackets

18:37:38again hard-coded deep into next year's that is something you have to follow for now

18:37:44page 2 also lands on the same thing page 3 also lands on the same thing but interestingly if you

18:37:50take a look in the console you're going to see the query parameter now gets populated with code down

18:37:56now you don't necessarily need this because you can extract you can technically extract

18:38:03this information from the url from the request.url parameter as well because if you go to url you're

18:38:10going to see this as page 3 then you can have your own regular expressions and run against

18:38:15that to extract the parameters but why do that when next chase is doing the heavy lifting for you

18:38:22so you can literally just go ahead and do context dot query dot uh context.query.codam and you are

18:38:30pretty sure that this value will be present 100 why because you know that the file name is the

18:38:39square brackets codename and next.js is not going to run this function for anything which

18:38:45does not match this routing pattern i mean that's that's exactly the point of routing pattern right

18:38:50so you need no validation nothing here you know that this will work and this will have a valid

18:38:55value if it does not that's a nexus bug not yours so anyway you have something like this and this is

18:39:06actually interesting because if you go ahead and give it a query parameter you're going to

18:39:11have query is 2 right here now if we take a look you're going to see right here that we probably

18:39:24okay yeah we are losing the context that's why so refresh and you can see

18:39:31that query right here interestingly gets all the stuff that is your dynamic segments of the url

18:39:40as well as the actual query parameters which are the question marks

18:39:45uh which are the syntax followed by question marks right however the patterns right here

18:39:53only get the dynamic patterns right so here's an interesting finding which i

18:39:58did the other day and that is if i try to change this to code damp the query parameter

18:40:05the actual query parameter because you know this question mark and stuff is actually called query

18:40:10parameter then it would actually just drop the query parameter at all from the query

18:40:18right so this is likely a bug i don't know maybe i'll report it but now if you technically

18:40:26want to extract this two you have to do it yourself right because the request.query.codam

18:40:33um favors the actual um sort of dynamic route before the actual thing which it should have

18:40:44supported but nonetheless this works fine for anything else if i have an underscore right here

18:40:50you're going to see we get a code down under score at 2. so that's fine but yeah that's

18:40:55something to consider so yeah we have a bunch of different attributes as well params just

18:41:02like i discussed would only contain the dynamic segments of the url not the query parameters

18:41:09we also have preview i think we do not have a preview here which is an interesting property

18:41:14or maybe we do i don't know preview do we have a preview no but we're gonna discuss about preview

18:41:21and preview data and all that stuff later on as well but that's pretty much it that should get

18:41:25you started that should get you familiar with get server side props at least one use case which i

18:41:32can tell you which i also use at codedam.com at the moment is that you can generate sitemap.xml

18:41:42like this right so you can generate sitemaps on nextgs websites and return the response

18:41:49as xml you might think this is a static file but this is actually a dynamic next.js file which is

18:41:56server-side rendered because obviously if you're not using server-side rendering you can pretty

18:42:01much just return html react response nothing else you can only return json and all that stuff

18:42:08without being inside api folder you can only return that if you're using its oversight props

18:42:14so anyway that's pretty much it for this video let's just keep it to this one

18:42:18that is all and i'm gonna see you in the next one really soon hey everyone welcome back and in this

18:42:24video let's just go ahead and take a look at what return value of get server side prop looks like

18:42:31so you're gonna see that we return an object with just props which is a little bit boring but you

18:42:38can make it a little bit more exciting by having a bunch of more properties so not only props you

18:42:45can return a different form of value as well so what you can do is that instead of returning props

18:42:54if you return something like redirect and then you can specify a bunch of mode parameters

18:43:01this route will actually perform a redirect on that particular url which is pretty cool

18:43:06and which is something you can do with a custom next.config.js file as well which you're going to

18:43:11see later on again but this is one way to go about so you can say destination destination

18:43:19as uh i don't know like google.com and then you also have to specify permanent now this permanent

18:43:27is an option which is basically uh responsible for setting http status code on your browser right

18:43:38your browser considers 301 that is 301 as a status code which means that will

18:43:46permanently map inside its memory that this url always maps to this one and 302 is a temporary

18:43:53direct so if you set this to false it's going to perform a redirect with 302 right so let's

18:43:58just take a look at that first of all so i'm going to go ahead and refresh this page right here and

18:44:06okay so we are not actually returning the value at all so let's just go ahead and refresh it now

18:44:13and we have a little bit of problem i think the server died anyway let's refresh it again and

18:44:22now you can see that we are redirected to google but if you take a look it actually it actually

18:44:28responds with 307 not 302 but anyway you get the idea right but if i switch this to true

18:44:35it's going to perform a 301 redirect so if i go back and refresh this you're gonna see now well

18:44:44again i'm actually wrong it's three zero eight and three zero seven back in the day when i remember

18:44:51uh it was three zero one and three zero two this at this i mean these are also like these are

18:44:56also these will be also valid redirect permanent and temporary but there might be a little subtle

18:45:02difference in the rest uh guidelines depending on um i guess the method and the data which you want

18:45:10to continue but anyway the point being that this means permanent redirect and that means

18:45:16now chrome your browser whatever unless you clear cache or anything it's not gonna

18:45:23look up for the server right before it actually hits that free direct so you can see it saves me

18:45:28from this cache now so even if i go ahead and do a false right here and if i go ahead and visit this

18:45:35url you're gonna see that it redirects me with 308 only and even if i go ahead and remove this

18:45:41all together with the props which should now technically render content and if i visit this

18:45:46you're going to see i'm basically screwed right unless i clear my disk cache so that's what

18:45:52permanent and temporary direct means and that is why you should be careful about them because

18:45:58by mistake if you set a permanent redirect to a url and people started wizarding them and if you

18:46:04wanted to make a change you would not be able to go ahead and refresh cash on their browsers right

18:46:11so you might end up in a bad state so anyway that's one way another way is another thing

18:46:18you can do is have a not found right here so once you have now not found as true this is basically

18:46:24similar similar can speak similar to 404 as the status code and the typical standard next year's

18:46:32template so if you go ahead and actually of course i can't really use that url unless i clear my

18:46:38cache which i'm not interested right now so i can just go to page one so now you can see we get a

18:46:44404 and a 404 status quo so these are like you know you just you can just go ahead and uh let's

18:46:50say fetch from db and you see that hey that does not exist then if no record exists then return not

18:46:59found right something like this otherwise you're going to continue and return props right here

18:47:06and just like us just like it you know demonstrate with props you can have something as a prof value

18:47:13return you can and whatever you return as a prop you can grab that right here so you can say create

18:47:21prop start something right so if i have create this you're gonna have create one

18:47:28next app as the title of the page right so if i refresh this you're gonna see record is not found

18:47:36yep sure so if i refresh this you're gonna see we have the title as create one next app

18:47:41right so yeah that's in a nutshell how uh nextgs get server side props method would overall work

18:47:51like just like i said it could be an async function you can be pretty much fetching

18:47:56data from different apis feel free to use fetch here you know you can do data is equal to await

18:48:03fetch something like google.com and remember because you're running this inside note context

18:48:10this is perfectly fine you're not gonna have any same origin policy stuff so you can have then t

18:48:17t dot text and then you can say slice 0 to 200 for example and now you can just go ahead and say pre

18:48:26and then props dot google first 200 yes something like that you know i

18:48:33don't know i just completely made that up very quickly and i can say

18:48:41yeah that's pretty much it right so i hope that works let's see

18:48:48right so it kind of works right because you can see right here you get the first 200 characters

18:48:55from the google home page which looks fine so anyway that's that's how you're gonna make it work

18:49:02and yeah that's pretty much it for this video i'm gonna see you in the next one really soon

18:49:09so what is going on everybody welcome back and in this video we're gonna be taking a look at

18:49:15get static props in next year's big big thing um you know a lot of power for next year's comes from

18:49:25this method so i'm gonna get rid of get server side props we might probably see how we can use

18:49:30both of them together later on but for now let's just focus on this bad boy called get static props

18:49:38super powerful method and super powerful concept as well which you know borrows a lot of learnings

18:49:45from the architecture of client cdn and then servo right so um you know if you are in the in the loop

18:49:58there's also this neat framework called remix although it's paid it's premium but remix does

18:50:05not follow this approach remix follows the traditional approach next js has come with uh

18:50:12sort of a new thing i won't really say it's new gatsby also uses it but it's a model

18:50:19where essentially what you're trying to do is a

18:50:25you are trying to build pages on build time right so what does this mean first of all

18:50:34this means that you as an application let's say you have

18:50:41uh 20 static routes right and 35 dynamic routes dynamic means that you have those in this form

18:50:52now these 20 static routes are simple right you just have to create an html and json payload out

18:50:58of them and just store them on the disk whenever somebody visits and just bam

18:51:03them with that static files that's simple this dynamics section what happens is that assuming

18:51:10that these are not server side rendering what you can do is you can build them ahead of time

18:51:18for example let's say you're running a e-commerce store simple e-commerce store with 35 products

18:51:26right and you have a database which contains these 35 products so instead of using get server

18:51:33side props and just fetching the product again and again for every single visitor

18:51:38in individually what you can do is that just build them ahead of time sure it might take you you know

18:51:45a couple of minutes on your continuous integration deployment servers but it will be worth it

18:51:51why because you have now uh complete static builds of those dynamic sort of pages as well

18:52:00that's one way another way which is interesting and where the power of get static prop lies

18:52:07incrementally or you know lazily build pages right or rather build a website which consists of pages

18:52:19here what happens is that out of your 35 dynamic routes ahead of time ahead of time that is on the

18:52:26build time you build zero pages right and whenever somebody visits let's say your store slash let's

18:52:34say this dynamic route is actually store slash id right so whenever somebody visits store slash one

18:52:43you run get static props just like you would run get server side props right so you would run get

18:52:50static props like get server side props but how get static props differs from this is that

18:53:01it is intelligent you can tell it to store this result now because you know let's say you had 35

18:53:09million of these routes right it's not feasible to build 35 million pages upfront so you can say that

18:53:16hey we're not going to build anything at all and whenever somebody visits it then we'll just build

18:53:21that page and keep it in the cache or keep it in the memory so when somebody was a store number

18:53:28uh let's say 999 you build this page again get static props gets called and

18:53:34you know it is saved for other people so now when somebody visits store 999 again what happens is

18:53:45that this is served served scrved immediately as uh you know a static build static page

18:53:56so cool because now a single visit a single visitor has to pay for that cost of building it

18:54:02once because you know if this is involving a lot of database calls and here and there this

18:54:07might take a couple of seconds and once a single visitor has taken that load on himself or herself

18:54:15a million other people who visits this page will have immediate results right because this

18:54:20page has already been built so that's how in a nutshell you can make use of get static props

18:54:26in the next video from the next video onwards we're going to be learning about different

18:54:30ways how you can block rendering how you can fall back to a loading sort of rendering we're

18:54:35going to discover you know just talk about all the stuff from the next video onwards so don't

18:54:40worry about that so yeah that's pretty much it for this video i'm gonna see you in the next one

18:54:46really soon hey everyone welcome back and in this video let's just discuss about get static props

18:54:52but technically so we have seen get static props how it works internally and on a theoretical level

18:54:59but let's just see what this function consists of so first things first i'm going to go ahead

18:55:04and rename this back to index.js because there's a major difference when you're using getstatic props

18:55:10in a dynamic versus a you know just a string based route so what i'm gonna do right here

18:55:17is just gonna return props uh something like this and i'm just gonna console.log context

18:55:23now surprisingly what you're going to see right now if i refresh this

18:55:28you're going to see if i go to the console we have only locales locale or whatever how you pronounce

18:55:36it and these three props present or these three values in the context present where are the

18:55:43requests and response and you know all that good stuff query and patterns where are those values

18:55:50well you see when you are using get static props in a string based route that is you know in a

18:55:57static route what next chase is going to do is it's going to automatically on the build time on

18:56:04build time it's going to generate a static html static html plus json payload of this

18:56:13particular page so that it never has to execute javascript again right and how it can do that

18:56:23well because you know you have just have a single route and given that next guest is not

18:56:28providing you with request response for adding any dynamic stuff and adding any funky stuff

18:56:34depending on how you are accessing it with with what headers and what cookies

18:56:39uh next years can safely generate a static html and a json payload right so if you are looking for

18:56:46adding any dynamic stuff here that is probably not the best option the best option

18:56:51again would be get server side props however let's not you know let's not get completely

18:56:57discouraged on this because there is a good option there's a good way to get this stuff

18:57:03which we're going to see later on but for now just realize that get static props is pretty much

18:57:09um a place where you can perform db calls you know network requests without being course binded

18:57:22any sort of stuff require require files which is js common js syntax or dynamic imports

18:57:31whatever you want to do you can do all that stuff right here right and once you're done with that

18:57:36once you return it as a props of something true again once you do something like this

18:57:43you can access this uh just like usual right so this is this is more like of a you know

18:57:51you are generating a page but it requires a little bit of dynamic stuff i can give you a

18:57:56quick example for this is that for example let's say you are creating a page where you want to show

18:58:02number of registered users you have right so you can create a db call here await get db and

18:58:12you know you can create a db call and you can fetch user count the weight db dot total users

18:58:21right something like this and then you can return this user count like this and you can just have a

18:58:27user count here sure it will be generated on the build time and we generated once but you know when

18:58:34you are building it again or we'll see another way when you're building it again you can pretty much

18:58:42you know just go ahead and show the user your total number of registered users on the

18:58:49uh without actually hitting the database on every single request right

18:58:53so if you have a million visits on the website you just have to hit the database

18:58:57once when you're building it and that's it why because rest of the visits are automatically

18:59:04served directly from uh the cash or the the static build which is already there

18:59:12all right now comes the interesting part that is the re-validate option so next js comes with a

18:59:20very very interesting option called re-validate what does this mean this means that the seconds

18:59:29which you supply here let's say i have 10 seconds right here the seconds which you supply here

18:59:36this will attempt to create this page again in at most 10 seconds let's see what that means so

18:59:47let's say this is one two three four five six seven eight nine ten right these are 11

18:59:5612 13 14 15. these are let's say 15 requests which are coming on our websites right so these are

19:00:04i will say these are requests request right and let's say this is the time at which those requests

19:00:13came so i'm going to say this came at zeroth second this came at uh i don't know fifth second

19:00:20this came at six second this also came as six six six this came at eight this came at ninth ninth

19:00:30this also came at nine this also came at nine this came at 10th this came at let's say 15th 15th 15th

19:00:38all right so what's happening now is that once once we build once we build this particular page

19:00:48let's say the build process is done we have created a single page we're gonna have

19:00:52version right so we're gonna have let's say version versions as one two three four

19:00:58five as the incremental versions of the things right so the version one is the build version

19:01:04of the page version two is when the page is again built thanks to this revalidate parameter version

19:01:11three is again when it's built next version right so let's see which user will see which version

19:01:18so what's gonna happen on the first that is the first visitor because it

19:01:25he or she visited at the zeroth time they're gonna see version one the fifth second we'll

19:01:31also see version one because we have ten seconds as the parameter here the six will see one

19:01:36uh this will also see one one one one one everyone would see one up till this point

19:01:44now what's going to happen is that this person right here which arrived at the 10th

19:01:50second is also going to see first version right and all these versions are shipped very very

19:01:58fast to the end user why because they are already generated they are already built of html plus json

19:02:05so you know they are just sitting on the disk just to be served right and if you are using

19:02:10versal or anything like that they are better they are on cdn's so all of them would see version one

19:02:18but something would happen here something will happen right something magical will happen at

19:02:24this point because 10 seconds has passed and next years has just released received a request what's

19:02:33going to happen is that next year's backend will start creating the new version of the page

19:02:41that is it will start calling the subway dv it will get user count again it's gonna create the

19:02:46page again it's gonna uh you know update the html and json so assuming that it happens at

19:02:55let's say it completes at 12 second let's see if you have a visitor at 11 second if we have a 12.5

19:03:0312.5 visitor at 11 second right let's see i'm a little confused with the spacing and everything

19:03:11but let's say this is the point where it gets completed right so this visitor would still see

19:03:18the version one why because this is not ready yet however once it's ready now we are shipping

19:03:26version two so this person would see version two this will see version two version two and so on

19:03:31right so i hope this gets the point across this parameter right here this is interesting because

19:03:42what if the request never came after the ninth second let's see what happens in the in that case

19:03:51well you see that next year says that hey i would attempt to revalidate the page

19:03:58once at most in this duration so what does this mean is that it is saying that i will at most

19:04:08generate only one page in 10 seconds it's not saying that it will generate one page

19:04:17every 10 seconds there's a difference it's sync it will generate one page at most uh you know

19:04:24in 10 seconds so this means there is no timer on the back end which is running every 10 seconds

19:04:30and it's triggering a page update nope that's not that's hap that's not how it happens this

19:04:35revalidate parameter you can think of something like this it can say that hey i reval last

19:04:41revalidate re-validate is let's say utc timestamp zero why not let's say uh once we have this fifth

19:04:52this request coming up right here so we're gonna have last revalidate as still zero right because

19:04:58well this request does not make any change but next year is checked on this request

19:05:03then again on this request this request on you know on the ninth request till the ninth request

19:05:09last revalidate validate is zero and you can you can just go ahead and maintain a now counter as

19:05:16well now five now nine right so next year says that hey now minus last is less than

19:05:2410 so i'm gonna skip now minus last is less than 10 so i'm going to skip now minus last is

19:05:32less than 10 so i'm going to skip right now what if the next request

19:05:41comes after an eternity let's say at hundred time stamp so what here what happened here nothing

19:05:52nothing happened here that means nobody requested and no page got generated as well no page got

19:05:58refreshed as well because nobody visited this route next js never checked the last revalidate

19:06:05and the now counter that means it never took the difference to check if it has to revalidate

19:06:10and that means this function never got called so now at this particular point next js is

19:06:15gonna still serve version one to the user but it's gonna see now is now minus last is greater than 10

19:06:27therefore revalidate and for the next request onwards or assuming that that completes perfectly

19:06:33it's going to say last value date is 100 now is 102. so you know 102 minus 100 is less than 10

19:06:42so i'm going to skip so i hope you understand how exactly this revalidate parameter is working and

19:06:49how uh you know this at most statement works this is super super important

19:06:54to understand because um you might think if you have a smaller value here you might think

19:07:01uh you know you're bombarding your server every single second or something but nothing like that

19:07:06is happening right in fact if your website let's say if you are running a news website or you know

19:07:13some life counter this is actually a pretty solid uh you know a way to go about because

19:07:21let's say you have 10 million or like not really 10 million let's say you have 100 000 people per

19:07:28second requesting this page so if you have server side props gets oversight props that bad boy is

19:07:37gonna perform a hundred thousand requests on your database every single second which is

19:07:43bad right which is bad bad depending on you know what your server configuration is and how you have

19:07:50configured load balancing and everything however if you are live with 100k requests a second

19:07:58and you have get static props with one second revalidate

19:08:04oh boy you are in luck because now you just have one request per second on the database

19:08:14super awesome consider this you are designing an architecture

19:08:19where you are getting a hundred thousand requests a second versus one request a second

19:08:24and uh you know at most people will be delayed by a single second of information here right so if

19:08:31you're maybe like if you're creating a website or a life counter for cricket or anything i

19:08:37mean that's a pretty solid deal right because you know you can afford to have a single second delay

19:08:43versus whenever somebody is visiting or refreshing your page they get pretty much you know your

19:08:48server gets pretty much down because of so much load so i hope that puts things in perspective

19:08:55a little bit how this is helpful how this works and all that stuff we're going to be discussing

19:09:00a little bit more on get static props and the additional function which it brings in in the

19:09:05next video so that is all for this one i'm going to see you in the next one really soon

19:09:12so what is going on everybody welcome back and in this video let's just take a very quick look at

19:09:17a get static props example before we move forward so i have created this simple simplest as

19:09:23couldn't get more simple user count uh probably a bad name but i have deployed it so anyway so this

19:09:31is a math.random variable and you just display it on the home page right on the index.js and

19:09:38this is deployed on versailles right we're going to come to deployment in the end but

19:09:44i have deployed this on versal and i have also opened this in the local

19:09:48as a local server now one thing you have to remember when you're developing with nexus

19:09:53locally next chase is gonna run get static props every single time on every single run

19:10:00so if you refresh you're gonna see this math.random value changing every single time right

19:10:05as you would expect because well it is running on every single one so this value gets updated

19:10:11every single time that's why we are getting a different value however on production because

19:10:16we have revalidate parameter it's gonna well run once but it's gonna revalidate the page at most

19:10:25every five seconds just like we discussed in the last video so now if i refresh this you

19:10:30can see well if i refresh if i keep refreshing it you're gonna see the value is not changing right

19:10:36however if i refresh it after five seconds for example the value updates and now it's

19:10:42gonna stay same for at least five seconds then it updates and it's gonna stay same so you know

19:10:48you can see how this is pretty much working and that's pretty much all i wanted to show in this

19:10:54short video so that is all for this one in the next one we're going to be discussing about get

19:11:00static parts again just like i said which is again a little bit of extension of get static

19:11:05props itself so that's all for this one i'm gonna see you in the next one really soon hey everyone

19:11:11welcome back and in this video let's just go ahead and take a look at get static parts right so this

19:11:18is an indi additional method which is sort of handy with get static props and actually mandatory

19:11:26and i'm going to tell you why this is required consider that if you have a route something like

19:11:32um i don't know shop id right and you're trying to implement get static props on that well

19:11:40first things first you need the id parameter to fetch the stuff right

19:11:46to fetch that particular information against that so first thing is that we need patterns somehow

19:11:53in get static props second thing is that you know next year's like i said

19:12:02likes to run get static props on build time right so if you even if you get you know some

19:12:13sort of way of using these patterns and then you know doing this doing data fetching using

19:12:20patterns you know if you want to probably build a part of your website on the build time

19:12:27there is no way next js can know what what ids this will take right it might take one

19:12:33two three four five till 100 it might take some strings and it could be anything right so you need

19:12:39next shares you need a way for for informing next that hey i want maybe i want these these pages

19:12:47built on the build time and then maybe we can fall back to this particular approach

19:12:52which we talked about that you know people will come and then we'll build and store it and then

19:12:57we'll just make that happen so in order to make that thing possible we have a function called

19:13:05get static pages right so this export function this get static pages

19:13:15is a function which is going to allow you not really pages or spots

19:13:22right it's going to allow you to provide that information to nextjs that means you're going

19:13:28to return certain value from this particular thing and precisely we're going to return

19:13:34parts as an array this is going to be a value it will contain information on what all pages

19:13:41you would want to be built at build time right ahead of time and anything else which

19:13:52is not present inside this will either 404 or will be built dynamically depending on

19:13:58a bunch of other parameters as well but first of all let's see how you can make use of this

19:14:03so this will be an object an array of object right and right here you're going to specify

19:14:10you're going to start writing patterns and then params will also be an array of object

19:14:16patterns p-a-r-a-m-s and params right you're going to start writing here

19:14:23and yeah the biggest requirement the biggest biggest requirement is that you

19:14:28need this route to be dynamic so i'm going to shift this to id right and now you can say id

19:14:35which should match the name of your file or the dynamic part of the segment which you're targeting

19:14:40and then let's say uh product one right then you can have an id of product two for this one

19:14:49and then maybe like id of product three for this one right so you have all these parts

19:14:56available to you and if you just leave it like this what's gonna happen well you have

19:15:01to specify another parameter called fallback let's say you have a fallback of false so in

19:15:07this particular configuration when you push it to production when you run next build

19:15:12what's going to happen is that on the build time next years will run get static props

19:15:19with product one well not exactly product one but you know you get the idea i'm gonna tell you you

19:15:26can extract you know patterns from this context as well so it's gonna run it with something like

19:15:38patterns id product one right that's that's more like it with a bunch of more options

19:15:45it's gonna run it with product two it's gonna run it with product three

19:15:49this is gonna spit out some html plus json this is gonna spit out some html plus json this is gonna

19:15:55spit out some html plus json right next test is going to run all this on the build time remember

19:16:01this is all happening on the build time and we finally store all on disk cdn whatever right

19:16:09and then serve it immediately whenever somebody comes this is because of fallback faults right

19:16:16if you have if you have fallback true something interesting happens well we all obviously we do

19:16:25the same thing again but this time actually let me let me just discuss fallback falls again but

19:16:32i guess we did not complete it so now if you come to a page which is something like shop id or like

19:16:40product id product 4. if you come to this and remember we have fallback false this will

19:16:47go 404 not found why because you mentioned that hey i don't want any fallback for any

19:16:55non-supported page right that means you're on your own you're going to get a 404 automatically

19:17:03now if you have fallback true something interesting will happen on this point

19:17:08when somebody visits this this route next chase is going to see that hey i don't really have an html

19:17:15plus json payload for this particular route but you know get static parts actually told me that

19:17:23the fallback is true so maybe i should go ahead and ask get static props what's up so when you

19:17:31visit this what's gonna happen with fallback true is that nextgs is gonna load the page

19:17:38with uh you know you can get the nexus router use router you can import the nexus router use router

19:17:49you're gonna have a router that is fallback property set to true and i'm not really

19:17:55entrusted into this into explaining this why because first of all this has already been

19:18:00explained in the basics course and secondly there's a better option now with next shares

19:18:05so right now as long as this is true on the client side right now uh react uh not really react

19:18:16next js uh get static props is executing right and the moment it becomes false that means you're here

19:18:24get static props has executed and you have the data from the props automatically and this will

19:18:30be stored again you can think of it getting added sort of getting added like this so that it does

19:18:37not have to build again right that happens to fall back true so let's take a quick example

19:18:44on this so i'm going to go ahead and return a loading right here and i'm going to say loaded

19:18:54here this could be like h1 only why not and we have product one two three four which is

19:19:01perfectly fine i think we just need to import the router import use router from next router

19:19:11i think this is a default yeah not really right so once we have that let's just go back

19:19:17to the browser and go to product one hit enter you're gonna see we get if i refresh this we see

19:19:26loaded because we already are generating product one automatically if i have product two

19:19:34we see loaded which is fine product three and four will also show loaded

19:19:39but if i go ahead and visit product 5 you're going to see that if i refresh this for a split second

19:19:46i get this loading right you can see that that does not happen with product 4.

19:19:52product 4 loads immediately but product 5 right here we get a split setting split second loading

19:20:00why because if you go to xhr and refresh this you're going to see product 5.json actually is

19:20:08uh loaded a split second later i'm not sure if i can show that let's toggle to slow 3g and see

19:20:16so now if i refresh this you're gonna see i get loading for a little bit longer let's hope

19:20:24actually it's downloading the whole js bundle as well in the development so that's why it's pretty

19:20:28slow but what you're going to see eventually is that the product 5.json is dynamically generated

19:20:36when you have the fallback true and it does not wait for it being generated it's just gonna

19:20:43throw something down the wire right so that's something the client can see at least

19:20:48something which is kind of bad if you want to have a full blown experience on the first load right so

19:20:55you can see it shows loading for a while and then we make a request and then it shows loaded right

19:21:02so how would you make this uh a seamless experience in terms of uh you know for example

19:21:09if you take a look at product four product four loads immediately just like we discussed right

19:21:16so how would you make it same for product five well there's a new mode called blocking right here

19:21:22and what fallback blocking would does is that it will not send any response at all unless

19:21:29the get static props has executed right so now if i refresh this on product five hit enter you're

19:21:37gonna see we no longer get loading anymore and the reason for that is that you know this actually

19:21:44runs uh the static props first of all and then sends it down the wire that means is fall back

19:21:51is never true so the pro of this pro of blocking is that no flashes flashes of uh

19:22:06loading or loaders or you know missing content

19:22:13the con of blocking is again of course the first visitor and only the first visitor right because

19:22:21you will be storing it on the disk and all that stuff the first editor will have a little delay

19:22:28that's it which is not a big of a con to be honest if you think about it so that's that's pretty much

19:22:34it so in most of the cases you would probably want to use fallback blocking unless this is very

19:22:40very slow right unless this is very very slow you would probably want to use always blocking

19:22:47so yeah i mean that's pretty much how uh get static parts work very simple

19:22:52method not really have a lot of bells and whistles just parts and fall back mainly

19:22:58and the fallback also i would highly recommend if you do not know upfront all the parameters you

19:23:05can set it to blocking a very common convention is to have empty parts here and have fallback

19:23:10blocking so that means now every single page route would be created on the runtime and then

19:23:16stored that means it will not be created again and again and then stored and will be refreshed

19:23:24depending on your revalidate parameter so i hope now you can see all the parts coming

19:23:29together and building together right so that is pretty solid infrastructure and framework

19:23:34which next year's provides you out of the box so yeah that's pretty much it i think a lot

19:23:40of knowledge a lot of concepts a lot of things if you are learning it especially for the first time

19:23:45so take some time you know visit this video again if you want and you should

19:23:50be done with it so that is all for this video i'm gonna see you in the next one really soon

19:23:58hey everyone welcome back and in this video let's just go ahead and take a look at what preview mode

19:24:05is in next js right so we have looked on gets oversight props and get static props and the

19:24:11get static parts method but there's also something known as preview mode in nextgs which kind

19:24:19of sounds like what it does but let's just go a little bit deep into what exactly it is and how it

19:24:25works so in order to do that what i'm gonna do is create an api function let's say enable preview.js

19:24:34right so you know in apis you know how this works you just export a function like this and you would

19:24:41be able to set the response status code and all that stuff in an express like way right it comes

19:24:47with a express like json sort of method attached to the response object and so on so instead of

19:24:56you know you can do all that stuff but inside of your api response if you do something like res dot

19:25:05set preview p-r-i-p-i-v-a-e-w data and you pass in an empty object what's gonna happen

19:25:14is that next year's is gonna set set some cookies right so this method internally sets some cookies

19:25:23on the response so let's see what that is so if i go to the browser and if i go to api slash enable

19:25:33enable preview and hit enter you're gonna see of course we get the response back

19:25:39but if you go to the dev tools inside the application cookies you will be able to see that

19:25:46there are a couple of cookies which are set you can see the first one is next review data and the

19:25:54second one is the pre-render bypass right if you take a look you're gonna realize that this looks

19:26:01awfully familiar to a jwt token right so we have two parts here the first one is next preview data

19:26:10and just like i said the second one is pre-render bypass next preview data is a jwd token right so

19:26:18you could probably just copy this next review data is jwd token and this one right here pre-render

19:26:25bypass it's just a random hash right random idea random hash whatever you want to call it

19:26:31right so what's happening here well you see if you try to decode this data right here

19:26:38if i try to go ahead and take a look here you're gonna see that the base64 encoded part which is

19:26:44the central part if you do a b2a of that not really b2a a to b you're gonna see you get

19:26:51something like this right which again looks like a bunch of encrypted data and actually i'm not sure

19:27:00what this data is exactly right i'm not sure of the encryption but the point is that you can pass

19:27:06some data right here so you can write something true and if you go ahead and refresh this

19:27:12the stuff which gets set as the cookie inside this next preview data is actually that object

19:27:20something is true right so if you do a to b here i mean you won't be really able to see

19:27:26it because that is using some sort of encryption even in the data parameter but you can see it has

19:27:32got an expiry date with it uh not really this is not expiry it's just the time when it was created

19:27:38right so let's see if this is correct and yep this sounds about right yeah so what's the use of this

19:27:49well you see that preview mode preview mode can technically be used to

19:27:59have the development like behavior of get static props now what do i mean by that let me just

19:28:06elaborate on that so if i have export function get static props right and if i return a prop of

19:28:14props off you know number as uh math.random and let's say i have fallback as blocking right and

19:28:29this is this is not the place to put it it should be export function get static parts return

19:28:38pages is this and fall black fallback is blocking

19:28:42so once i do that i can use props dot number and get rid of this

19:28:48right and now if i go ahead and refresh this particular two for example and we have some errors

19:28:58extra keys returned yeah this should be parts not pages refresh and now you can see that every

19:29:06single time you refresh you see you get a new response now the reason you get a new response is

19:29:13that get static props is called on every single page refresh on development this is important

19:29:21right even if you have a revalidate parameter here for example revalidate uh 10 seconds

19:29:28you're gonna see that you get a new response on every page load now the reason for that is

19:29:33you're running in development mode if you push this to production and let me just go ahead and

19:29:38clear the cookies first of all let's do it from devtools so that you are you are able to follow

19:29:44if you want to i'm going to go to application cookies and i'm just going to clear them off

19:29:49right so if you go ahead and refresh still refresh it you're going to see that you get a new

19:29:55different response on every single payload page reload reason for that is that get static props

19:30:01this is called every time in dev mode so preview mode is kind of like dev mode on production

19:30:13what does that mean that means that get static props will be called every time as long as

19:30:21preview mode is enabled all right so let's see what that means by

19:30:28actually uh you know deploying this on production and i'm gonna set a revalidated parameter to like

19:30:3560 seconds so that we can have a little bit of space in between of uh seeing things

19:30:47all right so i've just deployed this url on a versal domain and what i'm gonna do is just go

19:30:54to a random id right so if i go to let's say slash two and if i keep refreshing this page for example

19:31:00you know just leave that first blip but now if i keep refreshing this page you're gonna see

19:31:07that it pretty much stays the same value right i'm refreshing it again and again

19:31:11and it stays at the same value the reason for that is that once it generates uh you

19:31:17know match.random number for the slash two route that is uh that how time on it would pretty much

19:31:26not run this function again right because nexus says that hey i've already generated

19:31:31um the particular page for that particular route so let's just use it directly from the cache

19:31:37from the disk it would it would generate it if i keep on refreshing it and it hits the

19:31:4260 second limit which we have already discussed in the previous video but it will only generate

19:31:47it once at most once every sec every 60 seconds now let's say this was something of a blog post

19:31:55preview right you're editing your blog post with a cms like ghost or something and then you want

19:32:01to preview it so this is a this is a difficulty right with next yes because even if you try to you

19:32:08know if you're trying to set it too low then you are just hitting the um you know your server too

19:32:15much if you get a lot of traffic on your blog even though if your content does not change that much

19:32:20if you're setting this too high well you cannot really work with with a sort of draft preview mode

19:32:28from your cms so to fix this we have the preview mode which you can use this is like one use case

19:32:34so what i'm going to do is i'm going to go ahead and hit this enable preview api url so

19:32:39let me just go ahead and open the cookies part as well so right now you can see we have no cookies

19:32:45and if i refresh this it stays on the same particular value now let's just go ahead and

19:32:50hit api slash enable preview hit enter and you're going to see that it immediately sets two cookies

19:32:58next preview data and pre-render bypass which we have already talked about now if i go back to

19:33:06slash 2 right here what you're gonna see is that on every uh let me just keep that open is that

19:33:13on every refresh we are getting a new number even though this is a production domain right

19:33:19even though this is a production domain we are getting a new number on every refresh and if you

19:33:23can observe the page response times are a little bit slow because it has to like you know run this

19:33:30function again render the tree and then pass it so once you have preview mode enabled it will always

19:33:38always always run this function right now the beauty of this function is that the beauty of this

19:33:44feature is that if you do not have the preview preview cookies for example if you are a visitor

19:33:49of the site it will just work as normal right so you can see uh just that was just an update to the

19:33:58page but if you keep on refreshing it you're gonna see you get nothing

19:34:02but the moment you try to enable the preview again and go back to to keep on refreshing

19:34:09looks like we did not enable the preview mode refresh

19:34:14yeah so here we go needed a hard refresh so once we do that and now if you return to two again

19:34:21you're gonna start seeing different numbers again because this is just like i said renders

19:34:26it automatically every single time irrespective of what configurations which you have here

19:34:33so yeah this is like preview mode could be useful if you're developing a cms-like application

19:34:38where you want to have specific access uh you know real-time access to specific pages um but

19:34:44that's yeah that's pretty much it if you're not developing some sort of dynamic content which

19:34:50is linked to a gui in terms of editor or something this will probably not be required but nonetheless

19:34:57you should know about this so that is all for this video i'm gonna see you in the next one hey

19:35:02everyone welcome back and in this video let's just take a look at what dynamic imports are in next.js

19:35:09so dynamic imports is pretty important and interesting feature of next year's which you

19:35:15might encounter a lot of times if you're if you are working with npm packages and

19:35:20things which are browser environment specific right which require browser environment so

19:35:27what that means is that first of all dynamic import means that you

19:35:31are importing a piece of code on the runtime dynamically right so the first thing is that

19:35:37obviously it will not be included inside the html of your page it will not be

19:35:45server side rendered on the first load right so the first communication for example

19:35:52let's say i have a div right here and if i have dynamic h1 here and if i have p hello world let's

19:36:01do a quick uh you know demo of this so i'm going to have a dynamic h1 i'm going to explain you the

19:36:09syntax for this but just bear with me for a while here so let's say if i have dynamic

19:36:16h1 as the component and we would also need dynamics from next dynamic

19:36:25dynamic right so what you're trying to do here is that import this dynamic h1 on runtime

19:36:34so if i do something like export default function h1 and then just to h1 hello world

19:36:43so what do you think would happen so if you take a look at this you're gonna see you get an h1 and a

19:36:48p just like um you know you would expect to get right and if you go to let's say the sources or

19:36:55maybe like yeah the networks tab you're gonna see that this one.js file is the actual chunk

19:37:03of this dynamic h1.js right so what does this mean is that for example if you had something like um

19:37:15let's say a compute which is like an expensive compute right i don't know add it.fill

19:37:25or maybe like not add a dot fill at a thousand dot fill zero dot map uh or dot for each x

19:37:36console.log x right if you had something like this i mean this is this is ridiculous but just

19:37:41to give you an example and if i go ahead and refresh this now you're going to see

19:37:46if i go to console if i go to sources if i go to network you're going to see inside

19:37:52the one.js file well if only if we could just look inside the cival but let's see if i could

19:38:00if i do a console.log you can see that that bit of uh you know code execution is present

19:38:08inside one dot js which is a different file right if i go ahead and remove this

19:38:15as a dynamic import if i go ahead and import this in a regular way from let's say like this

19:38:24right if i do something like this and hit refresh you're gonna see that there is no one.js anymore

19:38:30there is just this uh console.log not even 0.js i think inside index.html

19:38:38will get probably yeah inside index.html you can see index.js you can see the single file which

19:38:48ships with the whole uh bundle of stuff right now this is obviously not the production build but

19:38:54inside production build as well you're gonna not see any different uh request with dynamic import

19:39:01although it will render it on the server you know if you go ahead and take a look refresh and go to

19:39:09page source you're gonna still see hello world right here it is still rendered on the server it

19:39:14is server side rendering but there's a big but the javascript bundle of this the rehydration you know

19:39:22the when the react downloads the chas and tries to add all those click handlers and everything that

19:39:29piece of javascript is only downloaded um when it is required right so what's the use case of this

19:39:38well one use case could be that let's say you have a user panel right and let's say you have a

19:39:47or maybe like not really user panel but authenticated panel and you have non authenticated

19:39:54panel right and you do the stuff so you know leave the uh compute part

19:40:02already like even if it is a lot of javascript that will also be good for us so if you have uh

19:40:08authenticated here and non-authenticated what you can do in react is that you can say hey

19:40:18if user is authenticated then show him this panel otherwise show him non-authenticated right

19:40:25something like this you can do something like this and the way it will work is that if the user for

19:40:31example on server let's say the user is considered always authenticated let's say if the user is

19:40:38authenticated you're going to always show this component and if the user leaves your website you

19:40:43can always keep on showing this component and you will never show the non-authenticated component

19:40:48how does this help this helps in the way that you never really download this non-authenticated panel

19:40:54bundle right so that's a huge um data saving if this is a big file if this is a big js file

19:41:04so yeah that's pretty much it on the dynamic import without dynamic import with server-side

19:41:10rendering there's also a variant of without server-side rendering we're going to take

19:41:14a look at that in the next video but i hope this gives you context on how dynamic imports

19:41:19exactly work how the split split the files into different chunks and how they are

19:41:25still server-side rendering but with a different approach right that is um the javascript which uh

19:41:34enables the dehydration and everything in the component is downloaded differently from the

19:41:39main bundle so yeah that's pretty much it for this video i'm gonna see you in the next one

19:41:44really soon hey everyone welcome back and in this video let's just go ahead and take a look at

19:41:51server-side rendering disabling of a server-side rendering in in the dynamic import section

19:41:59so what happens is that just like i told you that you can pretty much in the last

19:42:04video initially i told you that you can pretty much use this feature to render

19:42:10you know browser-specific things right and one very good example which i can give you right now

19:42:16is that if you're on codedam.com if you go to code dam you're gonna see that you use this practice

19:42:25you know this practice panel when you use this you're gonna see that the monaco editor which is

19:42:30in the center of the screen this editor which will fire up really soon in the center of the screen

19:42:37this is not server side renderable right monaco editor is highly sophisticated piece of technology

19:42:45from microsoft and this is not server side renderable right so if you try to render it on

19:42:50server side it'll throw a lot of errors where you would just have to bang your head against the wall

19:42:56so the only way to use modules like this in a next chase project is to go ahead and disable server

19:43:02side rendering completely on them and the way you do it is by passing another second argument

19:43:09called ssr and setting this to false now what this would do is that this would completely disable

19:43:16uh the server side rendering feature and act a lot like how regular javascript behaves right so

19:43:25now if you refresh this you're gonna see you get that flash of uh you know loading content and the

19:43:32reason for that is because the bundle for that particular the bundle responsible for displaying

19:43:38that particular dom node is loading right so now you can see inside one.js you're gonna see

19:43:44hello world right here right which is the react code the react equivalent of displaying this right

19:43:52and if you go to page source you are not going to see that h1 tag right you see a div opening p

19:43:58and a div closing although we have a dynamic boy right here right which is just sitting here

19:44:05there is also another attribute which you can plug in and that is the loading this loading right here

19:44:12um basically allows you to pass in a component which you can show while the page or while that

19:44:18particular piece of component is loading again super handy so you can go ahead and say something

19:44:23like dot dot loading right and once you do that if you go ahead and refresh this you're gonna see

19:44:30that you get a slash uh that flash of loading again and if you try to make this h1 it will

19:44:36exactly match the uh you know the dimensions so now if you go ahead and refresh this you can see

19:44:44it server side renders but the loading component i'm not sure if you go one level deep and

19:44:53try to you know have a dynamic import here as well you might want to try that

19:44:58that will be interesting to find what happens but you can see that pretty much they would expect you

19:45:03to have a static available component for loading right that's fair so yeah that's how pretty much

19:45:10dynamic imports overall work right you have loading component you have ssr with you

19:45:16and you can specify pretty much anything here right to load it dynamically on the runtime

19:45:22if you do specify ssr as false it will completely disable the loading at all nextgs is not going to

19:45:28look inside this file at all it will not render this file at all on the server right so that

19:45:35means if you're using anything specific like window dot um a lot something like this as 10

19:45:42this is absolutely fine right if you refresh this if you refresh this you get an alert of 10.

19:45:50however if you try to do this without an ssr that is ssr as true you're going to see that if you

19:45:57refresh this right here you're going to get an error that windows not defined and this error is

19:46:03not from the client this error is from the server right because even though it is dynamic import

19:46:08next js tries to render it um for the first flash of loading right and when it's trying to render

19:46:15it for the first flash it encounters this and this is an error but the moment you switch it that hey

19:46:21i don't want this at all and if you refresh this well next yes just doesn't even bother looking

19:46:27inside the file now obviously this is bad this is bad bad and you should always try to avoid

19:46:33anywhere writing ssrs false why because you kill all the performance benefits um for the user that

19:46:40means now they have to download the javascript in order to view the page right which is bad so

19:46:48just use this whenever it is highly necessary just like the example i showed you monaco in our case

19:46:54monaco editor which codem uses is not server side renderable so we have no option other than

19:47:02uh you know just disabling ssr on that page for that particular component but

19:47:08yeah that's pretty much it for ssr hope you know a lot more about dynamic imports and

19:47:14how server side rendering works with that and how you can have a placeholder sort of component

19:47:19for a while as well so that is all for this video i'm gonna see you in the next one really soon

19:47:26hey everyone welcome back and in this video let's just take a look at the next image component which

19:47:32is again a very interesting component from nextgs and like one of the most exciting features for me

19:47:40at least when it came out so what image component is is that i'll just show you an example real

19:47:48quick let's just go ahead and actually let me see if i can grab a screenshot and if i go ahead

19:47:54and grab the screenshot for this and place it somewhere inside public let's say right here

19:48:00right so if i have a screen oops if i rename this as screenshot right and if i go ahead and take a

19:48:08look at for example public and then if i do ls lhs of screenshot you're gonna see that this actually

19:48:18weighs 111 kilobytes right fair enough let's just go ahead and use an img src of uh you know

19:48:29screenshot.png right here right and if you go well let's just get rid of all the stuff right

19:48:38and if you go let's just remove this and if you go ahead and take a look you're gonna see that

19:48:44it pretty much just embeds the image just like you would expect it to right now the problem

19:48:50right here is that there are a bunch of problems first of all if you use something like s3

19:48:59or you know some other provider which is just raw file provider and not optimize images then

19:49:09you waste a lot of bandwidth right so this is like a huge problem second because of this your images

19:49:18images are heavy uh you know not scaled therefore slow for user right this is also a big problem

19:49:27right and third one is that you are lacking images for different different dimensions and you know

19:49:34accessibility and all that stuff because right now you can also see that we are not specifying width

19:49:39and height attributes so that means there would be a you know cumulative layout shift cls which

19:49:48which stands for like i don't remember the exact spelling cumulative layout shift which just means

19:49:55that how much your page is shifting within a span of let's say i think it's 50 milliseconds or 500 i

19:50:02don't remember but the more the page drastically shifts the worse the score is for the cls factor

19:50:09right so there are a lot of optimizations which can be brought in inside images when they are

19:50:14embedded and images are like a heart of almost every website there are a lot of images um pretty

19:50:21much anywhere on any website right so what next js did is that it gave you the option with nexus 10

19:50:29to have all these problems fixed with a drop in replacement of the image component from next

19:50:37so if you import image from next image and if you try to embed this like this with an image src

19:50:44what's going to happen is that if you save this you actually have to specify the width

19:50:48and height as well but yeah you have to specify so let's just give it a width of let's say 1280

19:50:57you can also use numbers and a height of 720 right you can technically disable this as well if

19:51:03you don't want to give this but there's a pretty good reason you should so if you refresh this now

19:51:08you're going to see that first of all your image is resized according to dimensions which you gave

19:51:14right and observe that this is actually a you know optimized version of image

19:51:20as well how do i know that let's go to networks tab clear this out refresh image

19:51:26and right here if you go to headers you're gonna see that the content size let's see

19:51:37let's see if i can save this um on the desktop as the image name so if i go ahead and do ls lahs

19:51:49of desktop image dot webp you're gonna see this is in fact 28 kilobytes right

19:51:56so what happened is that next year is detected that well this browser can support vp format and

19:52:02we want you know uh an image which is not um that large we have already specified the dimensions one

19:52:09two eight zero seven twenty why not just compress it a lot right and just make sure this is good

19:52:15so you got an image dot pepe format directly from the png or jpeg whatever you're using

19:52:21and it is much smaller right this is 28 kilobytes

19:52:2628 and that was one one one kilobyte right the original one so you got all that optimization

19:52:32automatically out of the box in fact if you take a look you're gonna see that it uh you know

19:52:39specifies a bunch of options as well and one another another one interesting option

19:52:44is that it lazily loads images that means if the viewport height is not you know if the

19:52:53viewport height is not that much that means that the image is visible it will not show that image

19:52:58so if i go ahead and create this multiple times a bunch of times you're going to see now if i

19:53:05refresh the page you're going to see in the networks tab inside a maid section we have not

19:53:10loaded the image yet right the image is not present but if i scroll down a little and make

19:53:16the image visible you can see that immediately it loads right just before the image is visible right

19:53:23so if i close this refresh this close this refresh this you can see it's not invisible right now

19:53:29and it is now visible right so that is pretty cool again that happens because of the

19:53:35uh next js optimization and there's also native browser support as well

19:53:40for this such such behavior but i think it's very limited right now to chrome only but anyway this

19:53:47is how this works right it also specifies it also gives you um you know a 2x version basically a lot

19:53:54of optimization out of the box so you can just feel free to replace all your img with image

19:54:00given that you have width and height otherwise there are a bunch of other dimensions as well

19:54:05other other sort of properties as well so you can specify layout fill and right here

19:54:11you can still get that exact same behavior which you pretty much get but i guess in this case

19:54:19the width and the height are pretty bad for the container but anyway you might

19:54:23want to customize this with css now so yeah i mean whatever happens

19:54:30what you can think about what you can do is you should always use the image component because it

19:54:36optimizes it scales it makes your images work much much better on a nexus website

19:54:44one caveat of this is that you need to have a next share server running that means you need to have

19:54:52a next chairs you cannot really statically export this why because if you go to networks tab you're

19:54:58gonna see it request a particular uh you know api endpoint which is specific to next year's

19:55:06framework and this endpoint will not be available if you are not running a nexus node server on the

19:55:13back end right so that is sort of a caveat but this is also um you know fixable in a way which

19:55:21we'll discuss in the next video and i'm also going to introduce to you with next.config.js

19:55:26file in the next video so yeah stick along so that is all for this video i'm going to see you

19:55:32in the next one hey everyone welcome back and in this video i'm going to introduce you to a couple

19:55:38of things the first one is obviously we're going to continue with our next image component and the

19:55:43second one is the next.config.js file now this file you have to create it will not be present by

19:55:52default but this is a hard coded file again the name is hard coded into next year's framework

19:55:58and whatever you export from this file has special meaning to next year's framework right and it

19:56:06shapes the behavior of the framework and of course this file is just read just like environment

19:56:12variables this is read on the boot so if you're making any changes you gotta restart your server

19:56:19so what i want to do first of all is i'm going to show you that this is fine this is

19:56:24absolutely fine that you're referring an image with a relative path but what about if you want

19:56:29to embed an image which is from a different domain right let's say if i go to courses and

19:56:36well this will also be a nexus embedded image but let me just go ahead and try to extract out the

19:56:47real image out of it so if i go ahead and do a decode uri component

19:56:55i will be able to see that right so this is like the raw image which is hosted on s3

19:57:00so now if i go ahead and try to embed this like this what you're gonna see is that it saves me

19:57:07invalid src prop because the hostname creatorassets.codam.com is not configured

19:57:14under images so what does this mean is that if you are trying to include any image which is not

19:57:24absolute path right or which is not relative path not absolute then you have to you have to add

19:57:34white listing for that particular domain and how you do that is that you go to next.config.js

19:57:40create an images key and add that to domains right so in this case it will be just created.codam.com

19:57:49now remember this is important if if you are hosting your website on codedam.com as well

19:57:55right so let's say if you are hosting an image on codedone.com itself and your website is also

19:58:01running on codedown.com if you use a direct absolute url you still have to whitelist

19:58:08codedam.com that means even if your website is deployed on codedown.com and if you're using

19:58:14like this you have to whitelist it right if you're writing any sort of domain name here you have to

19:58:19whitelist it otherwise this will not work it will complain it will throw an error in development

19:58:24and in production i guess it will just it will just crash i don't remember the exact behavior

19:58:29but it will not show you the image right so once that is done you know for this of

19:58:35course we just need the creator dot co down part and if i not really creator but creator assets

19:58:43right so if i go ahead and replace this and if i go back right here and if i restart the

19:58:49server you can also see it tells you to do that so now if you go ahead and refresh this what's

19:58:54going to happen is now it is loading that from the remote server it loads it first of all inside its

19:59:01own memory optimizes it for the first time and from the next times onward it's just gonna you

19:59:07know just make use of all of it from the cache so again super helpful super powerful um in terms of

19:59:16resizing and uh you know just having the best possible image served to a particular client

19:59:23highly highly recommended to make use of um you know the behavior which image tag provides you

19:59:32it also comes with a bunch of other attributes i did not go through every single one of them

19:59:37you can pretty much just take a look at the documentation if you want but the most common

19:59:41ones i have just listed you're going to just need width height and src you can also specify

19:59:48the loader which is an interesting bar you can specify the loader which you want with the image

19:59:54component and what do i mean by that that means that right now you can see that well it just

19:59:59fall backs to uh you know the local host so if you can observe what's happening here is that

20:00:06it takes your url it takes your url right here copies it and pastes it pastes it right here right

20:00:15so this is the image url and then it specifies the width and the height as well if it wants to

20:00:21uh this is quality parameter so what you can do is that let's say instead of having this hosted on

20:00:27nexus the image optimization service let's say you have bought it from some other service provider

20:00:33right let's say mjx or whatever you pronounce it right then you can also specify a custom loader

20:00:41for that and the way you do it is that you create a function you create a function called loader

20:00:49and it's going to accept some arguments it's going to accept some props and the props are

20:00:55src width and quality right pretty much which are passed um inside our this loader which was before

20:01:05right i just have not copied the url but what you're going to see if i console.log src width

20:01:13and quality and if i try to return for example http uh my custom service dot com slash url

20:01:25uh url is equal to src what you're gonna see now if i specify this

20:01:33as the loader for this particular image you're gonna see if you refresh you're gonna see it

20:01:40tries to load your service from a url like this my custom service url and then that so you can have

20:01:47all that custom logic of caching and everything on your own services as well if you want

20:01:51if you don't specify this this fall backs to the internal next share service this is useful

20:01:58if you're developing an a completely static site where you don't really want the next share server

20:02:04running on the back end right so that will help you save a bunch of money if you don't

20:02:10really want to run a node server just because of image compression so yeah that's pretty much it

20:02:17for the image tag basically we have covered all the important stuff

20:02:21you can figure out other details of the smaller details on the way as well but that's all about it

20:02:27so that is all for this video i'm gonna see you in the next one hey everyone welcome to a brand new

Redis Caching Concepts with Node.js

20:02:35course on redis plus no chairs this course will be interactive 100 interactive that means after

20:02:42this video you would probably have a task not a video you have to complete then another video

20:02:47few videos tasks videos tasks so make sure when you're attempting this course please go ahead

20:02:53and attempt all the tasks in place because that will help you build the muscle memory you need

20:02:58when you're learning to code on your own coming to redis this course will focus mostly on redis plus

20:03:06node.js however we will look at the integration with nodejs part a little later first of all we

20:03:11will understand and really work with redis in a first few sections in the last few sections

20:03:17we'll create full-blown projects with node.js which uses redis as well we'll be using this

20:03:23code dump playground for this whole course and you can use this by going to codedown.com

20:03:28playground slash node or you can go to codedam.com go to your dashboard here go to

20:03:34playgrounds and select the nodejs playground here this playground comes with a built-in support for

20:03:40redis you can write redis cli here and you will see that you are taken into the redis console

20:03:46so i'm super excited to start this course with you we'll be covering some fundamentals first and

20:03:50we'll be moving on to no chase integration very soon that is all for this video i'm gonna see

20:03:55you in the next one hey everyone welcome back and in this video let's just go ahead and take a look

20:04:02at what exactly this is why you would ever need it and how you can work with it so first of all

20:04:08what is redis redus actually stands for a remote dictionary server which is a fancy name for a key

20:04:18value database right so what a key value database means you know if you are working

20:04:23with javascript we do this all the time with objects for example so object can be sort of

20:04:30as a key value database but a javascript object in fact is a little bit more richer i would say

20:04:37than rather redis in the structure but are less richer in data extraction and retrieval

20:04:42so you know you can have a key one value one key two value two right you can have the structure

20:04:50similarly you can have the same structure key value stored inside redis right

20:04:56redis is a database just like you would consider mongodb or mysql with the exception that redis is

20:05:04a simple key value database which stores that also if you want to get a little bit technical

20:05:10redis is a nosql database right because it does not contain tables and columns and rows and you

20:05:16know the stuff which you actually get in sql based database so technically that is a nosql database

20:05:22now with redis there are actually two more terms which go or actually just a single mode term which

20:05:28goes with it right so we don't really say that this is a database we always almost always say

20:05:34red is is an in-memory database so what does this in-memory database right here means this in-memory

20:05:42database means that your data whatever you store in red is actually stays in memory that is random

20:05:50access memory your ram right so i've heard about you having four gigs of ram in your system or

20:05:55eight gigs or 16 gigs so that ram somewhere when you're running radius and you're storing data

20:06:02that data is stored somewhere on that ram not on your hard disk and why is that that is actually

20:06:07a choice redis has made to make it extremely fast right if you take a look at databases traditional

20:06:15databases like mongodb or even mysql those databases try to keep things which are actually

20:06:22hot that means they are accessed very frequently or they try to keep indexes inside memory right

20:06:28rest of the stuff goes to disk whether it's ssd or standard disk redis keeps everything in in

20:06:34memory because it wants to be fast it wants to retrieve data super fast that is one of

20:06:40the criteria of using awareness where you want performance where you want flexibility you want

20:06:46the ability to scale it to a lot of load so you want faster access there now technically redis

20:06:54also has options of writing it to disk so you can technically take a redis in-memory database

20:06:59and write it somewhere to disk but usually that really defeats the purpose of traders you want

20:07:04temporary data to be stored by radius which if even if it gets lost you don't really have to

20:07:11worry a lot about for example typical example is rate limiting right if you have a rate limiting

20:07:16system in place and even if it fails for one way or another you know that you know bad actors would

20:07:22be limited again pretty quickly from pub sub to rate limiting to caching of database queries

20:07:28all sorts of stuff so we'll be taking a look at that but first we'll start with the redis basics

20:07:33so that is all for this video i'm gonna see you in the next one really soon

20:07:38all right let's talk a little bit about redis versus in-memory storage of the language

20:07:44itself and why you would need that because i think not a lot of people cover this aspect

20:07:49so let's say you know like i said you can create a rate limiter we'll see how we can do that but

20:07:55let's say for now you have um you know an array of blacklist blacklist ips which you blacklist

20:08:02um if they are hitting your apis very often right and you know not really an even an array if you

20:08:10want a faster access you create an object and then you you know just have an app.get some api

20:08:17some api for example and then for example let's just say you perform some action and then

20:08:24somehow you are able to request your ip blacklist this ip right and if the next time this comes you

20:08:31just check if request or ip is blacklisted then you just say you know return error whatever so

20:08:37this is fine this is completely fine and you can see that when your program this nodejs program

20:08:44is actually running on on a computer on a cpu on a system you'll realize this blacklist ip is

20:08:50technically an object which is somewhere in the memory only right it it is obviously not inside

20:08:55the hard disk because the program is executing right so the v8 engine has compiled the javascript

20:09:01and it is running and it's executing somewhere in the memory so it obviously makes sense that

20:09:06this blacklist ip of request.ip access here it's not only just synchronous but it's actually faster

20:09:14compared to any other solution right because your code is technically sharing the same memory space

20:09:20where it is the data is also stored so why would you ever want to use redis right you could just

20:09:26create your own key value database right in a single file so you can pretty much create and own

20:09:32your own redis inside of node.js well there are a couple of reasons why would you want to do that

20:09:39first of all red is is used in scenarios where you want to make your code stateless right number one

20:09:48making your code stateless is super important for scalability i cannot stress this enough

20:09:54if your core is stateless you can pretty much throw it on any container any aws lambda for

20:10:00example let it run and don't really worry about if it crashes or you know if it returns response

20:10:06because it is stateless you can throw away that container recreate it and you will be good to go

20:10:12if your code has stayed you lose out on so many things like you have to for example websockets is

20:10:21a good example of this your websocket connection is always stateful so your backend server should

20:10:26always be same as what initially got connected to the front end with http this is not the case

20:10:33because http is a stateless protocol similarly you want your code to be stateless as less state

20:10:41as possible and in this code you can see that this is a huge state let's say i have a server

20:10:46which is running seven instances of this index.js right so we probably have you know nodeindex.js

20:10:54ran seven times and then the traffic is load balanced over those seven uh servers so obviously

20:11:01this logic will break out like you know anything because now randomly any sort of node process

20:11:08would be assigned this http request and some might have blacklisted that ips some might not have and

20:11:14you'll have end up in a chaos right red is what it does is that it takes out the centralized part

20:11:20of the state so you can say uh you know redis redis dot get stored we will see the syntax but

20:11:26the idea is that you take out the state away from application code and store it um somewhere

20:11:34if you are coming from front end and if you are especially a react developer which i can relate to

20:11:40you will kind of realize that redis is you can you can think of redis as a context api for react

20:11:47right so you take up your state to a higher level in in your hierarchy and you separate your uh you

20:11:55know ui or in this case your application logic and your global state so redis kind of acts like this

20:12:02right number two which is you know this is an this is an enhancement second most important

20:12:09reason of using red is is there might be a lot of applications which are disconnected to each other

20:12:15right you're just working with the single application right now but what if the same black

20:12:20listing of ip addresses is also used by let's say some other micro service which is running with it

20:12:27let's say this handles payments and let's say this handles registrations right or maybe like this

20:12:34handles another file handles registrations and this handles forward password right so you want

20:12:41you technically want if a person is blacklisted from registering uh because they are trying for

20:12:47you know they're just brute forcing their way into registering a lot of users

20:12:51you also want them to blacklist for the forgot password right so you want this

20:12:54assume that this is into a different file right so you can say this is some other microservice

20:13:02right so you want these two files to share this blacklist ipstate right and how do you do that

20:13:10of course you know they are not running inside same server they might be running as well inside

20:13:14different servers so you want to take this radius out of the system you want to take the state out

20:13:20of the system and create a centralized global place for all the state code and the stateless

20:13:26logic can go directly into your application layers right where you can just pretty much go ahead and

20:13:32focus on the business logic instead of worrying about how you would scale the code so these are

20:13:38two very solid reasons i would recommend you should use redis in your projects people kind

20:13:45of abuse redis for pretty much everything but i would say that if you do not need redis for your

20:13:50projects you probably are good enough um you know just not using it for your personal projects or

20:13:56um you know yeah so that's that's that's that's the thing you can implement pretty much the

20:14:02caching and you know database caching and all that stuff whatever i talked about more or less

20:14:07inside your programming language as well but the real use case of redis comes in these two cases

20:14:13so yeah that's pretty much it for this video i'm gonna see you in the next one where we'll actually

20:14:18get our hands on dirty with um actual exercises which i recommend you to try out and also with

20:14:25the video course so that is all for this one i'm gonna see you in the next video hey everyone

20:14:31welcome back and in this video let's just quickly do a hello world in radius because that's how we

20:14:37get things done in developer world we start with a hello world but what what i want to

20:14:41do in this one is actually tell you how you can use go and playground along this

20:14:46whole course as well so go to codedam.com slash playground slash node or you can go to code damn

20:14:52the official website go to dashboard go to playgrounds and open up the node playground

20:14:58note 12 right or whatever your version is showing this playground right here comes with an inbuilt

20:15:03support for redis as well as mongodb but we don't really need mongodb in this uh video at least so

20:15:10you can write redis cli and hit enter and you will get into that is cli if you see this prompt

20:15:17you mean that that means you are in today this now you can go ahead and install redis on ubuntu

20:15:23if you're running an ubuntu-based system debian based os by saying apt-get install redis or if

20:15:28you are on a mac you can do brew install mac uh not really mac brew install redis

20:15:34but i would recommend you to learn from code dam and then when you are moving on to your

20:15:39own projects later on then use your own systems because you can mess around with these containers

20:15:44you know you can just remove and delete and i'll do all sorts of stuff dangerous stuff here

20:15:50and because this is containerized your you will not really affect any other system except for

20:15:55this small little container now with that being done let's just go ahead and take a look at how

20:16:01you enter into redis server right how you entered into redis instance so what happens with redis is

20:16:08that it comes with two things the first one is redis server so you have a command called redis

20:16:13server and the second one is redis cli right so if you hit enter you're gonna see we actually get an

20:16:20an error that it could not create a server tcp listening on 6379 because address is already in

20:16:26use right that means we are already running redis server that's why we got this error at the end

20:16:32so that's completely fine if you do not get this error that means you have just started radius over

20:16:37and it's going to stay there all right so now that our reddish server is running what we can do is we

20:16:42can connect with a server by writing redis cli and we'll be using this command a lot to get into the

20:16:48redis server for the first um few uh sections as well as in the hands-on practice exercises

20:16:55so you are into this prompt and this is a ripple for redis now so whatever you execute hit enter

20:17:01it will be executed immediately so let's just go ahead and say hello world like this and you can

20:17:10see we got our hello world from radius one quick thing this command could be lower case as well

20:17:17it's just your you know your choice i prefer to write redis commands as upper case but

20:17:24it it could be your choice if you want to write lowercase commands that's completely

20:17:28fine so we did a three hello world here and that's like hippie pourray of hello world

20:17:33so yeah that's pretty much it for this video let's just go ahead and move on to the next one

20:17:39where we will do a little bit of more stuff and finally also take a look at how we can integrate

20:17:45nodejs with redis by the end of this section so that is all for this one i'm gonna see you

20:17:51in the next video hey everyone welcome back and in this video let's just quickly go over through some

20:17:57common operations in redis starting off with get and set so like i said redis is a key value store

20:18:04database so that means you have to set the key and the value and then you would have the ability

20:18:10to get the key value so on a very raw level let's just log into latest cli first on a very long raw

20:18:16level what happens is that in redis you can set by saying just set and you know the autocomplete here

20:18:24will really help you so the first argument you specify after writing set is the name of the key

20:18:29which could be anything like code damn and then separate it with a space this would be a value

20:18:35like awesome right and technically speaking you don't really need to give quotes to the

20:18:41value if it's just a single word but i would highly recommend you to do that because

20:18:45it clears you know it it kind of gives the indication what is the key and what is the value

20:18:50right so you know you'll see a lot of okays from datas redis loves to say okay right all the time

20:18:58so this means okay means that this key has been set now how do you know that that key has been set

20:19:03you know that by saying get the key name right and you don't really have to specify any value in this

20:19:09case because obviously that doesn't make sense now set and get are the fundamental building blocks

20:19:15of freddy's right and these are the few these are the two things on which basically everything else

20:19:21will be built uh you know more or less because the fundamental meaning of reddish is to have a

20:19:28key value store there's another interesting variant of set which i want to talk about which

20:19:33is called set nx so set nx basically just means set if non-existent right so what this means is

20:19:42let's just say set an x key value so i'm going to say code dam and i'm going to say go damn and i'm

20:19:48going to say wow right and you saw that we got an integer 0 as the output what does that mean

20:19:55that means if i just go ahead and say get code down now you can see our value is still awesome

20:20:02it did not update to wow why is that because set nx only sets the value if the key is not present

20:20:10right take a look at set here for example i can say set code damn one two three and now you will

20:20:16see that if i get code down it has been updated to one two three however if i do a set nx of code

20:20:22dam 456 you'll see it still does not work and the reason it still does not work is obviously because

20:20:29code dam is already set right if you try set nx with let's say redis as the key and value being

20:20:37awesome you're gonna see and i would want to keep that consistent with what i said so you're gonna

20:20:44see that you actually get a one and then you can say get redis and you'll see you get awesome right

20:20:51so set nx has a use case trust me this is not just any additional feature it gets a lot of

20:20:58use and rate limiters and a lot of custom applications these are the things you should know

20:21:02about in redis right you don't really necessarily have to memorize their syntax or their you know

20:21:09functionality to the metal as well you just have to know what you can do possibly in redis and then

20:21:15you can always look them up on google right all right let's let's also take a look at one of the

20:21:20other variants of get so let's say i have a key set as name and i'm going to say this key has a

20:21:27certain this value has a certain structure in the sense that the first two letters are initials of

20:21:32the name and separated to the dash and the next two letters are two letter word of um country

20:21:39code of that user right so for me it will be mahul mohan and then india so let's say i want to get

20:21:48the name obviously i can do that and i'll get this full thing but let's say i just want to get

20:21:52the first two initials of of of the user right not really get the whole thing well you know you might

20:21:59argue that you know you can get the full string and then trim it in your programming language

20:22:03of your use but let's let's be honest here you might want to skip a few steps if you can just

20:22:10get that thing done in the database itself right because that thing will cost you some

20:22:15cpu cycles within the programming language as well so why not just get it done on the database layer

20:22:20so what we have with redis is another function called get range get range and what this does

20:22:28is that as the autocomplete says you specified a key a start and an end value so let's just take a

20:22:34look at one by one so i'm gonna give it a name i'm gonna start with zero and end it with zero we got

20:22:40an m if i started with zero and edit with one you see we got an m so you can see this redis index is

20:22:47actually inclusive of both right you get the lower bound as well as the upper bound so get range mm

20:22:54zero to one gives us that we know that the format is you know initials and then country letter code

20:23:00so we know that it would probably be 4 5 not really 5 6 will be our answer for the country code

20:23:08right so you can now store all sorts of stuff in virus and just go ahead and do a get range of name

20:23:14five six and you'll be good to go similarly you can use set range here so you can say set range

20:23:20then you can say name then what you want to say is the offset and this is just the starting point

20:23:26right the ending point aurelius will automatically calculate from your value right so i'm going

20:23:31to say i want to update i n to let's say us for example and hit enter what you're going to see is

20:23:38now if i try to get name you'll see that the mehul mohan dash has become us now right so you have

20:23:45just updated the part of the key without actually getting the whole key and then removing that and

20:23:52doing all that stuff so you you don't really have to necessarily do that let's just go ahead

20:23:56and set another key so for example let's just go ahead and say key2 as maehul is awesome hit enter

20:24:06and now you get we get okay that's completely fine but what i want to do is now i want to get

20:24:12multiple keys like this together so how do we do that we say m get instead of just get m stands

20:24:19for multiple here and i can say key2 which is fine it just gives me one key but you can see

20:24:24we got a number in front of that key right so that means you know we we can sort of return an

20:24:29array in a programming language structure right if you can think about it it'll map to an array

20:24:35so key2 for example then also let's say i want to get name i also want to get code damp and let's

20:24:40say i want to get some random key which does not exist hit enter and you'll see that we got all

20:24:45the keys in the order which we specified that's important so that you can directly map the usage

20:24:50and for the key which does not exist we get nil right or null in in a programming language we'll

20:24:56see that how integration works with node later on but you get the idea then just like m gate

20:25:00exists there also exists m set which kind of gets confusing honestly but you know if you get the

20:25:07hang of it you can get used to it which is key value key value key value right so you can say

20:25:13key one value one key two value two key three value three right that's why i prefer to write

20:25:23values in quotes because it kind of you know right now we just have key one key to e3 as the

20:25:28names but if they're different it kind of gets a little messy to read statements like these what is

20:25:34being said so if you hit enter you still get okay and you can see that your key one or you know

20:25:39why not let's just do em get key one key two key three exist as value one value two value three

20:25:46right so that's pretty cool and finally you can also delete these keys right so like i said you

20:25:52can see that we have got a hotspot of keys right now so one way to go about is to actually delete

20:25:57them one by one which you can go ahead and do like dell and just write you know the key which you

20:26:03want to delete so let's say key one in this case key one gets deleted and you get an integer of

20:26:08one which is the number of keys deleted right so if you do a dell key two key three yeah that's it

20:26:15hit enter you get two two keys are deleted if you try to delete key two again for example you'll get

20:26:21zero that means key two was not there in the first place so that's why so you can do that or you can

20:26:27also use a command known as flush all but before that i'll actually show you one handy command

20:26:33which lists all the keys and you'll use that all the time so this key this command is called key

20:26:38and star nope keys and star right so this command right here lists all the available keys in your

20:26:49redis database right now you might say why is this useful very useful when you're developing

20:26:54applications with redis and you just want to get a quick glimpse of what the state of redis looks

20:26:59like at the moment so you can just have an open different open server terminal and just take a

20:27:03look at what redis looks like for now so you can see that key star gives us all the keys and now

20:27:08i can go ahead and do a dil del of name redis and code dab this will work just fine but instead of

20:27:14doing this what you can also do is write flush all and this will just remove all the keys

20:27:22from redis right so you can just go ahead and take a look at key star now and you'll see that there

20:27:28is no key now so yeah that's pretty much it for this basic redis tutorial i hope you get a hang of

20:27:35got a hang of how redis works looks like how you can manipulate get set multiple get multiple set

20:27:40delete list all the keys remove all the keys do all that stuff and this should be enough to just

20:27:45you know enable you to play around so for the next few exercises try to complete them on your own try

20:27:50to set complete the challenges which are given and yeah that's pretty much it for this one i'm gonna

20:27:56see you in the next video hey everyone welcome back a very quick video on conventions on redis

20:28:03key structure um you're going to find that you know you can pretty much name redis keys a lot

20:28:08of stuff you know like in variables you cannot really use column or hashes and stuff like that

20:28:14in red is that is allowed but a convention in red is to follow i mean you know you can

20:28:20break conventions that not that's not a big deal but the convention to follow is you have a key

20:28:26something like um you know name space one colon namespace 2 colon and so on

20:28:34so for example let's say we are oops for example let's say we are trying to go ahead

20:28:41and i don't know create some key for a blog post so that we can cache that result later on so what

20:28:48what that could look like is blog then maybe the url of the of the slug let's say uh my awesome

20:28:58post and then the id of the comment let's say we are caching that in redis so let's say 23 right so

20:29:06i'm going to say set blog my awesome post 23 as the value this is so awesome blog post

20:29:14for example right now in node.js all i need to do is let's say if i'm trying to get uh

20:29:21this command from commands right all i need to do is extract out first of all the post id and then

20:29:31comment id like this from request.body or whatever sanitize it super important make sure to parse it

20:29:39that you know the user is authorized and is you know enabled to see that comment make sure you do

20:29:46that stuff redis is not going to do that for you and then you finally can create a constructed key

20:29:52constructed key like this which follows a convention which looks like

20:29:56you know uh like i said blog then your post id then your comment id you know it's it's

20:30:06it's just a convention of course you can go ahead and make use of underscores of course you can go

20:30:11ahead and make use of slash of course you can go ahead and make use of hash here it's your wish

20:30:16but you'll see that in a lot of code bases if you're working you might see that this is a column

20:30:21so first thing i don't really want you to get confused what this is this is a valid key name and

20:30:26second thing this is the convention which kind of is followed in redis world so yeah that's pretty

20:30:32much it for this video i'm gonna see you in the next one all right guys welcome back to another

20:30:38video this is super power of redis which we're going to be discussing about in this video and

20:30:44honestly i love the fact about radius that this thing exists in redis and that is the support for

20:30:50temporary keys this makes so much sense and this is so awesome because now you are able to

20:30:56offload the timer aspect of your application to your database layer what does that mean

20:31:02this means that in redis you can go ahead and set keys which are temporary that expire after

20:31:09a certain duration it could be seconds it could be minutes it could be hours it depends on you so

20:31:16what we want to do in order to do that let's say i go ahead and say set um code damn is awesome

20:31:24uh you know awesome forever right because we know that code down will be awesome forever right but

20:31:31yeah i don't really want to expire this key but let's just say we want to expire this for some

20:31:36reason so what i can do is i can say expire and then i can say code down in 60 seconds

20:31:44so that means this key right here will be expired in 60 seconds and what do you do meanwhile well

20:31:50you can do a keys of star to see that the key still exists that's one thing you can do

20:31:55you can also write ttl and then the name of code down right so you can say code damn and

20:32:00you can see it's still got 45 seconds to go right 42 seconds to go 40 seconds to go 39

20:32:0738 and you can see the death approaching right so there's that so what does this mean is that

20:32:14once this timer will hit what will happen you know as long as this timer is working

20:32:20is it has not hit zero you will get awesome forever but the moment it hits zero in 20 seconds

20:32:25about you will see that this key is automatically removed without us writing dell code down and even

20:32:31if you write dell code down right now it wouldn't really crash or anything you know this is just a

20:32:37background feature which can just delete the key so you can see ttl five three two

20:32:44one boom right okay you saw that we got a minus two here because minus two means that the time

20:32:52or the key does not exist right so if you just go ahead and do dtl of some random thing then

20:32:57you'll also get minus two because that key has been deleted if you do set a key like

20:33:02key one and hundred and then do a ttl of key one which technically is not expiring

20:33:07you will get a minus one right so there's that otherwise you will get the duration in seconds

20:33:12um how much the key has to live now what you can do is instead of using set and then using

20:33:20expired you can do it in a single statement as well by saying set set ex and then the key name

20:33:26so i'm going to say code damn you know you can just omit the quotes for that go down i'm going

20:33:33to say this just for 10 seconds and the value is awesome forever and hit enter and you can see we

20:33:39got an okay and it's just gonna expire in d ten seconds let's see if we can make it four three two

20:33:48one ah it's gone right so now you get nil once it's gone so yeah that's one cool part of redis

20:33:55and what you can also do is just go ahead and set the redis key again if you want to convert an

20:34:01expiring key do not not expiry so you can say set ex for example go damn 50 and then let's say

20:34:10awesome forever right will be awesome forever for 50 seconds so if you go ahead and take a look at

20:34:16this right now it's awesome forever tdl is close to 44 right but i don't want it to expire right

20:34:23this is a pretty cool message so i can say expire and then code down to hundred right and now we

20:34:29will see that the ttl oops the tdl for code down ttl basically stands for time to live i'm sorry

20:34:35i did not actually elaborate on that so if you were confused ttl is time to live so now you

20:34:40can see the time to live of the key has been increased and if you want to remove this timer

20:34:44altogether you can just set this key again with the same value right so awesome forever and there

20:34:50you go now you can see the ttl has been changed to negative one that means it will stay here forever

20:34:57like you know like i said like we all know like you all know goddamn is awesome forever so that

20:35:03is all for this video we're gonna be having a lot of interesting use cases of this timers and

20:35:08working with that very soon but yeah that's pretty much it for this one i'm gonna see you

20:35:12in the next one hey everyone welcome back and in this video let's just quickly go ahead and take a

20:35:18look at you know just some theoretical stuff that how does actually expire keys right because this

20:35:24is interesting and you know if you think about it it's pretty cool thing right you can offload that

20:35:30timers and that part to redis which is a database layer so if you think about it

20:35:37redis was built to operate on millions even millions and hundreds or tens of millions of

20:35:42simultaneous keys together right so if you have tens of millions of simultaneous keys like set ex

20:35:49and you know you're working with them you might think that you have also have tens of millions

20:35:53of timers intel internal small timers running within uh the system which sounds bad right but

20:35:59that's not technically that's not technically how redis works so if you have a set ex for example

20:36:07go down and 100 you know not really go down 10 and 100 what's gonna happen is actually you know

20:36:15we are not touching anything right now nothing is going on nothing is happening i'm not really

20:36:19writing any command we are not technically touching this key right so redness evaluates

20:36:26whether the key is expired or not on a need to know basis there is no timer running actually

20:36:32what's really happening is that internally under the hood radius has stored that the scored dam key

20:36:39has to expire on 3 p 3 a.m to m 2 8 minute and let's say 15 seconds let's say we started at 5

20:36:47second right so that time stamp of expiry is there on this key and the moment you access it via get

20:36:55or maybe like you know wire listing all the keys by key start whatever you do the moment you uh

20:37:01try to access this key read this before actually sending this key's value or you know what the key

20:37:08is it'll actually try to see if the timestamp is expired or not if it is it will mark it as deleted

20:37:14remove the value and get on with it right now this sounds super cool in theory but actually this is

20:37:20cheating right redis is not really getting rid of this key it only gets rid of the key if you open

20:37:27the box which sounds good but it's actually bad for your system memory right if you think about it

20:37:33if you're storing a large string here with an expid of a few seconds you almost want

20:37:39that expiry to clear not because the key was meant to be cleared but because you wanted to free up

20:37:44the memory so for that also redis also randomly not really randomly before six red is version six

20:37:52red is randomly used to just ping up keys and say hey are you dead so that's that's a little funny

20:37:59but let us just go ahead and poke around random keys are you dead are you dead are you dead and

20:38:03he'll just clear off the keys which responded yes but with red six there's a there's a better better

20:38:09um i don't know this they're just following some algorithm which sorts the keys um according to

20:38:15their expiry times uh but yeah they have a little bit of structure there but the rest being assured

20:38:20that redis will always work as you intend it to like you know set ex would always

20:38:26work like you wanted to it's not like somehow the key would magically pop up even if you are

20:38:32uh you know even if redis does not expire it in memory but this is you know just a little bit of

20:38:36theory you should know how set ex and how it is under the hood works because that these things

20:38:41like keep the interest going right in the in the in the framework in the library in the software

20:38:48so yeah that's pretty much it for this video i'm going to quickly see you in the next one make sure

20:38:52you're doing all the challenges and labs that's pretty pretty awesome and important um and you

20:38:57can do that only on goddamn.com so yeah that's pretty much it i'm gonna see you in the next one

20:39:04hey everyone welcome back to another video in which i want to show you an actual integration

20:39:08between nodejs and radius now first things first you need to make sure that your redis server

20:39:15is running one way to go about that is to just write redis cli and you'll see that this thing

20:39:20appears um which means that your redis server is running on the local host at least the next thing

20:39:26you should be in a node.js project obviously i am and you can use code on playground as well

20:39:32codedown.com playground slash node and you're up and what you want to do is you want to install

20:39:38something known as ioredis right and let's assume cr instead of npm so i'm going to say yarn add

20:39:46iodis and what io data is is it's one of the packages of a node which

20:39:54enables you to communicate with this client right there are multiple packages there is redis

20:40:00there is node radius i guess there are a bunch of them but i recommend ioredis and i also use that

20:40:05on code dams infrastructure so that's that's that all right so once that is done what you can do is

20:40:12you can go ahead and start working with this bad boy so you can say constructis is required

20:40:18iodis first of all right and if you just console log this thing you will see in

20:40:24the console that you get a good object with yourself right but this is not how you do it

20:40:30this is actually initialized with new so you'll say a new redis instance which gives you access to

20:40:38uh you know a redis client which you can now interact with so what does this mean this means

20:40:43that you can go ahead and say for example host is localhost which is true in our case and port

20:40:51number is for example 6379. and how did we get this we got this because if you observed

20:40:57if you write ready cli that's what you get right now this might be different depending on

20:41:05you know if you're trying to use some aws radius elastic cache or some external third party one so

20:41:11you might have a different domain or sub domain here but the standard where is sport is always

20:41:156379 but for some reason if you are running it on a different uh port then you should mention

20:41:22that here there are a bunch of more parameters which you can specify here but i'll just leave

20:41:27it to you you know to you if you want to have authentication and all that stuff that's on a

20:41:31little bit of need to know basis so you can refer documentation to that now one quick thing about

20:41:37this redis operates is its messages on tcp right so this is actually tcp communication which is

20:41:44happening here so your node process is going to establish a tcp connection to your rarest process

20:41:53redis server your node server and redis server so all the communication happens that way right

20:41:59and that's completely fine that's how http works as well http works over and this is a

20:42:04bi-directional communication obviously so you can say something to redis redis can

20:42:08also say something to you which is especially useful in pub sub mode we'll see that later on

20:42:13but uh there's that so let's just go ahead and start working with this you can add listeners to

20:42:19this you know in in the sense when redis is ready or when redis is available but you necessarily

20:42:26do not need to do that because um this library will automatically key you your messages anyway

20:42:32right so we can start working with like redis dot set key one and then value one right and that's it

20:42:40so if i go ahead and for example run this right here we got a console log oops value one is not

20:42:48defined because this is not in quotes key one value one let's just go ahead and run this again

20:42:53and you can see that we got this and we stay at here because redis is still running in the

20:43:00background that connection is established so we probably need to close that down so for

20:43:04now let's just do a control c here and go to red cli and let's just go ahead and list all the keys

20:43:11i'm going to do a key star and you can see that we got a key one which we just saw

20:43:15set here with our node.js code right so let's just go ahead and exit this out and i'm gonna go ahead

20:43:21and actually show you how you can quit your edits client as well but before that how do we get this

20:43:28how do we get that okay response with us right so if you go ahead and say set for example key2 value

20:43:352 you see that we get this ok from redis which is an affirmation that's everything went right

20:43:41right in this case we did not get that so how do we do that well you see that this action is

20:43:46actually asynchronous just like an http request to a remote server is asynchronous this is also

20:43:52asynchronous because well at the end of the day you are talking over tcp right and redis might

20:43:57very well be located on a remote server so it makes sense to make it asynchronous so what

20:44:03this returns is that it also returns a promise this also expects a call back right so you can

20:44:07do either so i'm going to go with a promise i'm going to say value here and i'm going to say await

20:44:15and i'm going to actually console.log value i'm not sure if we are running the latest node here

20:44:21probably not so we might need to throw it in async function um boot for example i don't know and

20:44:31we'll just call this right and what we can also do once we are done is we can say redis dot quit

20:44:38so that it quits our node.js program so once we do that i can hit this and run this command

20:44:45and what's going to happen is that we run this actually let me just get rid of this console log

20:44:50let's run this and you can see that we got this okay which we always expected right so we can say

20:44:56okay yeah otherwise nope you know or we can just leave it like this so that's that's one way to

20:45:08go about if i try to get this key instead for example redis dot get and i say key one that's it

20:45:16hit the command you can see that we got value one as the output in this case right which is

20:45:22pretty cool so you can pretty much mimic all the commands of this uh redis from this library

20:45:28and i will highly recommend you to check out the documentation as well on the side for ioredis and

20:45:33how the common operators common instructions would look like we will learn a lot more about working

20:45:38with this library in the next few projects which will be building so that is all for this video

20:45:42i'm gonna see you in the next one hey everyone welcome back and in this section we're going to

20:45:49be starting off with some projects so i have set up a very simple node share server on code down

20:45:54playground and we're going to be taking a look at how we can incorporate redis into this one

20:45:59so first things first i'm just going to walk you through the project very quickly in this

20:46:03video what is being set up and what is there so it's a very simple node.js application which just

20:46:08serves the index.html page and gets the number of stars of a particular repository right and then

20:46:15just shows them here on the screen so we will be using github api on the back end to make that call

20:46:23and on the front end we will be just calling our backend server right so we call the data

20:46:28endpoint with the method of post and you can see we are using express in node.js

20:46:33and we have configured it to use json and we are creating an api endpoint with data

20:46:38extract out the repo which is you know what is passed in this input field

20:46:42we make a request to the github servers to get the number of stars which you know the endpoint has

20:46:49and then we respond to it now this is obviously not a production ready endpoint because it lacks

20:46:56try catch um error handling and stuff like that but you can take care of that later down the

20:47:01line as well i'm just gonna go for a little bit of simplicity at this point so that's why we're gonna

20:47:06keep keeping it like this all right so with that being done now we want to set up redis into this

20:47:13infrastructure right and actually before we do that let me just go ahead and actually show you

20:47:18how this looks like so if i go ahead or actually i can just do it right here by just go ahead and do

20:47:23that there so if i go ahead and write facebook react and hit on go wait for a few seconds um

20:47:29actually we need to refresh this because the code was changed facebook react you can see that we get

20:47:35starts for facebook react this much and then milliseconds this whole operation took was 471

20:47:40right let's just think of something else so um i don't know let's just think about

20:47:48google angular i hope this exists or maybe like no wrong url so maybe like angular angular

20:47:56because most of the companies keep it like this yeah so you can see we took about 458 milliseconds

20:48:02for this request as well all right so let's see if we can do better so what we're going to do is

20:48:08integrate redis into this api endpoint so that we can cache this thing right and the

20:48:15way we're going to be doing that is i'm going to be importing redis from require iodis right

20:48:23and we can see that we do not have iodis installed at the moment so let's just go ahead and install

20:48:29ioredis and actually what we can do instead of um you know just requiring it right here we

20:48:35can create a separate file we can say for example redis client dot js like this and here we can say

20:48:43redis is equal to require ioris then we're going to be saying redis dot reddest.createclient

20:48:50because that's what we wanted to do so we will say you know this should be something like redis and

20:48:56this then this will be something like red s oops let us is equal to redis dot create client and not

20:49:04really create client this should be registered new redis because create client is for a different uh

20:49:11syntax for a different client right so once we have done that we don't really necessarily need

20:49:16to pass any configuration because by default host is localhost and port is 6379 and you can verify

20:49:22that the redis is running by writing redis cli and yes it is running so that's perfectly fine and

20:49:28what i'm going to do is just say export default radius right here right so that means we are just

20:49:33not really export default because uh we are using uh common js right now so we're going to be using

20:49:40module.exports now what we can do is instead of doing it like this i can just say redis client

20:49:47and now we can do our magic right so i can just go ahead and say console.log redis just to see

20:49:54if everything's working fine nodeindex.js and looks like something is not working fine

20:50:01so node index.js there we go so we can get the we get that it is object so that's completely fine

20:50:09now what i want to do is i also want to say that how do we cache this how do we cache this response

20:50:17so to do that what i'm going to do is actually check if this if this repo

20:50:23exist in redis cache first of all before making a request i'm going to say if redis

20:50:30somehow dot get this repo somehow then i want to just you know use the cached version

20:50:38so to do that let's just go ahead and take the value out of the radius i'm going to say value

20:50:45await redis dot get repo let's assume that we are storing um you know it in the same fashion uh

20:50:53key is basically this this whole thing so one thing i would want to point out is

20:51:00please please please please perform validation before putting in arbitrary

20:51:12arbitrary user data as key right you don't you always never really want to do put arbitrary user

20:51:20data as a key as any operation without actually validating this right so i'm just going to skip it

20:51:27here for um brevity but you should go ahead and do that so i'm going to say if value does exist then

20:51:35that means means we gotta cache it right i'm just gonna go ahead and return it

20:51:42right in there so i'm gonna say status as okay and then stars as um you know

20:51:48response not really response just value we can actually include another field called let's say

20:51:55from and i'm gonna say remote right and here we can say from we can say redis right so there we

20:52:03go now if we do not have value then of course this will happen and then we'll get to this point and

20:52:09that's that's all fine and good but we also want to make sure that if it the key is not

20:52:14available we cache it so how we're gonna do that is we're just going to simply say await

20:52:21redis dot set and then i'm going to say repo i'm going to say response dot star gazers count

20:52:28right and we're going to only do that if response dot sarcascount is not equal to undefined

20:52:34because for not valid repos this field will be undefined right so i'm going to say if this is

20:52:40not undefined then set it and then return it to the remote right so there we have it now

20:52:48i'm just going to go ahead and run the server by nodemoreindex.js and what is going to happen next

20:52:56is right here let's just make a little bit of more modifications i'm gonna also say source

20:53:05source right here and i'm gonna say data dot from right so that tells us where it is coming from

20:53:12so i'm gonna go ahead and write angular angular let's start with that and actually

20:53:15refresh this first so i'm going to write angular angular right go and we can see

20:53:24that looks like something is crashing in our api and that is because it looks like

20:53:29we just returned it it should be returned let's start json right we want to respond it like this

20:53:40so if we go ahead and try to do this now you can see we get stats for angular is this millisecond

20:53:46is this and source is reduced you can see we got our source from redis let's say if i try

20:53:52for facebook react go you can see we got our milliseconds as 500 and sources remote

20:54:00right and this is the count let's say let's go to the github top repos and see if we can get

20:54:07these up and running so i'm going to go ahead and paste this and i'm going to get this to go

20:54:12815 stars 454 milliseconds source remote right but now if i go ahead and press go again we see

20:54:21we get a drop in the response time and that's that's a you know consistent drop you know it's

20:54:27it's not like uh it's just one time thing you can consistently see that we are close to 300 350 250

20:54:35that range but if you're doing a fresh repository and that is not from redis you're gonna clearly

20:54:42see that we are closer to 400 500 range right once you get to radius the milliseconds drop

20:54:50let's just take a look at bitcoin a very hot thing these days so we're gonna go ahead and take a look

20:54:57at that and you can see we get 472 so it's close to i would say 50 reduction and that is after

20:55:05the actual request that is you know this request right here

20:55:09which actually goes through a remote server it's not even through a you know small server it's

20:55:17a powerful server running on the cloud right so if you do it on your systems it will be much more in

20:55:22terms of the difference right so that's one way you can integrate it but the setup can obviously

20:55:29be improved a lot it's not perfect and we're going to be seeing how to improve that in the next video

20:55:34make sure you're attempting the exercises because i will be creating a lot of exercises so that you

20:55:39implement it yourself so do that and that is all for this one i'm gonna see you in the next video

20:55:47hey everyone and welcome back and in this video let's just go ahead and improve a little bit of

20:55:51our setup so that we get a little bit of more clarity on how this is working and we can

20:55:56improve the setup as well so first thing i want to do is i want to actually get a sense of um

20:56:05what is the total time which reddit stakes versus fetch takes right here because you can see both

20:56:11are async and this right here is a little bit of um you know not so good metric because it also

20:56:18includes the api endpoint of hitting this api from my browser to the server right so what we want to

20:56:25do is we also want to have a time start here which is something like date.now and then there if this

20:56:33value i'm going to say time end it's also date.now and i'm going to just go ahead and say time for

20:56:43retrieval and probably the spelling is wrong so i'm gonna just say red and i'm just gonna say time

20:56:51n minus time start right so this gives us a little bit of millisecond information on how much time it

20:56:57took similarly we're going to do the same thing here and we're going to be having this uh time in

20:57:04statement right after we have a response right and just for the sake of it you know just to make sure

20:57:14we are not calculating the reddest part inside the you know this part inside our calculation i'm just

20:57:21going to reinitialize it again so timestar is this time end is this and then we just do a time for

20:57:27retrieval as time and minus time start and we can go ahead and show that on the front end as well

20:57:35so what i'm going to do is actually actually just let's just go ahead and put it on different lines

20:57:41because that becomes a little bit of messy otherwise and i'm going to say time for retrieval

20:57:48is data dot time for red right that's what that's what we named right so there we go now what i want

20:57:57to do is convert this one into pre so that we get a nice output and refresh this so now if we try to

20:58:07go ahead and write angular angular for example we see that we get the stars we get the milliseconds

20:58:13we get redus and time for retrieval is essentially zero right which does not really help a lot

20:58:19and that makes sense right because redis is super fast in the sense that you cannot really measure

20:58:25that in terms of milliseconds you need a smaller resolution like microseconds or nanoseconds or

20:58:30something like that but rest assured we can we can say that this 330 milliseconds is just the

20:58:36round trip of this front end calling the backend api and then back and returning the response

20:58:42right so we can know that all right with that being done let's just go ahead and try to

20:58:47implement a new repository try to see a new one so i'm going to go ahead and copy this one iptv.org

20:58:54or whatever it is and let's see what we get here so you can see right here we got a second of

20:59:00response out of which 220 milliseconds actually went into this api call right here you can see

20:59:08right so technically our backend only took about 800 milliseconds for this whole round trip but

20:59:14it appears like 220 milliseconds were wasted and getting to github and getting that data out so if

20:59:20i go ahead and do that again you can see we kind of get a similar figure which we would have got if

20:59:25our time was zero so there's that you can see that this definitely saves a lot of time and then

20:59:30of course you know this stuff is variable because of network effects right now with that being done

20:59:37what i want to do is actually we want this to expire right because if this is not expiring then

20:59:44you know this is a problem because repositories gain or lose stars over the time right so you want

20:59:51to maintain an updated database so what you could do you can take a couple of strategies here the

20:59:57first one you can do is uh probably just go ahead and make use of get ex here so the syntax would be

21:00:05similar to what you see inside of redis cli so if you do a set ex not really get ex but actually set

21:00:12ex so you can see you get key seconds and value so instead of doing set you know what you do

21:00:19is you do set but with key and then seconds to expire so one thing you have to remember about

21:00:25using ioritis is that whatever you write here you know mostly this will work whatever you write here

21:00:32in small case will be a command of redis like said ex for example writing said ex would be a command

21:00:39and then all the arguments which you pass will be passed one by one into the data server right

21:00:45so let's just say i want to set it for 60 seconds and then be done with it so what i'm gonna do is

21:00:52i'm gonna go ahead and start our server one more time because this is already running

21:00:57let's just go ahead and refresh this and pick up a new fresh repository so i'm gonna go with this one

21:01:02now because we haven't really picked up that one before and once we go ahead and hit go you're

21:01:08gonna see we get a remote retrieval but the next time you're going to see that we get a reduced

21:01:13retrieval that means it's in redis but we have to hurry up now because we have actually set this to

21:01:19expire in one minute so let's see let's just go ahead and take a look at this ttl of this key

21:01:27and you can see that it's actually going to expire in about 38 seconds right all right so now you can

21:01:33see that you are not just caching the responses in the eternity so you are actually revalidating and

21:01:38you know invalidating the cash after one minute so that's a start that's all for this video in

21:01:43the next one we'll be doing some more interesting stuff so stay tuned hey everyone welcome back and

21:01:49in this video i want to share another way where we can you know just help improve performance

21:01:56overall and this is not really you know any any any sort of specific method but just something

21:02:02intuitive which clicked to me so you can see right now it is all working fine and good um you know

21:02:08you click on this you get a remote response for the first user and then you can just click on this

21:02:13and you'll start getting redis responding you for you know for the next 30 60 seconds whatever it is

21:02:21but if you see if you if you see what's happening here is that's what's happening essentially is

21:02:27that for the 60 seconds you are responding with you know the data which is there but

21:02:34that one user gets that response which is uh you know long in terms of retrieval time right

21:02:41so what you can do um again this kind of defeats the purpose of redness in the sense that you are

21:02:48making a request again uh but at the same time this could be useful if performance for users

21:02:56is much much more important than for example say hitting this endpoint again and again right if

21:03:02you don't really want to hit this end point again and again that's absolutely fine you should just

21:03:05return it right here but if you can't afford to do that what you can do is pretty much you know just

21:03:11return from here and then just perform and perform in a request right so you can say response await

21:03:19look that you have already sent the requ response to the front end right so this is just extra stuff

21:03:24which we are doing right here so what we can say once the response is available to us we can say

21:03:29if response uh the strategies are count is not undefined we can just go ahead and update the

21:03:37redis uh with the new stargazers count right because now whenever this means that whenever

21:03:44somebody is actually visiting and continuously visiting not only we are just actually keeping

21:03:49the same correct uh response time which is zero milliseconds or sometimes one millisecond but we

21:03:56are actually also updating it and then extending the duration of that particular thing right so in

21:04:02this case what's happening is suppose you receive you receive one hit on this every second that's

21:04:08about 60 hits per minute right if you're receiving that end point you don't necessarily want the data

21:04:14to stay uh you know stay stale for 60 seconds and then refresh and then stay stale for another 60

21:04:21seconds so this approach right here will help you with low response times number one because you are

21:04:27still uh you know we retrieved from remote first time and then we are always retrieving from radius

21:04:34but at the same time this will also help you to maintain correct data so your data

21:04:38is not stale right um well i don't know if github actually caches this so let's just see

21:04:44if we can break this out so if we go to this repo and if i start this repo right here we

21:04:52have 651 650 so if i go ahead and click ok yeah you can see that even though our source order

21:05:00was reduced all the time but still our response got updated it would not have happened unless it

21:05:06would have hit remote first and then you know back to that is so this approach will do that

21:05:11right so i just wanted to share this real quick with you and that is pretty much it that's all

21:05:16you would need in a in a in a setup like this now of course you can improve this in the sense that

21:05:22you know you can create wrappers around the code um which just cache them do something like that

21:05:29um so one way we can do that is we'll explore that in the next video but yeah that's that's

21:05:35the essence of how you're gonna be doing stuff right so that's pretty much it for this video

21:05:40i'm gonna be seeing you in the next one really soon all right everyone welcome back to another

21:05:47nodejs plus redis project in this project we'll be learning about how you can create a simple

21:05:53rate limiter with node.js and express but in this video i just want to walk you through over how the

21:05:58project works and looks like so the front end is pretty simple you can see we get and hit an api

21:06:03endpoint we have three buttons and we have an output for showing what the api is returning

21:06:09we just set up a few listeners on these three buttons and the function which is called is this

21:06:15hit api every single time one two three and you can see what we are doing essentially is

21:06:22just performing a fetch request to api 1 api 2 api 3 depending on what button we are heading

21:06:28the method is post and then finally we just convert it into json whatever response the server

21:06:34is sending to us right then finally we append that to output in our text and that's it so if you go

21:06:43ahead and take a look actually this is calls in a minute not really just calls so we're going to be

21:06:48changing that so if you go ahead and take a look inside the back end now you can see our first line

21:06:54is pretty simple first route is simple because it's just returns us this index.html document

21:07:00then our three endpoints here which are three apis api one two three all three say response okay and

21:07:07calls in a minute as zero right and one more thing this should be actually api two and three not just

21:07:12api one all along so once we do that and also on the back end what we want to do is actually

21:07:18change this to from just return to rest.json all the way down to every single api which we have

21:07:26all right so with that being done let's just go ahead and click on this hit api one and you can

21:07:30see we get a response okay called zero and we get all the way down so what next task would

21:07:36be to increment these calls and introduce radius and i have rate limiting and all that good stuff

21:07:40so i'm super excited to do that in the next video let's just go ahead and take a look at that in the

21:07:46next one hey everyone welcome back and in this video let's just go ahead and take a look at how

21:07:51we can integrate rate limiting with redis on an express app and on any any single api so we're

21:07:58going to be doing it raw bare bones metal uh but obviously you can use a package in production you

21:08:05can use any npm package you want but i'm going to show you how you can do it in redis itself

21:08:10so first things first for rate limiting let's stick to just api one and then we'll extend it to

21:08:15basically all the apis the first thing i want to know is the ip address of the user right

21:08:23so what how you determine an ip address of the user is in a couple of ways it depends on if

21:08:29you're using remote proxy or not so stuff like that depends right so if you go ahead

21:08:35and actually console you know just get the ip from either the x forwarded for so this is how

21:08:44you use it if you're sitting in front of a remote proxy like nginx and i know we are in fact sitting

21:08:50in front of nginx for this container codename runs in so we will have a right ip from this or

21:08:58you know you can have a request.connection.remote address as well as the property if you're directly

21:09:03sitting across the internet so you can use these two things and you'll be good to go

21:09:09now the next thing is let's just go ahead and actually take a look at our ip i'm going to just

21:09:13ip dot slice 0 to 5 so that we just know that it's working but not really expose the whole ip address

21:09:19so i'm going to go ahead and hit api in point one and you can see that it kind of you know

21:09:24gives that ip feel that's fine all right so the next thing i want to do is once we have our ip

21:09:30address what we want to do is we want to somehow say that you know this person has visited this

21:09:41api route and for for the sake of my ip address privacy i'm just gonna go ahead and use the first

21:09:51let's say eight or maybe like nine characters in the ip address right so you will get my ip address

21:09:59like this but ideally you can go ahead and use the full ip address right so you can go

21:10:08ahead and do that that's completely fine so what we're going to do next is we're going to

21:10:15be storing this thing inside redis and we already have a redis client with us which

21:10:21we did in the last project so there's there's that and what we want to do is we want to say

21:10:28first of all await redis dot increment and then we pass in this ip address which we have right

21:10:36and the property of increment is that if the key does not exist it'll create it it'll set it to

21:10:42zero and then increment it so you finally get one right if it does exist it just increments

21:10:47it by one so that's pretty handy so you can just go ahead and say const uh you know request and

21:10:56just console.log number of requests made so far and that could be just requests right

21:11:05so there we have it now if i go ahead and refresh this well we did not really need to

21:11:10do that but anyway if i click on this you can see we get number of requests made so far one

21:11:16two three and it will go on and on so we can pretty much pass this like this and you can see

21:11:22now if i go ahead and you know just press on this you can see our calls are now getting incremented

21:11:28which is progress right which is progress but this is still not calls in a minute thing right

21:11:34but we'll come to that but for now we can work on this right so we want to say that

21:11:39hey if you're making so many requests request is greater than let's say 20 then i just want to say

21:11:46return rest.status is 503 and you know json you know response error uh calls in a minute

21:11:59and then negative one you know whatever or maybe like request as well why not right so now if we

21:12:05go ahead and make it all the way to 20 you can see now we start getting response as error and

21:12:12calls has you know whatever the calls goals amount is right so this time now your

21:12:20your expensive function calculation can go here you know your database calls

21:12:26whatever you're doing that could happen here at this point because now you have just

21:12:30stopped the person from actually using your service right you have rate limited them so

21:12:35that's how you do rate limiting in a basic sense but this is obviously an incomplete solution so

21:12:40we're gonna be taking a look at how we can enhance this in the next video that is all for this one

21:12:45and i'm gonna see you in the next one really soon hey everyone welcome back and in this video let's

21:12:51just go ahead and take a look at how we can go ahead and implement the functionality to actually

21:12:58make sure that you know there is a cool down thing happening after some time so that's pretty simple

21:13:04if you have used redis so far you would understand now that the only thing we need to do is we need

21:13:10to just make sure that we are updating or renewing the expiry date on redis right

21:13:16so you can say await redis dot expire and then you can set expiry to this particular key so we

21:13:24know this is ip and then let's say i can say it's 60 seconds right and we do this only when request

21:13:32is equal to one that means on the first request whenever the server arrives we're gonna do that

21:13:39so that means whenever the ip address or whatever it is makes the request for the first time then

21:13:46we set the expiry on the key to be 60 seconds and then it will stay that all the way um up to you

21:13:53know if this window expires then your account gets reset otherwise you just stay there right and you

21:14:00can also go ahead and say let expiry time and what you can do if request is equal to one like this

21:14:09otherwise what you can do not really expiry time but dtl otherwise what you can do is

21:14:15set ttl to await reds dot ttl and then ip and then you can pass in the tdl like this

21:14:24and you can also pass dtl right here right and you know you can give this ddl

21:14:31right here so now what you can do is basically you know you can give ttl to 60 here instead of

21:14:38instead of assigning it to this value but you get the idea now you can go ahead and say right here

21:14:45response calls and then also ttl that is how much time there is left for this particular application

21:14:56to work and what you can do is go ahead and refresh this and hit on this all right so now

21:15:02let's just go ahead and try to hit api one and you can see we got a ttl of negative one which

21:15:08is not good because we are not clearing our radius cli so let's just clear our redis

21:15:19store and run node mod again hit refresh hit api one and you can see we get dtl 60 then on the next

21:15:27call it's 57 56 so it's expiring you know it's going down but if you take a look if we go all

21:15:33the way to 20 now we start getting errors right because now uh we are not executing this part but

21:15:40we still see that tdl is about 50 it's 42 now so it will come down it will come down all the way to

21:15:4660 all the way to zero and once it does then your client will be able to make more requests again

21:15:52right so this code right here is now safe from more than 20 executions per minute right now

21:16:00of course depending on your requirements you can play around with this number 20 and 60 right here

21:16:06depending on what you want maybe you want a per second um you know throttling or maybe like per

21:16:1410 minute or per hour throttling it depends on you but that's how you're gonna do it right in a very

21:16:20simple way you can see we have still four seconds to go and now if we hit enter you can see we got

21:16:27tdl60 again and it goes on and on right so that's one thing to go about so yeah that's pretty much

21:16:35it for this uh video in terms of how you can set up tdl we will in the next one probably take a

21:16:43look at how we can clean this up a little bit so that is all for this one i'm gonna see you in the

21:16:48next video really soon hey everyone welcome back and in this video let's just go ahead and take a

21:16:54look at how we can create a middleware for our um rate limiter because this looks ugly to use and

21:17:01you know it's not really feasible as well so let's just go ahead and actually just go ahead and do

21:17:07uh something like raid limiter dot js right and this file will consist of our function right here

21:17:14which we can use as a middleware so first things first what this would be is it will be a function

21:17:22which would be in the form of an express middleware so rate limiter would probably look

21:17:28like request response and next that's what express middlewares provide you request is this object

21:17:35which you get response is this object and next is basically a function which if you call the next

21:17:42middleware in the chain will be called otherwise it will not be called so our functionality would

21:17:48remain more or less the same so i'm just gonna copy and paste this whole thing right here

21:17:54right we will also get our redis like this so that we have access to our radius client this will

21:18:01again become async so we have a rate limiter right here and we will finally say module dot exports

21:18:07rate limiter so we get the ip address first of all we check the request by rate limiting you know by

21:18:14incrementing it in redis um we can see that if this thing happens it's fine otherwise this is it

21:18:21then what we can do is we can check you know just copy our copy out that logic and then

21:18:27make a little bit of modifications so oops we say if this is the case

21:18:33then do this otherwise just call next that means just call the next route right whatever it is

21:18:41with that being done what we want to do is we want to make this rate limiter a little bit more

21:18:47flexible in the sense that instead of doing all of this what this rate limiter would do is it will

21:18:54actually return as a function itself right and i'm gonna tell you why that is a good way to go about

21:19:02all right so now why i did that i did that because this way we will be able to provide some of the

21:19:08features some of the functionalities which might differ from api to api right and you don't really

21:19:13want to mess around with the actual code code so let's say this is a this is let's say a second

21:19:19window uh you know seconds window not really a good name but i'm bad at naming things so there

21:19:26we go and then let's say allowed hits so these are the two parameters which are also required

21:19:32so what i'm gonna do is i'm gonna put the seconds window right here and allowed hits right here

21:19:39right so what we are doing is basically making this dynamic in the sense that hey if your second

21:19:46window second windows expire or if it does not expire and you're allowed it's exceed that thing

21:19:53then you know you're you're bad right and you can also set your ttl like this so there we go

21:19:59this looks good to me at least um let's just try to take a look at this and see

21:20:04if we can use it as a middleware so i'm going to go ahead and import this rate limiter from

21:20:09this file rate limiter which is available right and now inside express i'm just going

21:20:15to put it like this and i'm going to say you know what we need to do seconds window

21:20:20is basically let's say 10 for this and allowed heads is four for example right and then we do

21:20:28something like this or you know because this is not an end point we're going to be doing this

21:20:33right here all right so now once we do that hit refresh what's going to happen now well

21:20:40i think our application is crashing that's why await data.increment is only valid in

21:20:47uh all right looks like we are doing a little bit of problem here first of all we want to get

21:20:53rid of all of this so your expensive function calculation goes here and second of all this

21:20:58should be async not this one i mean you could keep that one async as well but that's not required

21:21:05so once we do that what's going to happen is the following so now if we go ahead

21:21:12and take a look at our index file hit api one you're gonna see oh and i made a big big mistake

21:21:20can you guess what it is these functions orders should be reversed this should be actually here

21:21:25because the first call you make is actually with the arguments right then this returns a function

21:21:31to you which actually is an express middleware so that is something which should not have happened

21:21:39on a live course but you know just just to share failures along the way that's how you

21:21:44learn right so function request response next and you can say rate limiter this is real rate

21:21:52limit of function so you call this function right here by these arguments this returns you

21:21:58a middleware which technically if you know about this is using closures to store these values and

21:22:06that's how it happens so once that is done let's just go ahead and see if we are good to go

21:22:12yep hit api one and we are still facing some errors request is not defined so all right that's

21:22:20because you know we have removed some code so we can use request.request and we can inject this

21:22:26um through the middleware so i can just go ahead and say that you know before calling this request

21:22:32and then i can just set it to request right so that that's a little hack not really hack you know

21:22:38express middlewares modify the request object all the time and then you can access that inside here

21:22:44right like that all right so with that being done we are closing enough on uh making sure that our

21:22:50api works just fine so if i click on this we still get another error ttl is not defined and that is

21:22:58again something we can hook into the request so i won't really recommend doing this on the top

21:23:03level but probably somewhere inside you know your own custom object somewhere so that you just don't

21:23:10uh you know just populate the global scope of the request object so now if i click on hit one

21:23:16you can see we have a you know small tdl and we are now getting errors so that's one thing

21:23:22another thing is now this solution is pretty much reusable across different apis right so that's

21:23:29pretty cool so you can have a seconds of five an allowed hit of two or maybe like just one so you

21:23:34just want a single request happening at a five second interval that's how you're gonna do it

21:23:39right so if i go ahead and refresh this again hit api two you can see that you know we go ahead and

21:23:46do that and of course the first request we got is bad because we are not returning the correct

21:23:51values from the backend that's why so if i hit on this again you can see we have a ttl of five now

21:23:58and it errors out after one single request so yeah i mean you can pretty much do that on api 3

21:24:03as well i hope you get the idea and that's how you create a very simple rate limiter with reduce so

21:24:09that is all for this video in the next one we'll be exploring some more fun stuff about traders

21:24:14we'll be seeing what is possible i'm gonna see you in the next video and make sure

21:24:19you're attempting the challenges the labs doing it yourself as well as we go on in the course

21:24:25hey everyone welcome back to another video in which we'll be discussing about atomicity and the

21:24:32nature of redus so redness by default you should know is single threaded and what do i mean by that

21:24:40that is a very important thing you should know if you are trying to work with redis in high

21:24:46load environments and what does single threaded mean and achieve so for example let's just say

21:24:52let's just go ahead and create a function a dummy function which just does await let's

21:24:58say red s dot increment and let's say some key with a value of one or whatever right so you can

21:25:07see that this statement right here will increment the key right now you can go ahead and write it a

21:25:12bunch of times in the statement and assume that this is running on server one right which is a

21:25:19which is a server somewhere on the cloud let's say there is another function dummy two which is also

21:25:25running but this is running on server 2 which is a completely different function from dummy one right

21:25:30so these are two complete completely different functions which are running on different servers

21:25:35now the question is if we take a look at this method right here at a single method

21:25:41at the single call what you'll realize is that redis dot increment is actually

21:25:47um you know returns your promise which you have to wait why because this

21:25:51communication happens over tcp right so let's say server 0 let's say server 0

21:25:58is our server which hosts redis right host redis instance or cluster or whatever it is

21:26:05so whenever you call this what's going to happen is server 1 is going to communicate to

21:26:10the connection the established tcp connection to server zero and say hey i want to increment this

21:26:15key then it's it's also going to say hey i want to increment this key here i want to increment this

21:26:20key increment increment and so on right and so on here as well but the server 0 which is actually

21:26:30writing these operations to the database and reading from database and performing all sorts

21:26:35of stuff is actually running on a single thread by definition what this means is that redis

21:26:43is never parallelly executing two operations at once inside of an instance mode right so if you

21:26:50are running a release like this and if red is you know receives two operations it technically you

21:26:57know not even theoretically it technically cannot run two operations at once because it is a single

21:27:02threaded language not really a language a single threaded implementation of the database you know

21:27:08what else is single threaded node.js node.js is also another example of a single threaded language

21:27:14now you know node.js can obviously handle a lot of traffic and http and it's built for io

21:27:18but that's that's for a different day why that works but you know with redis what the point is

21:27:25that all of these operations are always happening sequentially right irrespective of where you are

21:27:31you know how you're calling them what you're doing these operations on radius machine are happening

21:27:36sequentially that means no two operations will ever be running together let's see why this

21:27:42is important this is important because let's say for some reason redis was able to process

21:27:47operations on two threads right so you know depending on um what the redis call looks like

21:27:56let's say our key starts from zero let's say this this call right here gets finished we get to one

21:28:03right at the same time somehow server two also makes a call right and let's say this call ends

21:28:09in key two becoming two right now let's assume that this request and this request right here um

21:28:19arrives at radius at the same point right therefore now what's happening is that

21:28:25you're running two instance you know two threads of radius so these are two threads

21:28:29t1 and t2 it is technically possible that there might be a race condition in the sense maybe

21:28:39redis tries to increment this key right with this operation as well as this operation now if redis

21:28:46was supposed to be running on two threads you know under the hood under the hood at you know

21:28:52we are talking like very bare bones right now on on you know assembly level so under the hood

21:29:00i'm not you know my assembly is not very strong but i do remember you have to copy the value

21:29:05from memory to register inside of inside of cpu so you do something like you know copy it from

21:29:12eax register to you know from memory address to register eax for example then you increment it

21:29:20you increment the register and then you store it back to memory right my assembly again like

21:29:25i said it's it's it's wobbly but this operation right here is not fundamentally atomic right

21:29:32a lot of good stuff can happen in between this is the assembly code which redis will be running

21:29:36under the hood so what could happen is technically let's say there's a you know t2 is also working

21:29:43here so let's say you copied this you know memory to eax for example in t2 thread and then

21:29:51once it does it let's say it copies value of 2 right now this right here does that

21:29:58the same thing but this also increments it and stores it back now you have a problem because

21:30:04the second increment which was supposed to make this value this was supposed to make it three

21:30:09and then this was supposed to make it four this value is now old right it's still value

21:30:15so it will also make this three and effectively you have missed a redis command

21:30:22right so now you have stored just you know stored an older value although this should be four this

21:30:28is why redis does not use multi-threading at least that's what i can make out of there might be a lot

21:30:33of good other reasons as well but you get the idea that there might be as a developer you have to

21:30:40be very careful how you're dispatching operations right if you're using multi-threaded mode in redis

21:30:45so that's why i believe redis does not stick to multi-threaded or at least you know it stays

21:30:51single threaded mode so that we don't really run into these conditions so yeah this is this is um

21:30:58a quick you know overview you know basically an underlying overview of why it is is single

21:31:04threaded and why it is good to be single threaded you know it's not always bad to be single threaded

21:31:10so yeah but yeah obviously one one huge advantage huge disadvantage which you can see right away is

21:31:16that redis cannot really use your multi-core cpu now because at the best it will be just confined

21:31:23to a single core system you know a single core of the system so that's because it runs on a

21:31:29single thread same problems with no chase right so these these things are pretty much common

21:31:35so yeah that's pretty much it for this video i'm gonna see you in the next one

21:31:40hey everyone welcome back and in this video let's just go ahead and take a look at

21:31:44key matching with patterns using redis now this might seem awfully familiar if you have

21:31:50used maybe either regular expressions or if you have used any sort of database before as well so

21:31:57you know you would be able to relate to it so how does that work let's say we set a key to code damn

21:32:04and let's say this is code down blog and let's say this is go down dot com slash news right the value

21:32:11let's say another one is code main which is the main website and this is goddamn.com right let's

21:32:18say another one is code damn creator people who create good damn courses creator.com.com

21:32:24right so this should be a good enough start for us now what we could do is we can go ahead and

21:32:31actually extract out some of the keys you know we can extract all the keys like key star so that's

21:32:37one way to go about another thing you can do is you can actually pattern match these things right

21:32:42let's let's just say i said a random key as well something right so if we do key start

21:32:48you're gonna see that you get all the keys however you can just restrict it to getting code damn keys

21:32:53so how do you do that let's say we do code damn and then star right so you see now we are just

21:33:00listing keys with start with code time right that's the pattern that this should be code down

21:33:05and then any key followed by you know any number of characters once you do that you have other

21:33:13options to proceed for example let's say we want the keys which have code damn and let's go ahead

21:33:22and set one more key oops let's just go ahead and set one more key go down and let's say uh

21:33:33i don't know mamma mia i don't know let's just go ahead and set it to one two three right and now

21:33:42what i can do is i can try to list keys all of them which start with code damn and

21:33:49actually start with m or b right so if i go ahead and do that you're going to see

21:33:56that we got nothing because we have to have a star operator there as well so it starts with m or b

21:34:02and then anything in front of it right similarly you can have keys code damp which have only four

21:34:10values for characters to be precise out of out of uh apart from this you know this uh colon so

21:34:20hit enter and now you're only getting keys which have these four characters so you can see that

21:34:25you know although i did tell you that you could pretty much just go ahead and keep

21:34:28uh keys name as anything this these these sort of identifiers will actually help you narrow down

21:34:34a few keys right so you can kind of like make this a checklist that don't really keep

21:34:41question mark or start or you know these square brackets as as your key name right

21:34:48although there are ways you can escape them as well but that's what i would recommend

21:34:52you won't really need it that much unless you have a specific use case but you should know about this

21:34:57so yeah that's pretty much it for this video i'm gonna see you in the next one

21:35:01really soon hey everyone welcome back and in this video let's just go ahead and learn about list

21:35:07in redis and how they work so list in red is if you're coming from a python background you know

21:35:12the term sounds familiar it's basically and a bunch of elements in a specific order

21:35:18so what you can do is you can go ahead and create a list by saying l push and then the key and the

21:35:24value so the key would be the name of the key which is the name of the list so let's just say

21:35:29this is fruits for example and the value is [ __ ] not really [ __ ] but actually mango so mango

21:35:37let's do an l push of fruits with an apple right and let's do an l push of fruits with a

21:35:45banana let's say right so now how do you see what's the list well you can see that by saying

21:35:52l range and then the name of the list and then start and stop so if you want like start and stop

21:35:58to be 0 200 then obviously only three elements exist that's why you get only three elements

21:36:04now one interesting thing you can see is that we were using l push that means if you consider this

21:36:10as a list for example this is the direction you're always pushing at this end of the list right at

21:36:16the left end so that's why the name l push you can see you start with the mango then you push apple

21:36:22to the left that means apple comes here before mango and then banana comes here before apple and

21:36:27that's what precisely happens if you do an r push of let's say fruits and let's say um strawberry

21:36:38straw right and now you go ahead and do an l range again of fruits from 0 to 100 you'll see that

21:36:47strawberry is actually at the other end right so that's how you push to list that's how you

21:36:53get the you know total elements in the list and that's how you

21:36:57write push and lift push so this was a quick introduction to lists in the next

21:37:01video we'll see how to work with list even more with some some of the more features and

21:37:05functionalities and a bunch of use cases so i'm gonna see you in the next one really soon

21:37:12hey everyone welcome back and in this video let's just go ahead and take a look

21:37:16at how you can remove elements from a list and what are the different ways of doing that so

21:37:22first of all let me just go ahead and quickly create another list so i'm going to say l push

21:37:27fruits [ __ ] mango flute [ __ ] again mango banana let's say orange or range and let's say

21:37:40um i don't know let's keep it that right so now we have a list of three items now let's say i want to

21:37:46remove this list right remove some element from this list so one way to go about that is doing an

21:37:53l pop so it obviously means that you are doing a list pop it it might seem like that but that is

21:38:00actually that stands for left pop so that means it's gonna remove an element from the left that is

21:38:06the starting of the list right so we discussed that a list can be pretty much created and removed

21:38:12from either end so if you actually do a let me just go ahead and show you the list first before

21:38:17we remove it so if i do an l range of fruits 0 200 for example you're going to see we have orange at

21:38:24the first then banana then mango so if i do an l pop of fruits you're going to get orange so that's

21:38:30because that's the first element from the left right that is from the starting if you arrange

21:38:35this in a in a sequence where you just move this in a column instead of a in a row instead of

21:38:41a column you'll see that l stands for left makes sense similarly if you do an r pop what's going to

21:38:47happen it's going to remove mango because that's the right most element right and now l pop or both

21:38:53will remove banana because that's you know the only element left in the list so there's that now

21:38:58this is interesting let me just go ahead and do an l pop again of fruits and you're gonna see that we

21:39:03get banana but if i do it one more time you're gonna see we get nothing right and obviously it

21:39:07makes sense because the list is empty so that'll similarly that will happen on our pop as well

21:39:13but in redis what happens is that redis gives you another method and you know another function

21:39:19call you can say whatever another command which is known as blpop and br pop and what these commands

21:39:26are you can see in the helper you have to specify the key and then a timeout what these commands do

21:39:32is that they basically allow you to block the operation as long as that element is not

21:39:39available right so it will not return you nil immediately let me just go ahead and show you that

21:39:44so you see bl pop for example fruits and then a timeout of zero so if i do

21:39:50that you're gonna see it stays there and the reason it stays there is because it saw that

21:39:54okay i don't have anything to return that means i'm gonna return nil but because you have

21:39:59specified timeout of zero that means i'm gonna wait forever i'm gonna wait until someone pushes

21:40:06to this list and once they do i'm gonna give it to you right so if you had another node.js program

21:40:12for example in the background running which probably might have connected to redis and pushed

21:40:16to this list and if you did that you will see that later right so you you will see that element

21:40:22popped here but for now if you go ahead and do for example bl pop of fruits not be a lop but bl

21:40:32pop of fruits and then let's say you specify a time out of five seconds so it'll gonna wait for

21:40:38five seconds just to see you know if somebody gives you anything and if not it'll return you

21:40:44now right so it's kind of like a fail safe so that you don't really end up into deadlock situations

21:40:49um so there's that again it also has a complementary method function called b r pop

21:40:56that is again blocking right pop so fruits you know if we just go ahead and actually do

21:41:02something like um i don't know let's see l push fruits hello for example and if i do br pop fruits

21:41:13you're gonna see if i specify a timer of zero the first element you get is the key name the second

21:41:18one is the list and why is that because you can have multiple key names multiple keys specified

21:41:24here so you can have a list l push of let's say list one is hello one and l push of list two is

21:41:32hello too and if you do a br pop of list one and list two you're gonna see oops you're gonna see

21:41:41that you get list one hello one and that's it now the reason why it stopped there is because br pop

21:41:49is made in such a way that whatever number of list you specify here it's gonna return it's gonna try

21:41:56to return the right most element because of the br and it's gonna stop there right so if you

21:42:02try to do this again you see that list one is now empty because it only had single element hello one

21:42:08but if you do it now you're gonna see you get the output now from hello two that is now you get the

21:42:13output from list two so basically it's just going to scan all the list which you specify and return

21:42:18the element whichever is not null as fast as it could right and obviously if you have

21:42:23specified a timeout it's going to just wait on all of those lists now if you think about it

21:42:29it is actually very very you know it could be actually a sophisticated logic in your programming

21:42:36language where you might have to involve timers and watchers and everything and redis provides

21:42:40you on a database layer right it provides you this functionality out of the box this is why

21:42:46it is much more than just a key value store although it's advertises itself like this but

21:42:53things like these can be used to implement highly efficient cues right and they are actually used in

21:42:59a lot of production systems but you might see them being used um as an abstraction right so you might

21:43:06have a service which is using redis under the hood uh performing all these low level actions and they

21:43:11might be just exposing a simple queuing api to you so aws does that for a lot of its services um i

21:43:18hope i know that a lot of other services can also make use of this functionality as well so that is

21:43:25all um again if you try to do this it's gonna just hang on and just see whenever something gets added

21:43:32to list one or list two and it's gonna return that so yeah that's pretty much it for this video i

21:43:37hope you understood how you can push and pop and blocking pop from list in redis and that is more

21:43:45or less the majority of things which you'll do with redis like you you can also just trim and

21:43:50get elements at a certain index but you know you can refer to documentation for them all the time

21:43:56so yeah that's pretty much it for this video i'm gonna see you in the next one really soon

21:44:03hey everyone welcome back and in this video let's just go ahead and learn about

21:44:07sets in redis so set if you have a little bit of mathematical background you know consists of

21:44:14only unique values so you can create sets in radius and that is a pretty cool thing

21:44:20right because now you don't really have to worry about duplicated elements and uh you know all that

21:44:25stuff you can just throw a bunch of elements at radius in a set and redis will make sure that

21:44:30you are always having unique elements in there so that's a pretty cool thing if you have a use case

21:44:36which requires unique elements but the input kind of is arbitrary right you cannot really determine

21:44:43beforehand so how do you do that just like list you just start adding stuff right you don't really

21:44:49declare that this is a set element and not stuff like that you just say s add which is the command

21:44:54for adding something to set so s stands for set and add stands for you know adding something let's

21:45:00say i want to have a favorite languages let's say favorite lang and add javascript to it right

21:45:07i'm gonna go ahead and do s add again and favorite lang let's say python for example i've added two

21:45:13elements to the set and what i can do is now take a look at what this what the list consists

21:45:21of so for that i'm going to do go ahead and say s members and this will be favorite line right

21:45:27and when that's once i hit enter you're going to see this is python and javascript all right so

21:45:32if you try to add something let's say another thing uh favorite lang and why not let's say

21:45:38c plus plus that's also a good language and you see that every time it returns to

21:45:44a single one right apart from you know you would have seen a list that it returns you

21:45:49uh you know the number of elements but this time it returns you one and the reason for that is that

21:45:54one means that the element has actually been added to the set right if you try to add another element

21:46:01which has the same you know the same name as some element before in the set you're gonna get a zero

21:46:08that signifies that hey it has already been added right so i'm not really gonna add it

21:46:12again to the set and s members favorite lang would just reveal that hey you just have two

21:46:19uh three elements here one thing you have to remember is that this is an unordered collection

21:46:24of you know strings or whatever you're using so don't really expect any particular order to be

21:46:30maintained here right you can also get the length of this instead of just getting all

21:46:35the elements by using s card and card again is mathematical term cardinality of a set

21:46:40which means the size of the set right so it might seem very familiar if you have done set theory

21:46:47or anything like that so the names are similar um again you have a bunch of more methods like

21:46:53set difference set intersection which might be super useful if your application requires

21:47:00that right because um otherwise you will be writing it yourself in your coding layer which

21:47:07almost always is gonna be a little bit inefficient compared to what you know redis is providing you

21:47:13up front right because obviously redis is written in cc plus plus is if operating on a

21:47:20lower level and would be most likely faster than your implementation right because

21:47:26people have been writing and maintaining the source code for years so that's one thing and

21:47:32uh you can do a bunch of other stuff with redis as well i would recommend if you just learn these

21:47:37stuff on learn these things on need to know basis right if you need this on for your project you

21:47:42should just know that sets exist right and then go ahead and take a look at the documentation

21:47:47if you want to make a difference how you do that and go ahead and do that no need to like

21:47:52you know just cram this up um beforehand because the important stuff is you know about trellis you

21:47:58know about sets exist and you know about how to work with them on a bare bones level that's it

21:48:04once you are above that you should be good to go and figure out everything on your own

21:48:09so yeah that's again pretty much it for this video i'm gonna see you in the next one really soon if

21:48:14you're still watching this video make sure you comment down in the comment section i watched this

21:48:19video till the end also if you are not part of code dam's discord community you are missing out

21:48:24a lot on events which we organize on a weekly basis to code you already know the drill make sure

21:48:30you like the video subscribe to the channel if you haven't already and thank you so much for watching

This transcript was generated from the captions YouTube publishes for this video. Get the transcript of any YouTube video atfreeyoutubetranscribe.com: free, unlimited, no sign-up.