Good day.

Faced with the banal task - get the parameter from Url.

url.parse (request.url) .query); getting from url

http: // localhost: 8888 / delay? cat = betty I was able to get the parameters: cat = betty

url.parse (request.url) .query ["cat"]; -> undefined

How can I programmatically get a collection of parameters and then get a value for each of them? Is this possible here?

thank

    1 answer 1

    https://nodejs.org/api/querystring.html

    querystring.parse(url.parse(s).search.substr(1)) 

    Example:

     > qs = url.parse("/delay?cat=betty") Url { protocol: null, slashes: null, auth: null, host: null, port: null, hostname: null, hash: null, search: '?cat=betty', query: 'cat=betty', pathname: '/delay', path: '/delay?cat=betty', href: '/delay?cat=betty' } > s = qs.search '?cat=betty' > querystring.parse(s) { '?cat': 'betty' } > querystring.parse(s.substr(1)) { cat: 'betty' } > f = s => querystring.parse(url.parse(s).search.substr(1)) [Function] > f("/any?x=12&y=123&smth") { x: '12', y: '123', smth: '' }