编程语言
首页 > 编程语言> > Node.js url模块

Node.js url模块

作者:互联网

url

url就是网址,比如http://www.baidu.com/20220728/news/page1/index.html?count=20&maxid=123456#top1等等都是url。

url的组成

网址的组成:协议、域名、pathname(路径)、querystring(查询字符串)、hash(哈希值)

url模块

在url模块中,我们主要用的是parse这个方法,也就是解析网址。

var url = require('url');
var adr = 'http://localhost:8080/default.html?year=2017&month=february';
var q = url.parse(adr, true);
//如果第一个值时第二个值默认是false console.log(q) console.log(q.host,typeof(q.host)); console.log(q.pathname,typeof(q.pathname)); console.log(q.search,typeof(q.search)); var qdata = q.query; console.log(qdata,typeof(qdata)) console.log(qdata.month,typeof(q.month));

当parse第二个值是true时

 当第二个值是false时

 

标签:Node,console,log,url,qdata,js,typeof,var
来源: https://www.cnblogs.com/forever-ljf/p/16533615.html