This article mainly introduces node. url in js. the format method is described in this document. format method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see
Method description:
Convert a parsed URL object into a formatted URL string.
Syntax:
The Code is as follows:
Url. format (urlObj)
Receiving parameters:
UrlObj indicates a URL object and can contain the following attributes: (for example)
Complete href path
Protocolis protocol (such as http ://)
Auth
Hostname Host Name
Port
Host (host name + port)
Pathname'/'can be understood as a directory
Query parameter list
Search query condition (that is, add "?" Parameter List)
Hash Value
Example:
The Code is as follows:
Var url = require ('url ');
Var a = url. format ({
Protocol: 'http ',
Auth: null,
Host: 'example. com: 8080 ',
Port: '123 ',
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 ();
// Output result: http://example.com: 8080/one? A = index & t = article & m = default