Home > Web Front-end > JS Tutorial > Instructions for using the url.parse method in node.js_node.js

Instructions for using the url.parse method in node.js_node.js

WBOY
Release: 2016-05-16 16:27:52
Original
1553 people have browsed it

Method description:

Convert a URL string into an object and return it.

Grammar:

Copy code The code is as follows:

url.parse(urlStr, [parseQueryString], [slashesDenoteHost])

Receive parameters:

urlStr URL string

parseQueryString When it is true, the query module will be used to analyze the query string. The default is false

slashesDenoteHost    

The default is false, a string in the form //foo/bar will be interpreted as { pathname: ‘//foo/bar’ }

If set to true, a string of the form //foo/bar will be interpreted as { host: ‘foo’, pathname: ‘/bar’ }

Example:

Copy code The code is as follows:
var url = require('url');
var a = url.parse('http://example.com:8080/one?a=index&t=article&m=default');
console.log(a);

//Output result:
{
Protocol: 'http' ,
auth : null ,
Host : 'example.com:8080' ,
Port: '8080' ,
Hostname : 'example.com' ,
hash : null ,
Search : '?a=index&t=article&m=default',
Query : 'a=index&t=article&m=default',
Pathname : '/one',
Path: '/one?a=index&t=article&m=default',
href : 'http://example.com:8080/one?a=index&t=article&m=default'
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template