Change path separator using path module
node.js, path
Solution
John's answer will only replace the first instance of a '\'
img.src = thisImagePath.replace(new RegExp('\\' + path.sep, 'g'), '/');
Would replace all of them.
You can pass the 'g' flag to `.replace` but this non-standard.
Problem
Here is my code: ``` var thisImageName = thisRow["imagename"]; var thisImagePath = path.relative("./public", __dirname + "/public/uploads/" + thisImageName + ".jpg"); console.log(thisImagePath); // returns __dirname\public\uploads\ img.src = thisImagePath.split(path.sep).join("/"); ``` To get the appropriate image path, I have to split by the path separator and then join the array with the appropriate slash. Does anyone know of a more efficient way of doing this?