[英]Request Parameter in express js
I am using express.js and I am trying to fetch the request parameter using the following code. 我正在使用express.js,我正在尝试使用以下代码获取请求参数。
app.configure(function () {
app.use(express.static(__dirname + '/public'));
});
app.get('/', function (req, res) {
console.log(req.params[0]);
console.log(req.params.id);
res.render('/public/index.html');
});
My url looks like this. 我的网址看起来像这样。
http://localhost:8080/?id=34.
I am not getting the request parameter. 我没有得到请求参数。 I tried all possibilities.
我尝试了所有可能性。
You need to reference req.query
您需要引用
req.query
req.params
is for params embedded in the URL path. req.params
用于URL路径中嵌入的参数。
You can also use 你也可以使用
req.param('id')
req.param( 'ID')
It will fetch path,body and query params for you. 它将为您获取路径,正文和查询参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.