Express.js req.query Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

In Express.js, req.query is an object of parsed query-string parameters — everything after ? in the URL. For /search?term=express&limit=10, you get keys like term and limit.

Use it for optional filters, search, sort, and pagination. Path identity belongs on req.params. Configure parsing with app.set('query parser', …). The pathname alone is req.path.

Syntax

Read req.query in your Express.js route handler. Start with this line.

Express
req.query
req.query.page
req.query.sort
CallWhat it does
req.queryPrimary signature.
req.query.pageRelated call form.
req.query.sortRelated call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.query
req.query.page
req.query.sort

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

req.query is an object of parsed query-string parameters. Values are usually strings (or nested objects/arrays depending on the query parser).

Express
// GET /search?term=express&limit=10
req.query; // { term: 'express', limit: '10' }

Express.js Examples

Example 1 — Read Search Query Keys

Return the parsed object for a simple search URL.

Express
const express = require('express');
const app = express();

app.get('/search', (req, res) => {
  // GET /search?term=express&limit=10
  const { term, limit } = req.query;
  res.json({ term, limit });
});

app.listen(3000);

How It Works

  1. Client sends a query string. Keys sit after ?, joined with &.
  2. Express parses into an object. req.query gets term and limit.
  3. Values are strings. limit is '10', not the number 10.
  4. Destructure what you need. Missing keys would be undefined.

Example 2 — Pagination with Defaults

Coerce page/limit to numbers and fall back when keys are missing.

Express
const express = require('express');
const app = express();

app.get('/products', (req, res) => {
  const page = Number(req.query.page) || 1;
  const limit = Number(req.query.limit) || 10;
  res.json({ page, limit });
});

app.listen(3000);

How It Works

  1. Read optional keys. Query params do not have to be present.
  2. Convert with Number. Turns '2' into 2.
  3. Use || defaults. NaN or 0 from bad input falls back (tighten this in real apps).
  4. Respond with numbers. Ready for skip/limit math after further validation.

Example 3 — Extended Query Parser

Opt into nested objects when you need bracket syntax (common after Express 4 → 5 upgrades).

Express
const express = require('express');
const app = express();

// Express 5 default is 'simple'; enable nesting when needed
app.set('query parser', 'extended');

app.get('/catalog', (req, res) => {
  // GET /catalog?filter[color]=red&filter[size]=m
  res.json(req.query);
});

app.listen(3000);

How It Works

  1. Set the parser early. app.set('query parser', 'extended') uses qs.
  2. Client sends bracket keys. Nested filter fields arrive in the query string.
  3. Parser builds objects. req.query.filter.color becomes available.
  4. Still validate. Nested shapes are still untrusted user input.

Runtime Support

req.query is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send URLs with query strings to your app.

✓ Server · Express 4 & 5

req.query

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.query Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is an object of parsed query-string parameters from the part of the URL after ?, such as ?page=2&sort=asc.
Usually yes for simple keys. Repeated keys can become arrays. Nested objects need the extended query parser. Always coerce and validate before use.
req.query comes from the optional query string. req.params comes from named path segments defined in the route, like /users/:id.
app.set('query parser', …) chooses how the string is parsed: simple, extended, false (empty object), or a custom function.
No. It is a server-side Express request property. Browsers only send the URL; your app parses the query into req.query.

Next: req.range()

Parse Range headers for partial content responses.

req.range() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful