URL Resolution Lab
In this lab, you will be using the built-in url
module of Node.js to resolve and transform URLs with different base URLs and relative URLs. The url.resolve()
method is used to resolve a base URL and a relative URL into an absolute URL. The method takes two arguments: the base URL and the relative URL. The result will be a new absolute URL constructed from the two input URLs.
For example, if you have a base URL https://example.com/a/b/c/
and the relative URL ../d/e/f
, the resulting URL will be https://example.com/a/b/d/e/f
.
In this lab, you will create a Node.js module that exports the following functions:
-
resolveAbsoluteURL
: A function that takes a base URL and a relative URL as its parameters and returns the resolved absolute URL using theurl.resolve()
method. -
customURLResolver
: A higher-order function which, when called with a base URL, returns a new function. The new function accepts only the relative URL and returns the resolved absolute URL.
Remember to use ESM (ECMAScript Module) syntax for importing and exporting modules.
Challenges
- Export
resolveAbsoluteURL
function. - Export
customURLResolver
function. resolveAbsoluteURL
function should correctly resolve the absolute URL.customURLResolver
function should return a new function that resolves the absolute URL correctly.