How Can I run a node.js application through WebStorm IDE with root privileges in order to let node.js run shell commands?
Thanks in advance!
The easiest way is to run WebStorm itself with root, parent node process will inherit the privileges.
As mentioned by CrazyCoder, it is possible to do this with a shell script. To elaborate, the script would look something like this:
#!/bin/bash
sudo /path/to/node "$@"
Additionally one would want to run sudo visudo
and add the following line:
username ALL=(ALL) NOPASSWD: /path/to/node
Finally, one would want to chmod +x
the script and then specify the path to the script as the path to node in WebStorm.
[WS=WebStorm]
A little variant/addition if you want to debug it in WS as well: (without running WS as root):
Gist: WS terminal window + debug port + remote debug config
sudo nodemon --debug=40155 --nolazy server.js
(40155 is the debug port to connect to later, you could just run node
instead of nodemon
)It's then very easy to just go back to the WS terminal window and rerun the server.