Edit:
As Andreas correctly points out in a comment, url.resolve would only help if the problem is as simple as the example. url.parse also applies to this question because it returns consistently and predictably formatted fields via the URL object that reduces the need for "code full of ifs".

Email codedump link for Can I use require(&quot;path&quot;).join to safely concatenate urls?