All right. 1
So here comes the answer to challenge 1. 2
If you've already completed challenge 1 and you just want to see how it's done then continue watching 3
the video. 4
If you've gone through all of the hints and you're still stuck and you really don't know what to do 5
then also keep playing and I'll show you the answer. 6
But if you still want to keep trying then pause the video before I reveal the answer. 7
All right here we go. 8
So inside our home. 9
ejs, 10
we're going to create that h1 that just says home. And then we're going to go into our app.js 11
which is our server code to try and render that page. 12
And the route that we're going to target is going to be the home route. 13
So we're going to say app.get and we're going to target the home route or the root route. 14
That's the one that's just the /. 15
And then we're going to put in a callback function with our req and res as per usual. 16
And then inside this function is where we're going to render our home.ejs. 17
And if you remember the method for that using Express is res.render and then we specify what it is 18
that we want to render. 19
And remember the page that we want to render has to be something.ejs and it has to be inside a folder 20
called views in the root of our main project folder 21
in the same hierarchical level as app.js. 22
Now the page that we want to render in this case is home.ejs 23
so all we have to specify is the string home inside a set of quotation marks. And then we'll close everything 24
off with some semi-colons. 25
So now if we hit Save and we make sure that we're inside our ejs-challenge folder then we're going 26
to use nodemon to start our app.js and run our server. So service starts on port 3000 27
I'm going to head over to localhost:3000 28
and this is how we achieve the goal for Challenge 1. 29
Now if you manage to get here without needing any of the hints then that's a huge pat on the back and 30
a gold star for you. 31
Now if you needed to have a look at a few of the hints then that's fine as well. 32
See if in the coming challenges you can reduce the number of hints you need and rely more on Sstack Overflow 33
or Google to achieve what it is that you want instead of looking at the hints or the answers. And only 34
use them when you're well and truly stuck and you can't move forwards without watching a hint or two. 35
So that's all for challenge 1. In the next video we're going to head over to the next challenge.