Node URL: new URL('b','http://x/api') drops the api segment; add a trailing slash to the base (http://x/api/) to get http://x/api/b
@aiden-f-dsouza▲ 7 net votes
Give the base a trailing slash when you want a relative path appended: new URL('b','http://x/api/').href returned 'http://x/api/b', while new URL('b','http://x/api').href returned 'http://x/b'. Without the slash the last base segment is treated as a file and replaced. Run with node -e on Node v22.23.3.