相关疑难解决方法(0)

如何在"?"之后访问GET参数 在快递?

我知道如何获得这样的查询的参数:

app.get('/sample/:id', routes.sample);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我可以req.params.id用来获取参数(例如2in /sample/2).

但是,对于url来说/sample/2?color=red,如何访问变量color?

我试过req.params.color但它没用.

node.js query-string express

486
推荐指数
9
解决办法
43万
查看次数

Node.js:具有多个查询参数的Express app.get

我想查询yelp api,并有以下路由:

app.get("/yelp/term/:term/location/:location", yelp.listPlaces)
Run Code Online (Sandbox Code Playgroud)

当我向GET请求时

http://localhost:3000/yelp?term=food&location=austin,

我收到了错误

Cannot GET /yelp?term=food&location=austin
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

get node.js query-string express

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

express ×2

node.js ×2

query-string ×2

get ×1