summaryrefslogtreecommitdiff
path: root/doc/api
diff options
context:
space:
mode:
authorLiran Tal <liran.tal@gmail.com>2020-04-11 17:02:59 +0300
committerAnna Henningsen <anna@addaleax.net>2020-04-28 00:47:49 +0200
commit6b2e3afee95f5d5fdc0751b6f58c447b87d8ec47 (patch)
tree71c1547a20ba8be89e0ed44f84272680e1de860f /doc/api
parent4e8797353c86ba86799ce0d19236d133188f1c9d (diff)
downloadnode-new-6b2e3afee95f5d5fdc0751b6f58c447b87d8ec47.tar.gz
doc: improve WHATWG url constructor code example
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: https://github.com/nodejs/node/pull/32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc/api')
-rw-r--r--doc/api/url.md7
1 files changed, 7 insertions, 0 deletions
diff --git a/doc/api/url.md b/doc/api/url.md
index 49f56509fe..6950c92f09 100644
--- a/doc/api/url.md
+++ b/doc/api/url.md
@@ -105,6 +105,13 @@ const myURL = new URL('/foo', 'https://example.org/');
// https://example.org/foo
```
+The URL constructor is accessible as a property on the global object.
+It can also be imported from the built-in url module:
+
+```js
+console.log(URL === require('url').URL); // Prints 'true'.
+```
+
A `TypeError` will be thrown if the `input` or `base` are not valid URLs. Note
that an effort will be made to coerce the given values into strings. For
instance: