Parse the Query String
Easy · URLs
In a Node HTTP server, req.url holds only the path and query, like "/search?q=node&page=2". new URL(req.url, "http://localhost") turns it into a full URL, so you can read url.searchParams.
Write a function parseQuery(url) that returns the query parameters as an object:
- values stay strings, decoded (%20 and + become spaces)
- a key that appears more than once becomes an array of its values, in order
- no query → {}
Next: Parse Cookies