I've got a function that uses path.join
to construct a UNC path for use by another (Windows) system (the Node.js application does not need access to it, it just needs to construct the path correctly):
function constructUncPath (fileName, userLastName) {
var storageLocation = getStorageLocation(); // Returns a UNC base path
var todayDateFormatted = moment().format('YYYYMMDD');
return path.join(storageLocation, userLastName + '_' + todayDateFormatted + '_' + fileName);
}
On Windows it creates the path correctly, but on Linux it fails because it inserts forward slashes instead of backslashes:
+ expected - actual -\\path\to/user_20150101_file.txt +\\path\to\user_20150101_file.txt
Is there a way to force path.join
to use backslashes instead of forward slashes?
Or should I just explicitly replace them after the join?