Using the Node path.join function in Angular or Typescript

Ole Ersoy
1 min readDec 4, 2019
Image by Bessi from Pixabay

Gotcha

This is probably not a good idea. See this SO post:

Also join from node will replace http:// with http:/ . It will remove a slash.

Since we needed join like functionality we created this:

It works in a web context and can be used to join paths in your front end.

Scenario

We have two paths:

const p1 = '/foo/boo/';const p2 = '/pity/the/foo';

We want to concatenate them without having to first check whether the second path starts with a / .

In other words we want to avoid the concatenated path looking like this:

/foo/boo//pity/the/foo

Approach

Dependencies

Approach

import { join } from '@fireflysemantics/join';

Demo

--

--