node.js url模块
具体地址:http://nodejs.cn/api/url.html
3种引用模式
C:\Documents and Settings\Administrator\WebstormProjects\untitled3>node
先进入node环境
> url
{ parse: [Function: urlParse],
resolve: [Function: urlResolve],
resolveObject: [Function: urlResolveObject],
format: [Function: urlFormat],
Url: [Function: Url] }
调用url
parse解析:
> url.parse('http://www.imooc.com/video/6710')
//生成项:
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'www.imooc.com',
port: null,
hostname: 'www.imooc.com',
hash: null,
search: null,
query: null,
pathname: '/video/6710',
path: '/video/6710',
href: 'http://www.imooc.com/video/6710' }
format解析:你给予的信息生成一个url
> url.format({ protocol: 'http:',
... slashes: true,
... auth: null,
... host: 'www.imooc.com',
... port: null,
... hostname: 'www.imooc.com',
... hash: null,
... search: null,
... query: null,
... pathname: '/video/6710',
... path: '/video/6710',
... href: 'http://www.imooc.com/video/6710' }
... )
//生成项:'http://www.imooc.com/video/6710'
resolve解析
> url.resolve('http://imooc.com/','/course/list')
//生成项:'http://imooc.com/course/list'
parse的应用
> url.parse('http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1')
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'imooc.com:8080',
port: '8080',
hostname: 'imooc.com',
hash: '#dloor1',
search: '?from=scott&&course=node',
query: 'from=scott&&course=node',
pathname: '/curse/list',
path: '/curse/list?from=scott&&course=node',
href: 'http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1' }
> url.parse('http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1',true)
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'imooc.com:8080',
port: '8080',
hostname: 'imooc.com',
hash: '#dloor1',
search: '?from=scott&&course=node',
query: { from: 'scott', '': '', course: 'node' }, //query被解析成了对象
pathname: '/curse/list',
path: '/curse/list?from=scott&&course=node',
href: 'http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1' }
互相对比下看看那里不一样
> url.parse('//imooc.com/curse/liast',true)
{ protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null,
search: '',
query: {},
pathname: '//imooc.com/curse/liast',
path: '//imooc.com/curse/liast',
href: '//imooc.com/curse/liast' }
> url.parse('//imooc.com/curse/liast',true,true)
{ protocol: null,
slashes: true,
auth: null,
host: 'imooc.com',
port: null,
hostname: 'imooc.com',
hash: null,
search: '',
query: {},
pathname: '/curse/liast',
path: '/curse/liast',
href: '//imooc.com/curse/liast' }
protocol : 协议
slashes: 是否有协议的双斜线
auth:
host: 域名/ip地址
port: 端口
hostname: 主机名
hash: 面向某个锚点
search: 查询字符串参数
query: 发送给http的一个参数 =号分支开的参数串
pathname:访问资源路径名
path: 路径
href: 超链接
node.js url模块的更多相关文章
- Node.js——url模块
url模块通过api可以将get提交的参数方便的提取出来
- Node.js 文件系统模块
章节 Node.js 介绍 Node.js 入门 Node.js 模块 Node.js HTTP模块 Node.js 文件系统模块 Node.js URL模块 Node.js NPM Node.js ...
- Node.js Web模块
什么是Web服务器? Web服务器是处理由HTTP客户端发送的,如web浏览器的HTTP请求的软件应用程序,并返回响应于客户端网页. Web服务器通常伴随着图片,样式表和脚本的HTML文档. 大多数W ...
- node.js基础模块http、网页分析工具cherrio实现爬虫
node.js基础模块http.网页分析工具cherrio实现爬虫 一.前言 说是爬虫初探,其实并没有用到爬虫相关第三方类库,主要用了node.js基础模块http.网页分析工具cherri ...
- Node.js的模块载入方式与机制
Node.js中模块可以通过文件路径或名字获取模块的引用.模块的引用会映射到一个js文件路径,除非它是一个Node内置模块.Node的内置模块公开了一些常用的API给开发者,并且它们在Node进程开始 ...
- Node.js工具模块
在Node.js的模块库中提供实用的模块数量. 这些模块都是很常见的,并同时开发基于任何节点的应用程序频繁使用. S.N. 模块的名称和说明 1 OS Module提供基本的操作系统相关的实用功能 2 ...
- Node.js:模块
概要:本篇博客主要介绍node.js的模块 1.创建模块 在node.js中创建一个模块非常简单,因为一个文件就是一个模块.我们只需要明白如何从其他文件中获取这个模块.Node.js提供了 expor ...
- node.js之模块
node.js之模块 1.自定义模块的设置 加载自定义模块利用require: eg: require('./custom_module.js') 2.从模块外部访问模块内的成员 2.1使用expor ...
- Node.js的安装以及Node.js的模块管理
索引: Node.js的安装以及Node.js的模块管理Node.js开发环境搭建以及对ES6的支持Node.js构建Vue.js项目Vue.js单文件组件的开发基于Vue.js的UI组件(Eleme ...
随机推荐
- iOS 苹果app提交 ITC.apps.validation.prerelease_build_missing
提示这信息,由于没有选择包文件, 在提交页面以下bulid的区域, 加入你的app就可以 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWxpbmNleG ...
- [Redux] Generating Containers with connect() from React Redux (AddTodo)
Code to be refacted: const AddTodo = (props, { store }) => { let input; return ( <div> < ...
- 关于String字符串反转
这是网上看到的一篇java面试题中的问题: 问题是: 如何将一个String字符串反转. String str = "1234567"; int length = str.leng ...
- 常用几个UITableView,UICollectionView UIScrollView关键点
UITableView UITableView 在Ios中大量使用,我们对UITableview中的有关知识进行整理 UITAbleView是表视图控制器 1 UITableView ...
- hdu2429Ping pong
Problem Description N(3<=N<=20000) ping pong players live along a west-east street(consider th ...
- DECLARE CONTINUE HANDLER FOR NOT FOUND
1.解释: 在mysql的存储过程中经常会看到这句话:DECLARE CONTINUE HANDLER FOR NOT FOUND. 它的含义是:若没有数据返回,程序继续,并将变量IS_FOUND设为 ...
- ubuntu安装jira步骤
背景:前些日子在原来的一台云主机上已经部署了一个jira系统,使用一段时间后发现jira占用很多的系统资源,导致主机上的其他服务无法正常工作,于是老大新注册了一个云主机专门用于运行jira,可见公司对 ...
- mac git 命令提示
直接进入正题: $ brew list 查看你是否已经安装了"bash-completion",如果没有,继续往下看: $ brew install bash-completion ...
- 整理:GET与POST的区别
1.根据HTTP规范,GET用于信息获取,而且应该是安全的和幂等的. (1).所谓安全的意味着该操作用于获取信息而非修改信息.换句话说,GET 请求一般不应产生副作用.就是说,它仅仅是获取资源信息,就 ...
- Flask把变量注册到模板中
使用python的Flask框架时,参考<Flask Web开发>一书时,发现书中可以在全局使用Permission.FOLLOW变量. 但是自己在尝试是,确提示变量没有定义.经过搜索,找 ...