How to get GET (query string) variables in Express.js on Node.js?

前端 未结 26 3487
庸人自扰
庸人自扰 2020-11-21 23:53

Can we get the variables in the query string in Node.js just like we get them in $_GET in PHP?

I know that in Node.js we can get the URL in the request.

26条回答
  •  -上瘾入骨i
    2020-11-22 00:14

    From my point of view I think that many people mix two different concepts. During the REST development I was familiar with passing information in the URL with two ways "path variables" and "request parameters"(query parameters). The RFC describes the parts of URI like this: enter link description here So I understood that author would like to know how to pass request parameters. I would only want to make the topic easier to understand, but the solution was mentioned here many times.

    You can get query parameters from the URI with request.query., the second mentioned solution was request.params. and with this you can get the path variables.

提交回复
热议问题