M
path.relative
History
Added in: v0.5.0
v0.5.0
Introduced in: v0.10.0
v0.10.0
On Windows, the leading slashes for UNC paths are now included in the return value.
v6.8.0
path.relative(from, to): string
Attributes
The path.relative() method returns the relative path from from to to based
on the current working directory. If from and to each resolve to the same
path (after calling path.resolve() on each), a zero-length string is returned.
If a zero-length string is passed as from or to, the current working
directory will be used instead of the zero-length strings.
For example, on POSIX:
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb'); // Returns: '../../impl/bbb'
On Windows:
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb'); // Returns: '..\\..\\impl\\bbb'
A TypeError is thrown if either from or to is not a string.