Resolving the URL Components
A useful feature of the url module is the ability to resolve URL components in the same manner as a browser would. This allows you to manipulate URL strings on the server side to make adjustments in a URL. For example, you might want to change the URL location before processing a request because a resource has moved or changed parameters.
To resolve a URL to a new location, use the following syntax:
url.resolve(from, to)
The from parameter specifies the original base URL string. The to parameter specifies the new location to which you want the URL to resolve. The following code shows an example of resolving a URL to a new location.
var url = require('url');var originalUrl = 'http://user:pass@host.com:80/resource/path?query=string#hash'; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access