📅  最后修改于: 2023-12-03 14:44:40.701000             🧑  作者: Mango
The URL.href
API in Node.js is used to get or set the complete URL string of a parsed URL object. It returns a string containing the complete URL, including the protocol, domain, path, query parameters, and fragment identifier.
urlObject.href
None.
A string containing the complete URL.
const url = require('url');
// Creating a URL object
const myUrl = new URL('https://www.example.com/users?id=123');
// Getting the complete URL
console.log(myUrl.href);
// Expected output: https://www.example.com/users?id=123
In the above example, we have created a URL
object using the new URL()
method and passed the URL string 'https://www.example.com/users?id=123'
as a parameter. We have then printed the complete URL using the href
property of the URL
object.
In this tutorial, we have learned about the URL.href
API in Node.js, which is used to get or set the complete URL string of a parsed URL object. By using this API, we can easily retrieve or manipulate the URL.