I am trying to write to a mapped network drive in Node using the windows-network-drive module and the fs module.
networkDrive.mount('\\\\server', 'Z', 'username', 'password')
.then(driveLetter => {
let filePath;
filePath = path.join(driveLetter + ":\\path\\to\\directory", "message.txt");
fs.writeFile(filePath, "text", (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
})
.catch(err => {
console.log(err)
});
How can I get the connection and path to write to a remote location?
Do I need to pass in the drive letter? If so, how do I locate it?
(node:4796) UnhandledPromiseRejectionWarning:
ChildProcessError: Command failed: net use Z: "\server" /P:Yes /user:username password System error 67 has occurred.The network name cannot be found.
net use Z: "\server" /P:Yes /user:username password(exited with error code 2)
at callback (C:\app\location\node_modules\child-process-promise\lib\index.js:33:27)
at ChildProcess.exithandler (child_process.js:279:5)
at ChildProcess.emit (events.js:159:13)
at maybeClose (internal/child_process.js:943:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
name: 'ChildProcessError',
code: 2,
childProcess:{ ChildProcess: { [Function: ChildProcess] super_: [Function] },
fork: [Function],
_forkChild: [Function],
exec: [Function],
execFile: [Function],
spawn: [Function],
spawnSync: [Function: spawnSync],
execFileSync: [Function: execFileSync],
execSync: [Function: execSync] },
stdout: '',
stderr: 'System error 67 has occurred.\r\n\r\nThe network name cannot be found.\r\n\r\n' }
P.S. this code logs Z
networkDrive.mount('\\\\server\\path\\to\\directory', 'Z', 'mdadmin', 'Password1!')
.then(function (driveLetter) {
console.log(driveLetter);
fs.writeFile('L_test.txt', 'list', (err) => {
if (err) throw err
})
});

