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!
最简单的方法是使用root运行WebStorm本身,父节点进程将继承权限。
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.
To add to krisp's answer: You probably also want passing environment variables from your WS configuration to work.
To do that add -E
to sudo
in the scipt like this
#!/bin/bash
sudo -E node "$@"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.