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);
const definitelyWindows = somePathString.split(path.sep).join(path.win32.sep);
This will convert your path to POSIX (or Windows) format irrespective of whether you’re already on a POSIX (or Windows) compliant platform, without needing any kind of external dependency.