Understanding the Differences between req.query and req.params in Express

Fri Jan 13, 2023

In Express, req.query and req.params are both used to access values from the URL, but they are used in slightly different ways.

req.query is used to access query parameters, which are key-value pairs appended to the end of the URL with a "?" character. For example, in the URL http://example.com/search?q=express, "q=express" is a query parameter and can be accessed using req.query.q.

req.params is used to access parameters in the route path, which are placeholders in the URL that can be matched to values. For example, in the route app.get('/users/:id', ...), ":id" is a parameter and the value can be accessed using req.params.id.

In short req.query is used for getting the query string values and req.params is used for getting the route parameters.

DCT Academy
Full Stack web development training institute in Bangalore

Launch your GraphyLaunch your Graphy
100K+ creators trust Graphy to teach online
𝕏
Best MERN Full Stack Development Course | Bangalore | Offline | Online | 100% Placements | Training Institute | Front End Course | React JS Training | Online Course India 2024 Privacy policy Terms of use Contact us Refund policy