Run node commands as root in electron app

Viewed 1502

I am trying to write electron program for creating and configuring multiple Apache websites sites. But my problem is that i need to read from and write to files that are owned by root user. such as /etc/hosts, etc/apache/sites-avaliable/mysite.conf. my program works only when I run it as root from terminal. but when i package it. I cannot launch it as root user. there as some pakages as sudo-prompt - npm. but they accept only terminal commands. But I want to use native node functions for accessing file system such as

fs.writeFileSync(`/etc/apache2/sites-available/${serverName}.conf`, template);
1 Answers

Yes, it is possible via electron.

You can use https://github.com/jorangreef/sudo-prompt to exec a command using sudo and show a graphical OS password prompt.

You can use sudo-prompt from Electron as well as from any Node script.

It is regularly updated, has no dependencies and does not require any native compilation.

Related