摘要:本篇Node.js教程讲解了有关官方URL模块的内容,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。
这个模块含有一些系列方法函数处理和解析URL
使用require('url')使用
parsing(string)
这个方法返回包含具体路由信息的对象
没有就返回null
url.parse('//user:pass@host.com:8080/p/a/t/h?query=string')
{
protocol: 'http:',
slashes: true,
auth: 'user:pass',
host: 'host.com:8080',
port: '8080',
hostname: 'host.com',
hash: null,
search: '?query=string',
query: 'query=string',
pathname: '/p/a/t/h',
path: '/p/a/t/h?query=string',
href: '//user:pass@host.com:8080/p/a/t/h?query=string#hash'
}
1. href,完整的路径
2. pathname,路径名字不包含参数
3.host比hostname多一个端口号format(urlObj)
同理这个函数就是根据obj的信息构造一个路径
var obj = { protocol: 'https', host: 'www.cycok.com:4000', pathname: 'index' }url.format(obj)//returns 'https://www.cycok.com:4000/index' url.resolve(from, to)
提供一个基础的路径,还有要去的路径,解析出浏览器最终会去的路径
url.resolve('/one/two/three', 'four') // '/one/two/four'
url.resolve('//example.com/', '/one') // '//example.com/one'
url.resolve('//example.com/one', '/two') // '//example.com/two'
本文由职坐标整理发布,欢迎关注职坐标Node.js频道,学习更多WEB前端知识!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号