Method description:
Convert a parsed URL object into a formatted URL string.
grammar:
The code copy is as follows:
url.format(urlObj)
Receive parameters:
urlObj represents a URL object and can contain the following properties: (can be compared with examples)
href full path
Protocolis protocol (such as http://)
auth
hostname hostname
port port
host host (host name + port)
pathname '/' can be understood as a directory
query parameter list
search query conditions (that is, the parameter list with "?")
hash hash value
example:
The code copy is as follows:
var url = require('url');
var a = url.format({
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'
});
console.log(a);
//Output result: http://example.com:8080/one?a=index&t=article&m=default