MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Route Parameters, Query Strings & Request Body Parsing0%
Study Materials
Node.js & Express.jsProgress 0%
1.1Node.js Architecture, V8 Engine & Single-Threaded Event Loop1.2Call Stack, Callback Queue, Microtask Queue & Libuv Workers1.3Non-Blocking Asynchronous Code with Promises and Async/Await
3.1Native HTTP Server vs Express Framework Philosophy3.2Express Application Initialization, Routing & Request/Response Objects3.3Route Parameters, Query Strings & Request Body Parsing
HomeTutorialsNode.js & Express.jsRoute Parameters, Query Strings & Request Body Parsing
Middleware Pipeline: Application-Level, Router-Level & Third-Party

Route Parameters, Query Strings & Request Body Parsing

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Client applications transmit data to backend APIs through three primary channels: Route Parameters (identifying specific entities in the URL path), Query Strings (filtering, pagination, and sorting parameters), and the Request Body (structured JSON payloads).


1. Route Parameters (req.params)

Route parameters are named URL segments used to capture values at specified positions in the URL path. They are defined using a colon : prefix:

1import express from 'express';
2const app = express();
3 
4// Single parameter: /api/users/42
5app.get('/api/users/:id', (req, res) => {
6 const userId = req.params.id; // "42" (string type)
7 res.json({ id: userId });
8});
9 
10// Multiple parameters: /api/courses/react-101/reviews/99
11app.get('/api/courses/:courseSlug/reviews/:reviewId', (req, res) => {
12 const { courseSlug, reviewId } = req.params;
13 res.json({ courseSlug, reviewId });
14});

Note: All values in req.params are initially strings. Convert them with Number(req.params.id) or parseInt() when querying numeric database IDs.


2. Query Strings (req.query)

Query strings follow the ? character in a URL and are separated by &. They are commonly used for filtering, pagination, and searching:

1GET /api/products?category=electronics&minPrice=100&sort=asc&page=2

Express parses query strings automatically into the req.query object:

1app.get('/api/products', (req, res) => {
2 const { category, minPrice, sort, page = 1, limit = 20 } = req.query;
3 
4 console.log('Category filter:', category);
5 console.log('Minimum price:', minPrice);
6 console.log('Page number:', page);
7 
8 res.json({
9 filters: { category, minPrice: Number(minPrice) },
10 pagination: { page: Number(page), limit: Number(limit) }
11 });
12});

3. Request Body (req.body)

The request body carries large, structured payloads (JSON, form data) typically in POST, PUT, or PATCH requests. In Express, you MUST register body-parsing middleware before accessing req.body:

1// Parse application/json
2app.use(express.json({ limit: '1mb' }));
3 
4// Parse application/x-www-form-urlencoded (HTML form submissions)
5app.use(express.urlencoded({ extended: true }));
6 
7app.post('/api/orders', (req, res) => {
8 const { items, shippingAddress, paymentToken } = req.body;
9 
10 if (!items || items.length === 0) {
11 return res.status(400).json({ error: 'Order must contain at least one item' });
12 }
13 
14 res.status(201).json({
15 orderId: 'ord_12345',
16 status: 'CONFIRMED',
17 totalItems: items.length
18 });
19});

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Given the route definition app.get('/articles/:category/:id'), what will req.params contain when a client accesses /articles/tech/55?
Question 2
In an incoming URL /api/search?q=nodejs&sort=desc, how do you access the search term nodejs in an Express handler?
Question 3
What will req.body evaluate to if a client sends a JSON payload to an Express app that has NOT registered app.use(express.json())?
Question 4
What is the data type of req.params.id in the route /users/:id when the user requests /users/100?
Question 5
Why should you configure { limit: '1mb' } in express.json({ limit: '1mb' })?

Next Lesson

Middleware Pipeline: Application-Level, Router-Level & Third-Party

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Express Application Initialization, Routing & Request/Response ObjectsMiddleware Pipeline: Application-Level, Router-Level & Third-Party

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Node.js & Express.js with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext