0

While I am starting to get a hold of NodeJS programming, I am a bit confused by when to use request params and how their practical use differs from using query strings.

In particular, I can do localhost:8080/:param1 in the URL followed by req.params in the code or localhost:8080/?param1=value in the URL followed by req.query in the code, and get the same outcome - the value of param1. How should I decide when to use which? What is a good use case for either of these approaches?

4

You use

localhost:8080/param1value

when you are referring to a resource, as in

http://barnesandnoble.com/books/12345/how-to-win-friends

You use

localhost:8080?param1=value

when you are supplying a parameter to a request, as in

http://barnesandnoble.com/search?searchterm=friends

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.