url 模块:
1、用于解析和处理URL的字符串
2、处理带参数的请求
比如这个请求:http://localhost:8990/news?newsid=1&author=zs,带有参数:newsid=1&author=zs
引入模块:require('url');
url.parse();
parse函数:接受一个URL字符串,解析它,然后返回一个URL对象
const urlString = url.parse('http://www.nodejs.org/some/url/?with=query¶m=that#about');
console.log(urlString);
/*
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'www.nodejs.org',
port: null,
hostname: 'www.nodejs.org',
hash: '#about',
search: '?with=query¶m=that',
query: 'with=query¶m=that',
pathname: '/some/url/',
path: '/some/url/?with=query¶m=that',
href: 'http://www.nodejs.org/some/url/?with=query¶m=that#about'
}
*/
protocol: 'http:', ------------------------------------ url协议
slashes: tr