req.query Dealing with URL Stuff
- Where the Data Comes From: It’s from the extra bits attached to the end of a URL, like when you fill out a form or put something in the search bar.
- When to Use It: Great for handling info from URLs, especially when things like search terms are involved.
Example: using req.query:
Javascript
app.get( '/search' , (req, res) => { const searchTerm = req.query.query; // Do something with the search term }); |
Difference between req.query and req.params in Express
In this article, we will learn about the req.query and req.params and we will also learn the difference between them.
Table of Content
- req.query: Dealing with URL Stuff
- req.params: Figuring Out Route Things
- Difference between req.query and req.params in Express.js