Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why NodeJS fs module won't read or write to visible folder shared on the network? #4390

Open
worknotalent opened this issue May 7, 2024 · 6 comments

Comments

@worknotalent
Copy link

Details

I shared a folder on my network through the use of Windows UI.

I'm able to access this folder and edit its content through the File Explorer but problems arise when I try to do the same programmatically. Any fs functions will work on the hoster machine but on any secondary device it won't.

I had to pass the hoster session credentials when I first tried to access the folder from the secondary device so I'm guessing this folder is invisible to NodeJS for the same reason but I'm not sure, and if so I don't know how to pass credentials to NodeJS to make network folders accessible to it.

Node.js version

20.12.0

Example code

node:fs:2342
return binding.writeFileUtf8(
^

Error: UNKNOWN: unknown error, open '//DESKTOP-NAME/folder/test.txt'
at Object.writeFileSync (node:fs:2342:20)
at file:///C:/Users/me/some_folder/some_file.js:3:4
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'open',
path: '\\DESKTOP-NAME\folder\test.txt'
}

Node.js v20.12.0

Operating system

Microsoft Windows [Version 10.0.19045.4291]

Scope

code

Module and version

fs

@RedYetiDev
Copy link
Member

@nodejs/platform-windows does Node.js support network drives?

@worknotalent
Copy link
Author

Someone on StackOverflow suggested to use a package called node-cmd to update the credentials first and then use the fs function but it still fails for me :
import cmd from "node-cmd"
cmd.runSync(net use \\DESKTOP-${device} /user:${username} ${password});

@preveen-stack
Copy link
Contributor

Did you try escaping backslashes
\\DESKTOP-NAME\folder\test.txt

@mStirner
Copy link

You cant use a smb/cifs share as path in node.js.
Mount that network share as local resource like drive X: or what ever you want, and use then x:/path/to/wher-ever-you-want-to-go.

@mStirner
Copy link

@nodejs/platform-windows does Node.js support network drives?

Does node support nfs/linux network shares? No.
You have to mount the network shared resources as local medium/device, and use that in node.js

@tniessen
Copy link
Member

Does Node.js not support UNC paths on Windows? I was under the impression that any UNC path referring to a real file system (not an emulated file system or USB device or so) would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants