I have a Node application that is supposed to run on both Linux and Windows environments. Using the code below, I am able to successfully get this to run on Linux, but not on Windows (which I use Powershell to run). The format seems to be correct, but the path seems to be different.
On Linux, the path pathA/pathB/pathC/file.txt
can easily be found in my project, but on Windows, this keeps getting transformed into C:\Logs\pathA\pathB\pathC\file.txt
which always throws an error because this isn't where my file is. I want it to be something like C:\myActualProject\pathA\pathB\pathC\file.txt
.
I have been following a number of solutions on Stack Overflow, but while they have been getting me closer (such as finding the right JS code to translate Linux paths into Windows paths and vice versa), they haven't helped me solve the issue altogether.
The line of code that I'm targeting, looks like this:
const ca = fs.readFileSync(path.resolve('pathA/pathB/pathC/file.txt'))
but more specifically, I'm looking at this:
path.resolve('pathA/pathB/pathC/file.txt')
I'm not sure why this is saving in the C:\Logs
directory, but then again, I don't work with Windows that often either.
Could someone please help me figure out how to read files that exist within the project directories and not Logs
?