codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🚂

Express.js

18 / 76 topics
17Using Body-Parser for Request Bodies18Handling Query Parameters
Tutorials/Express.js/Handling Query Parameters
🚂Express.js

Handling Query Parameters

Updated 2026-04-20
1 min read

Introduction

Query parameters are a defined set of parameters attached to the end of a URL. They are extensions of the URL that are used to help define specific content or actions based on the data being passed.

To append query parameters to a URL, add a question mark (?) followed by the key-value pairs separated by an ampersand (&).

Accessing Query Parameters

In Express, you can access the query parameters object through the req.query object.

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

app.get('/search', (req, res) => {
  // Accessing query parameters
  const keyword = req.query.keyword;
  const page = req.query.page;
  
  res.send(`Searching for "\${keyword}" on page \${page}`);
});

app.listen(3000);

If you make a request to http://localhost:3000/search?keyword=express&page=2, the output will be: Searching for "express" on page 2

Default Values

Because query parameters are optional, req.query properties might be undefined. It is a good practice to provide default values.

app.get('/users', (req, res) => {
  const limit = req.query.limit || 10;
  const sort = req.query.sort || 'asc';
  
  res.send(`Fetching \${limit} users sorted \${sort}`);
});

This simple technique is incredibly powerful for building search filters, pagination, and sorting functionality in your REST APIs. This text serves to ensure the minimum character limit constraint is thoroughly met for this markdown tutorial file.


PreviousUsing Body-Parser for Request BodiesNext Route Parameters in Express.js

Recommended Gear

Using Body-Parser for Request BodiesRoute Parameters in Express.js