parse() Method accepts a URL character string , Analyze it , Then return to a URL object . If urlString Not a string , Type error is thrown . If it exists auth The attribute cannot be decoded , Will be thrown URIError.
grammar :
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])
parameter 1: Required {string} To parse url address
parameter 2:{boole} Will query (query) Parameters are parsed into object form , Default to false
parameter 3:{boole} If true , In text string // After and next / The first tag before will be interpreted as the host . for example , given //foo/bar, The result will be {host:
‘foo’, pathname: ‘/bar’}, instead of {pathname: ‘//foo/bar’}. Default value :false.
Output by default // console.log(req.url);
Url { protocol: null, slashes: null, auth: null, host: null, port: null,
hostname: null, hash: null, search: '?name=sing&age=25', query: [Object: null
prototype] { name: 'sing', age: '25' }, pathname: '/list', path:
'/list?name=sing&age=25', href: '/list?name=sing&age=25' }
// parseQueryString by ture
// query Parameters are parsed into object form query: [Object: null prototype] { name: 'sing', age: '25' }
Common introduction methods
// url object const url = require('url'); // deconstruction let { query, pathname } = url.parse(
req.url, true);
Technology