Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Using Data and Route Parameters

1 Answer

Marco Cornejo
Marco Cornejo
3,412 Points

req.params is an object containing properties mapped to Route parameters, in other words, the Route parameters are simply keys being declared, and req.params assign a value to them.

Say we want to display card with id 6, the composition is as follows

//Route path: /card/:id
//Request URL: http://localhost:3000/cards/6
//req.params: { "id": "6" }

Note that req.params can store multiple key:values, which is how most search engines apply filters or redeem/referral urls work, for further details check the Documentation: https://expressjs.com/en/api.html#req.params

I hope I answered your question, cheers!