profile
viewpoint

Ask questionsFeature request: url.join(baseUrl, ...others)

<!-- Thank you for reporting an issue.

This issue tracker is for bugs and issues found within Node.js core. If you require more general support please file an issue on our help repo. https://github.com/nodejs/help

Please fill in as much of the template below as you're able.

Version: output of node -v Platform: output of uname -a (UNIX), or version and 32 or 64-bit (Windows) Subsystem: if known, please specify affected core module name

If possible, please provide code that demonstrates the problem, keeping it as simple and free of external dependencies as you are able. -->

  • Version: v9.4.0
  • Platform: Darwin
  • Subsystem: url

<!-- Enter your issue details below this comment. -->

I want to join url href just like path.join, examples

url.join('http://nodejs.org', 'dist', 'download') === 'http://nodejs.org/dist/download'
url.join('http://nodejs.org/dist', 'download') === 'http://nodejs.org/dist/download'
url.resolve('http://nodejs.org/dist', 'download') === 'http://nodejs.org/download'
url.join('http://nodejs.org/dist/', '/download') === 'http://nodejs.org/dist/download'
url.join('http://nodejs.org/dist', 'http://mirror.nodejs.org/dist') === 'http://mirror.nodejs.org/dist'

// without protocol prefix, just like path.join
url.join('nodejs.org', 'dist', 'download') === path.join('nodejs.org', 'dist', 'download') === 'nodejs.org/dist/download'

What do you think about this?

nodejs/node

Answer questions 88250

My solution

path.join(SERVER_URL, imageAbsolutePath).replace(':/','://');

Please be careful it does not work on Windows, since path.join converted / to \.

useful!

Related questions

--max-http-header-size= is not allowed in NODE_OPTIONS hot 6
Crash with "req.handle.writev is not a function" on Socket.Writable.uncork hot 2
pkg-exports: "." errors without a specified `main` hot 2
shutdown ENOTCONN on TLS.Socket._final hot 2
HTTP/2 requests eventually start throwing NGHTTP2_ENHANCE_YOUR_CALM errors hot 2
stream.finished behaviour change hot 2
Assertion `(parser->current_buffer_len_) == (0)' failed hot 1
Node.js 12.10 throwing EPROTO on HTTPS request hot 1
Remove util.inherits usage internally? hot 1
[Bug] Node 10.1.0 TLS issue with ldap: Client network socket disconnected before secure TLS connection was established hot 1
ReferenceError: internalBinding is not defined hot 1
Incorrect timezone hot 1
HPE_INVALID_HEADER_TOKEN on http requests hot 1
HPE_INVALID_HEADER_TOKEN on http requests hot 1
crypto, bad decrypt hot 1
Github User Rank List