Courses / Node.js
3. Parsing URL and query parameters (url and URLSearchParams)
Extract pathname and query parameters from request URLs using the WHATWG URL API or url module.
JavaScript
Parsing URL and query parameters (url and URLSearchParams)
Breaking a request URL into its pathname and key/value query parameters using the WHATWG URL API or legacy url module.
"I need to read /users/42?page=2 and get the path /users/42 and the page=2 parameter as data."
The URL API turns a full URL string into an object with properties like pathname and searchParams; URLSearchParams gives easy methods to read, iterate, and modify query parameters.
"I need to read /users/42?page=2 and get the path /users/42 and the page=2 parameter as data."
The URL API turns a full URL string into an object with properties like pathname and searchParams; URLSearchParams gives easy methods to read, iterate, and modify query parameters.