URL Parameters vs Query Strings in Express.js

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
In this article we'll learn about the URL params and query strings in express.js. For a beginner it hard not to have the doubt between this topic. We'll be covering the following in sequences:
What URL parameters are
What query parameters are
Differences between them
Accessing params in Express
Accessing query strings in Express
When to use params vs query
What does we understand by the query string and URL parameters ? When you start working with backend using Express.js, one thing you’ll see very often is URL parameters and query strings. At first, both look similar, but they are used for different purposes.
Let’s understand them in a simple way
URL parameters are part of the URL path itself. They are used to identify a specific resource.
/users/101
Here, 101 is a URL parameter.
In Express, we define it using :
app.get('/users/:id', (req, res) => {
res.send(`User ID is ${req.params.id}`);
});
If you open:
/users/101
You’ll get:
User ID is 101
Used to identify specific data
Mandatory (usually required in route)
Query parameters come after the ? in a URL and are used to send extra information.
/products?category=shoes&price=1000
Here:
category=shoes
price=1000
In Express:
app.get('/products', (req, res) => {
const category = req.query.category;
const price = req.query.price;
res.send(`Category: \({category}, Price: \){price}`);
});
If you open:
/products?category=shoes&price=1000
You’ll get:
Category: shoes, Price: 1000
Used for filtering, sorting, optional data
Optional (can be missing)
| Feature | URL Parameters | Query Strings |
|---|---|---|
| Position | Inside URL path | After ? |
| Example | /users/101 |
/users?id=101 |
| Purpose | Identify resource | Filter / extra info |
| Required | Usually yes | Optional |
| Access in Express | req.params |
req.query |
app.get('/posts/:postId', (req, res) => {
console.log(req.params);
res.send(req.params.postId);
});
If URL is:
/posts/55
Output:
55
app.get('/search', (req, res) => {
console.log(req.query);
res.send(req.query.keyword);
});
If URL is:
/search?keyword=react
Output:
react
This is where most beginners get confused, so remember this simple rule
You are fetching specific resource
Example:
/users/101
/posts/45
You are filtering or customizing results
Example:
/products?category=electronics
/users?page=2&limit=10
Params = "Which exact item?"
Query = "How do you want the data?"
Both can be used together:
/users/101?active=true
101 → specific user (param)
active=true → extra condition (query)
That’s it! Once you understand this difference, working with APIs in Express becomes much easier!