How compare dynamically two paths in the same domain and get the relative path between them?
var path2 = "http://site.net/test1/test2/img/1.jpg" // test example
var path3 = "http://site.net/test1/img/1.jpg" // test example
And get a return path2 to path3 for example = "../../img/"
A better way would be to use path.relative
const path = require('path');
const path2 = "http://example.com/test1/test2/img/1.jpg";
const path3 = "http://example.com/test1/img/1.jpg";
const relativePath = path.relative(path.dirname(path2),path.dirname(path3));
console.log(relativePath); //'../../img'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With