Reputation: 1953
I'm trying to verify if a file exists using fs.readFile. However, I am getting an error telling me a URL that definitely exists does not exist.
Here is the error in the console and the path open in windows explorer on my machine: https://i.sstatic.net/y52Pp.png
Here is my code:
fs.readFile(url, "utf8", function (error, data) {
if (error){
//saveContentError(url);
throw error;
}
});
message: "ENOENT: no such file or directory, open 'C:\Users\my-name\AppData\Roaming\Company%20Name\DashboardApps\Apps\eCatalog\Contents\Product Groups\order.csv'"
path: "C:\Users\my-name\AppData\Roaming\Company%20Name\DashboardApps\Apps\eCatalog\Contents\Product Groups\order.csv"
I also tried changing url
to url = url.replace(' ', '%20')
This is from my app.js which has a different root than my node folder. Initially this was an issue as I was only passing the end of the path and it was adding it to the wrong root. However since I'm passing it the full path now (starting with C:) I assumed this would correct that issue.
Does anyone know why I'm being told that no file exists when in reality it does?
Thank you very much for your time. Let me know if I am being unclear or if you need more information.
Upvotes: 0
Views: 1516
Reputation: 2696
Instead of creating a path using \
, either use /
, or \\
. The latter because \
is an escape character, which needs to be escaped before using it -> \\
to use \
For instance \n
is the newline character... So you are sending strange requests, instead of a correct path...
Upvotes: 1