0 1 00:00:00,410 --> 00:00:00,680 All right. 1 2 00:00:00,690 --> 00:00:03,620 So here comes the next problem that we have to solve. 2 3 00:00:03,810 --> 00:00:11,670 As I showed you before, if we head over to compose and we created a new post that just had a title of 3 4 00:00:11,670 --> 00:00:19,980 Test an our URL if we type posts/Test spelt at exactly the same way as our title when we hit 4 5 00:00:20,010 --> 00:00:23,280 enter then we get match found 5 6 00:00:23,280 --> 00:00:23,720 right? 6 7 00:00:23,910 --> 00:00:30,900 But here's a problem. Let's say if I go into my Atom and if the requestedTitle is not equal to any of 7 8 00:00:30,900 --> 00:00:34,070 the store title I have, I'm going to use else 8 9 00:00:34,110 --> 00:00:37,270 and then I'm going to log not a match. 9 10 00:00:37,680 --> 00:00:41,380 So now if I again go and create my Test post 10 11 00:00:41,700 --> 00:00:47,140 and now inside my home page I've got home and test. I can see that I've got that there 11 12 00:00:47,160 --> 00:00:48,420 but in the URL 12 13 00:00:48,450 --> 00:00:57,750 if I put /posts/test with a lowercase 't', in this case once I hit enter inside my 13 14 00:00:57,750 --> 00:01:00,690 console you can see I get not a match. 14 15 00:01:00,960 --> 00:01:08,160 And that is because in our code we're testing to see if storedTitle is equal to requestedTitle. 15 16 00:01:08,400 --> 00:01:14,680 And if the requestedTitle had a lowercase t and our storedTitle because it's a title right? 16 17 00:01:14,790 --> 00:01:16,860 It probably has a title case right? 17 18 00:01:16,850 --> 00:01:19,600 So most of the words are capitalized. Then 18 19 00:01:19,650 --> 00:01:21,550 this is not going to be true. 19 20 00:01:21,870 --> 00:01:27,630 But in most cases, URLs should be lowercase. so it doesn't really make sense to put in a capital 20 21 00:01:27,630 --> 00:01:30,630 T in there, it looks very very weird. 21 22 00:01:30,630 --> 00:01:35,610 The other problem we have is that when you look at some of the blog posts say medium right? 22 23 00:01:35,760 --> 00:01:41,070 You can see that they use word - word as their formatting for the URL. 23 24 00:01:41,340 --> 00:01:44,880 And this is what we call kebab case in programming. 24 25 00:01:44,880 --> 00:01:52,530 Now if I had a post that has two words in his title and I tried to use kebab case on it, say / 25 26 00:01:52,530 --> 00:01:54,540 posts/ 26 27 00:01:54,540 --> 00:01:57,810 Another-post, 27 28 00:01:57,810 --> 00:02:00,770 then it's also going to be not a match 28 29 00:02:00,780 --> 00:02:02,100 right? 29 30 00:02:02,160 --> 00:02:03,750 How do we solve this? 30 31 00:02:03,780 --> 00:02:11,110 I want to introduce you to something that developers use a lot with Node which is something called Lodash. 31 32 00:02:11,430 --> 00:02:20,020 And this is simply a utility library that makes it easier to work with Javascript inside your Node apps. 32 33 00:02:20,340 --> 00:02:27,850 If you head over here to lodash.com you can see how to install it, how to use it inside Node. 33 34 00:02:28,050 --> 00:02:29,600 Now here comes the challenge. 34 35 00:02:29,610 --> 00:02:34,290 The goal of this challenge is for you to read through the documentation of Lodash 35 36 00:02:34,500 --> 00:02:38,930 and I want you to have experience and practice in implementing the documentation. 36 37 00:02:39,210 --> 00:02:46,500 We've already used a couple of libraries now such as Express, EJS, Requests and I want you to have practice 37 38 00:02:46,590 --> 00:02:51,010 of implementing the documentation in a safe kind of environment 38 39 00:02:51,030 --> 00:02:53,620 right? Because I'll show you how to do it very soon. 39 40 00:02:53,730 --> 00:02:55,250 But I want you to give it a go. 40 41 00:02:55,350 --> 00:03:01,300 And once you've installed it and required it, then I want you to head over to the documentation. And if 41 42 00:03:01,300 --> 00:03:09,930 you search for lowercase then you can see that they have a method that allows you to turn all strings 42 43 00:03:10,020 --> 00:03:11,640 into a lower case. 43 44 00:03:11,920 --> 00:03:17,850 And if you look at the example it actually goes much further than that. It will in fact ignore all of 44 45 00:03:17,850 --> 00:03:24,630 the hyphens or the underscores and it will simply just give you a pure string to work with. 45 46 00:03:24,630 --> 00:03:32,130 So you should be able to use this library in order to make this URL actually give us a match for this 46 47 00:03:32,190 --> 00:03:33,620 particular title. 47 48 00:03:33,660 --> 00:03:37,930 When I type in this URL after you are done with implementing Lodash 48 49 00:03:38,370 --> 00:03:46,780 and when I hit enter, in our console we should see match found. Pause the video and try to complete this challenge. 49 50 00:03:48,060 --> 00:03:50,770 So here's hint number 1. 50 51 00:03:50,820 --> 00:03:56,640 If you check out lodash.com you can see they tell you how to install it and it shows you how to do 51 52 00:03:56,640 --> 00:03:57,800 it using NPM. 52 53 00:03:57,800 --> 00:04:02,990 And this is pretty familiar to us by now. We just have to install Lodash right? 53 54 00:04:03,000 --> 00:04:04,200 So let's go ahead and do that. 54 55 00:04:04,200 --> 00:04:10,750 Let's head over to hyper and let's Control + C to quit our current nodemon session. And 55 56 00:04:11,100 --> 00:04:15,780 we're going to use npm i or npm install whichever way you prefer. 56 57 00:04:16,020 --> 00:04:21,420 And then we're going to spell out lodash and make sure that you have the right spelling. 57 58 00:04:21,420 --> 00:04:22,470 Then we hit enter 58 59 00:04:22,530 --> 00:04:25,980 and that gets installed to our current project. 59 60 00:04:25,980 --> 00:04:32,280 The next thing you see here in the documentation is how to use it using Node.js which is perfect 60 61 00:04:32,280 --> 00:04:32,950 right? 61 62 00:04:33,060 --> 00:04:37,120 And you can see this familiar require thing that we've got going on. 62 63 00:04:37,320 --> 00:04:44,970 And the thing about Lodash is that a Lodash actually refers to this which is known to some people 63 64 00:04:45,000 --> 00:04:46,710 as an underscore. 64 65 00:04:46,710 --> 00:04:53,690 And so their preferred way of working with Node is to create a new variable or constant 65 66 00:04:53,700 --> 00:05:00,750 if you're using your versions of Javascript that is simply just a underscore and you set that to be 66 67 00:05:00,780 --> 00:05:02,420 the Lodash library. 67 68 00:05:02,790 --> 00:05:09,420 And then when you go to the documentation and you want to use one of its methods say the one we want 68 69 00:05:09,420 --> 00:05:17,060 which is lower case, then you simply have underscore or lodash .lowercase and then in between 69 70 00:05:17,130 --> 00:05:20,330 you pass in the string that you want to change into lowercase. 70 71 00:05:20,550 --> 00:05:24,470 See if that is enough of a hint to be able to complete the challenge. 71 72 00:05:26,290 --> 00:05:27,290 So here comes hint 72 73 00:05:27,310 --> 00:05:35,560 number 2. In order for our requestedTitle to match with our storedTitle we need to reformat them so they're 73 74 00:05:35,650 --> 00:05:38,120 both in the same format. 74 75 00:05:38,380 --> 00:05:44,590 And it doesn't matter whatever it is that the user typed in here. It could be uppercase, lowercase, kebab 75 76 00:05:44,590 --> 00:05:47,400 case, snake case, whatever it may be. 76 77 00:05:47,440 --> 00:05:52,750 We want to convert it to the same format in order to work with it and compare it. 77 78 00:05:52,750 --> 00:05:58,660 And that means that we have to format the storedTitle using that same lowercase method as well so that 78 79 00:05:58,660 --> 00:06:00,200 they are equatable. 79 80 00:06:00,250 --> 00:06:04,300 Pause the video now and see if you can now complete the challenge.