0 1 00:00:00,240 --> 00:00:00,570 All right. 1 2 00:00:00,570 --> 00:00:03,630 So here comes the answer to challenge 1. 2 3 00:00:03,750 --> 00:00:08,730 If you've already completed challenge 1 and you just want to see how it's done then continue watching 3 4 00:00:08,730 --> 00:00:09,500 the video. 4 5 00:00:09,840 --> 00:00:14,820 If you've gone through all of the hints and you're still stuck and you really don't know what to do 5 6 00:00:15,150 --> 00:00:18,420 then also keep playing and I'll show you the answer. 6 7 00:00:18,450 --> 00:00:24,460 But if you still want to keep trying then pause the video before I reveal the answer. 7 8 00:00:24,480 --> 00:00:25,470 All right here we go. 8 9 00:00:25,650 --> 00:00:27,050 So inside our home. 9 10 00:00:27,220 --> 00:00:27,610 ejs, 10 11 00:00:27,630 --> 00:00:33,510 we're going to create that h1 that just says home. And then we're going to go into our app.js 11 12 00:00:33,810 --> 00:00:37,130 which is our server code to try and render that page. 12 13 00:00:37,320 --> 00:00:40,760 And the route that we're going to target is going to be the home route. 13 14 00:00:40,830 --> 00:00:46,440 So we're going to say app.get and we're going to target the home route or the root route. 14 15 00:00:46,530 --> 00:00:48,590 That's the one that's just the /. 15 16 00:00:48,710 --> 00:00:55,140 And then we're going to put in a callback function with our req and res as per usual. 16 17 00:00:55,560 --> 00:01:00,790 And then inside this function is where we're going to render our home.ejs. 17 18 00:01:00,900 --> 00:01:08,790 And if you remember the method for that using Express is res.render and then we specify what it is 18 19 00:01:08,790 --> 00:01:10,070 that we want to render. 19 20 00:01:10,230 --> 00:01:16,830 And remember the page that we want to render has to be something.ejs and it has to be inside a folder 20 21 00:01:16,830 --> 00:01:20,800 called views in the root of our main project folder 21 22 00:01:21,120 --> 00:01:25,550 in the same hierarchical level as app.js. 22 23 00:01:25,740 --> 00:01:29,230 Now the page that we want to render in this case is home.ejs 23 24 00:01:29,370 --> 00:01:37,140 so all we have to specify is the string home inside a set of quotation marks. And then we'll close everything 24 25 00:01:37,140 --> 00:01:39,180 off with some semi-colons. 25 26 00:01:39,180 --> 00:01:46,230 So now if we hit Save and we make sure that we're inside our ejs-challenge folder then we're going 26 27 00:01:46,230 --> 00:01:54,020 to use nodemon to start our app.js and run our server. So service starts on port 3000 27 28 00:01:54,090 --> 00:01:56,700 I'm going to head over to localhost:3000 28 29 00:01:56,970 --> 00:02:02,530 and this is how we achieve the goal for Challenge 1. 29 30 00:02:02,540 --> 00:02:07,280 Now if you manage to get here without needing any of the hints then that's a huge pat on the back and 30 31 00:02:07,280 --> 00:02:08,710 a gold star for you. 31 32 00:02:08,960 --> 00:02:13,460 Now if you needed to have a look at a few of the hints then that's fine as well. 32 33 00:02:13,460 --> 00:02:19,860 See if in the coming challenges you can reduce the number of hints you need and rely more on Sstack Overflow 33 34 00:02:19,860 --> 00:02:25,910 or Google to achieve what it is that you want instead of looking at the hints or the answers. And only 34 35 00:02:25,910 --> 00:02:31,690 use them when you're well and truly stuck and you can't move forwards without watching a hint or two. 35 36 00:02:31,880 --> 00:02:37,140 So that's all for challenge 1. In the next video we're going to head over to the next challenge.