更新时间:2023-11-14 09:29:58
是的,您可以访问 req.url 并手动解析:
var url = require('url');
var url_parts = url.parse(request.url,true);
var query = url_parts.query;
但是,在expressjs中,已经为您完成了,您可以使用 req.query :
var id = req.query.id; // $ _GET [id]
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. Is there a method to get the query string parameters?
Yes you can access req.url and parse it manually:
var url = require('url');
var url_parts = url.parse(request.url, true);
var query = url_parts.query;
However, in expressjs it's already done for you and you can simply use req.query for that:
var id = req.query.id; // $_GET["id"]