Express req.query Property
What you’ll learn
- How to read URL query parameters with
req.query. - How to handle optional filters, pagination, and sorting inputs.
- How to convert and validate query values safely.
- How
req.querydiffers fromreq.params.
Usage syntax
javascript
req.query
req.query.page
req.query.search1
Read pagination query params
javascript
app.get('/products', function (req, res) {
var page = Number(req.query.page || 1);
var limit = Number(req.query.limit || 10);
res.json({ page: page, limit: limit });
});2
Use optional filter query values
javascript
app.get('/search', function (req, res) {
var keyword = req.query.q || '';
var sort = req.query.sort || 'relevance';
res.json({ keyword: keyword, sort: sort });
});❓ FAQ
It is an object containing query string parameters from the URL.
They come from the part after ? in the URL, such as ?page=2&sort=asc.
Often yes, though parser behavior can vary; always validate and convert types explicitly.
req.query comes from query string, while req.params comes from route path segments.
No. Treat it as user input and validate before using in filtering, SQL, or business logic.
Did you know?
req.query provides parsed key-value pairs from the URL query string, and values should be validated before use.
4 people found this page helpful
