Reputation:
I am trying to write a file in nodejs and it is working fine using below code:
writeFile() {
const sharedFolderPath = "\\server\folder";
fs.writeFile(sharedFolderPath, templatePath, (err) => {
if (err) {
console.error(err);
} else {
console.info("file created successfully");
}
})
}
It is writing into the shared drive because I have permissions but I want to do it using superuser account but not getting how to inject superuser credentials?
The same above code failed if I am using with different user machine. Is there any way to write a file in NodeJS in shared folder using credentials?
Upvotes: 0
Views: 1251
Reputation: 136425
It looks like you are using Windows and writing into a shared folder. The superuser in Windows is LOCAL_SYSTEM
but it only has superuser privileges on a local machine (otherwise a compromised LOCAL_SYSTEM
could wreck havoc in your network). In other words, running an application as Administrator would not grant it privileges to bypass shared folder permissions.
The easiest solution would be to make that shared directory writable by the users you intend to run this application under.
Upvotes: 1