Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node fs Error: EPERM: operation not permitted, open

Tags:

node.js

fs

I get this error in my app:

Error: EPERM: operation not permitted, open 'C:\Program Files (x86)\Full Menu\db\main.json'

The app I have is built with electron-boilerplate. I am using this function to get the path to the root of the app:

path.dirname(process.execPath) 

And this is the script that writes the file:

fs.writeFile(apath + '/db/' + elem + '.json', JSON.stringify(results) 

I know what the problem is: permissions. But how could I get this working without running the app as an administrator?

like image 598
Sergiu Avatar asked Oct 29 '15 16:10

Sergiu


People also ask

How do I fetch a file in node JS?

Downloading a file using node js can be done using inbuilt packages or with third party libraries. GET method is used on HTTPS to fetch the file which is to be downloaded. createWriteStream() is a method that is used to create a writable stream and receives only one argument, the location where the file is to be saved.

How do I save a node js file?

writeFile("/tmp/test", message, function (err) { if (err) { return console. log(err); } console. log("The file was saved!"); }); }); Hope this works for you.


1 Answers

For the benefit of searchers; I has this error. I added full permissions for Everyone as a test, but that didn't fix it. The issue was that the file was set to readonly (by source control).

Unchecking the readonly option in the file properties fixed the issue.

like image 93
JsAndDotNet Avatar answered Sep 18 '22 12:09

JsAndDotNet