I'm using node.js and want to send file to the frontend. So I specified the direct path to my file like: path = "c:/app/A" and when I run res.sendFile(path, fileName); I'm getting the Error: ENOENT: no such file or directory, stat '/home/projects/c:/app/A' How I can disable this auto path adding "/home/projects" part? I want to download file that is not in my project folder with my code. File is in my computer in different folder.
Asked
Active
Viewed 181 times
0
-
if you can provide your project directory structure and in which file you are executing res.sendFile – rajesh-nitc May 13 '19 at 11:37
-
1please submit your code – Kamil Naja May 13 '19 at 11:38
-
Possible duplicate of [res.sendFile absolute path](https://stackoverflow.com/questions/25463423/res-sendfile-absolute-path) – Vikash_Singh May 13 '19 at 11:57
-
@Rajesh I want to download file that is not in my project folder with my code. File is in my computer in different folder. Could I do that? – Anna May 13 '19 at 13:04
-
You have the server running on a Linux and are attempting to access a path that is only valid in Windows. This seems to imply that there are two machines that don't have a common filesystem and as such the Linux one can't access the filesystem of the Windows one. – Dan D. May 16 '19 at 08:36
2 Answers
0
Try to use \\
as path delimiter for Windows (c:\\app\\A
) and read about Node.js module "path".

Volodymyr Sichka
- 531
- 4
- 10
0
so I need use just new URL(file:${"c:/app/A"}
);
so it will be like that:
let filename = "someName.com"
let absPath = "c:/app/someName.com";
fs.writeFileSync(`${filename}`, fs.readFileSync(new URL(`file:${absPath}`)));
res.download(`${filename}`, `${filename}`)

Anna
- 1
- 2