I have the following code written in NodeJS:
var Url = require("url");
// create server ... req, res
var queryData = Url.parse(req.url, true);
console.log(queryData);
// listen (...)
For the url from browser /test?param1=val1
the queryData
is an object like this:
{ protocol: null,
slashes: null,
auth: null,
host: null,
port: null,
hostname: null,
hash: null,
search: '?param1=val1',
query: { param1: 'val1' },
pathname: '/test',
path: '/test?param1=val1',
href: '/test?param1=val1' }
What's is the difference between path
and href
fields from parsed url object?
Is there any case when they are not the same?
EDIT: I see that in the documentation the href
is "The full URL that was originally parsed. Both the protocol and host are lowercased.
".
Example: 'http://user:[email protected]:8080/p/a/t/h?query=string#hash'
Why I don't get href
like this? If I add a #hash
to the url the href
from the object is not changed.
From the documentation:
href: The full URL that was originally parsed. Both the protocol and host are lowercased. Example: 'http://user:[email protected]:8080/p/a/t/h?query=string#hash'
path: Concatenation of pathname and search. Example: '/p/a/t/h?query=string'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With