I\'m developing on windows, but need to know how to convert a windows path (with backslashes \\
) into a POSIX path with forward slashes (/
)?
Given that all the other answers rely on installing (large) third party modules: this can also be done as a one-liner for relative paths (which you should be using 99.999% of the time) using Node's standard library path module, and more specifically, taking advantage of its dedicated path.posix
and path.win32
namespaced properties/functions:
const path = require("path");
// ...
const definitelyPosix = somePathString.split(path.sep).join(path.posix.sep);
This will convert your path to POSIX format irrespective of whether you're already on POSIX platforms, or on win32, while requiring zero dependencies.