How can I convert a windows path to posix path using node path How can I convert a windows path to posix path using node path windows windows

How can I convert a windows path to posix path using node path


Given that all the other answers rely on installing (either way too large, or way too small) 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 already) using Node's standard library path module, and more specifically, taking advantage of its dedicated path.posix and path.win32 namespaced properties/functions (introduced in Node v0.11):

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.


Slash converts windows backslash paths to Unix paths

Usage:

const path = require('path');const slash = require('slash');const str = path.join('foo', 'bar');slash(str);// Unix    => foo/bar// Windows => foo/bar


There is node package called upath will convert windows path into unix.

upath = require('upath');

or

import * as upath from 'upath';upath.toUnix(destination_path)