All right so here comes the answer. 1
Before you do anything I recommend reading through the docs and seeing how these parameters work. 2
And remember that we're using the colon and then we're going to give our parameter a name so that we 3
can tap into it later on using req.params. the name that we specified. 4
So now we can head into our app.js and you can create that route any way you wish. 5
I'm going to put it just before the end right down here 6
just before my app.listen. And I'm going to say app.get and then I'm going to specify / 7
posts/: and then here comes the name of my parameter which you can call anything you 8
wish as long as it makes sense to you 9
but I'll call it postName. And then I'll add my callback, my req and res and then inside my callback I 10
am going to tap into that parameter called postName. 11
So I want to console log it. So I'm going to log the req.params.postName. And it has 12
to be spelt exactly the same as you see here after the colon. 13
But there's no colons down here 14
remember that. This is all that you need in order to tap into a dynamic 15
URL right? 16
Because we're using this parameter to decide what it is that we should do inside our app.get. 17
So we can now say if they said I wanted you know the post that has a post name of testing then we will 18
send them over there 19
and if they wanted the post that had a name of ordinary I love pets then we will show them that page. 20
So this is the first step towards getting a dynamic website created. 21
And this is all down to using Node and Express, nothing else. 22
Now we can test this and if we head over to posts/ anything you want to write afterwards then 23
it will get logged down here in our console. 24
So this is the first step towards achieving our dynamic website and feel free to mess around with it, 25
try out different parameter names, try out multiple parameters as you can see where they've got 26
this one which is a single parameter and this one which is another parameter 27
and you can actually tap into both just by using req.params. the name of your parameter in your 28
URL. 29
So play around with that and once you're ready we'll head over to the next challenge.