Node.js url模块
2022/7/30 14:22:52
本文主要是介绍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.js url模块的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist
- 2024-03-11icons for vue
- 2024-03-07breadcrumbs react js
- 2024-03-06react login page example
- 2024-03-06react router uselocation
- 2024-03-04postgres jsonb_set
- 2024-03-01react native uuid
- 2024-02-29vuejs sidebar