WebStorm How run nodejs as root to execute shell commands?

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

  1. I'm using nodemon, so still wanted to use that
  2. Open terminal window (Inside WS: Tools->Open Terminal..)
  3. In the terminal run sudo nodemon --debug=40155 --nolazy server.js (40155 is the debug port to connect to later, you could just run node instead of nodemon)
  4. Create a remote debug configuration in WS as explained here and set the port to 40155
  5. Select that debug configuration and hit the WS debug button
  6. Set breakpoints and profit :)

It's then very easy to just go back to the WS terminal window and rerun the server.