Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right so here comes the answer.
Before you do anything I recommend reading through the docs and seeing how these parameters work.
And remember that we're using the colon and then we're going to give our parameter a name so that we
can tap into it later on using req.params. the name that we specified.
So now we can head into our app.js and you can create that route any way you wish.
I'm going to put it just before the end right down here
just before my app.listen. And I'm going to say app.get and then I'm going to specify /
posts/: and then here comes the name of my parameter which you can call anything you
wish as long as it makes sense to you
but I'll call it postName. And then I'll add my callback, my req and res and then inside my callback I
am going to tap into that parameter called postName.
So I want to console log it. So I'm going to log the req.params.postName. And it has
to be spelt exactly the same as you see here after the colon.
But there's no colons down here
remember that. This is all that you need in order to tap into a dynamic
URL right?
Because we're using this parameter to decide what it is that we should do inside our app.get.
So we can now say if they said I wanted you know the post that has a post name of testing then we will
send them over there
and if they wanted the post that had a name of ordinary I love pets then we will show them that page.
So this is the first step towards getting a dynamic website created.
And this is all down to using Node and Express, nothing else.
Now we can test this and if we head over to posts/ anything you want to write afterwards then
it will get logged down here in our console.
So this is the first step towards achieving our dynamic website and feel free to mess around with it,
try out different parameter names, try out multiple parameters as you can see where they've got
this one which is a single parameter and this one which is another parameter
and you can actually tap into both just by using req.params. the name of your parameter in your
URL.
So play around with that and once you're ready we'll head over to the next challenge.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.