0

I am trying to check whether write permission exists inside a particular directory in my PC using Node.js. But I think Node.js is checking with respect to the admin user but when I try to download a file/directory inside that directory in the electron app, it's returning Uncaught Exception. Error: EPERM: Operation not permitted, open <file-path>.

    fs.access(download_path, fs.constants.W_OK, (err) => {
        console.log('Checking permission for downloading file...', download_path);
        if(err) {
            // Show an alert if no write access
            const options = {
                type: 'error',
                message: `You do not have permission to download file(s) at ${download_path}`,
                buttons: ['Ok']
            };

            dialog.showMessageBox(null, options, (response) => {
                console.log(response);
            });

            console.log(`File(s) cannot be downloaded at ${download_path}`);
        } else {
            console.log('Downloading file(s)');
            startDownload();
        }
    });
});
Himanshu Kumar
  • 89
  • 1
  • 10
  • do you use a windows os? run the node command prompt as administrator to solve this issue. – nima Oct 13 '21 at 12:37
  • more information on https://stackoverflow.com/questions/33419474/node-fs-error-eperm-operation-not-permitted-open – nima Oct 13 '21 at 12:37
  • That might work but we cannot give admin privileges to app. – Himanshu Kumar Oct 13 '21 at 13:28
  • Also, how to take care of that in production? – Himanshu Kumar Oct 13 '21 at 13:28
  • yes, of course, you must not run your applications with admin privileges, but for testing purposes, I told you that just to be sure about the functionality and implementations. – nima Oct 13 '21 at 13:30
  • Yes, you are right. But how to fix it code wise? Because in production, the users do not open the app by admin privileges..neither will we allow them to. – Himanshu Kumar Oct 13 '21 at 16:22

0 Answers0