Thursday, 13 January 2022

is there any replacement for the nodejs url.resolve function?

nodeJs provides the https://nodejs.org/api/url.html module which allows to:

  • resolve two relative urls:
require('url').resolve(`profile/user/99/details/`, `../../55/details/`) // -> 'profile/user/55/details/'
  • resolve a relative url and an absolute url:
require('url').resolve(`profile/user/99/details/`, `http://example.com`) // -> 'http://example.com/'
  • resolve an absolute url and a relative url:
require('url').resolve(`http://example.com`, `profile/user/99/details/`) // -> 'http://example.com/profile/user/99/details/'
  • resolve two absolute urls:
require('url').resolve(`http://example.com`, `https://stackoverflow.com`) // ->
'https://stackoverflow.com/'

however require('url').resolve was deprecated

what would be the correct (as in non deprecated) way to resolve the urls like in the examples above?



from is there any replacement for the nodejs url.resolve function?

No comments:

Post a Comment