Node | urlObject.search API
The urlObject.search() method in Node is used to get the search query within the hostname which is followed by the ‘?’ character.
Syntax :
urlObject.search()
Return : Returns the search query after ‘?’ character.
Example #1 : In these examples, we have shown how the urlObject.search() method is able to extract the search query from the hostname.
// Importing the module 'url' const url = require('url'); var adr = // Parse the address: var q = url.parse(adr, true); /* The parse method returns an object containing URL properties */ console.log(q.search); |
chevron_right
filter_none
Output :
?year=2019&month=may
Example #2 :
// Importing the module 'url' const url = require('url'); var adr = // Parse the address: var q = url.parse(adr, true); /* The parse method returns an object containing URL properties */ console.log(q.search); |
chevron_right
filter_none
Output :
?year=2k19&month=geekofthemonth
Recommended Posts:
- Node js | OS
- Why Node.js ?
- Node | URL.port API
- Node | URLSearchParams.has()
- Node.js Events
- Promises in Node.js
- Routing in Node.js
- Node | URL.pathToFileURL API
- Node | URL.host API
- Node | URL.fileURLToPath API
- Node | URL.format API
- Node | URL.pathname API
- Node | URL.search API
- Node | URLSearchParams.get()
- Node | URL.resolve(from,to) API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



