[英]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? 如何通过具有root权限的WebStorm IDE运行node.js应用程序,以便让node.js运行shell命令?
Thanks in advance! 提前致谢!
最简单的方法是使用root运行WebStorm本身,父节点进程将继承权限。
As mentioned by CrazyCoder, it is possible to do this with a shell script. 正如CrazyCoder所提到的,可以使用shell脚本执行此操作。 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: 另外,人们想要运行sudo visudo
并添加以下行:
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. 最后,人们希望chmod +x
脚本,然后指定脚本的路径作为WebStorm中节点的路径。
[WS=WebStorm] [WS = WebStorm]
A little variant/addition if you want to debug it in WS as well: (without running WS as root): 如果你想在WS中调试它,还有一点变体/添加:(不以root身份运行WS):
Gist: WS terminal window + debug port + remote debug config 要点:WS终端窗口+调试端口+远程调试配置
sudo nodemon --debug=40155 --nolazy server.js
(40155 is the debug port to connect to later, you could just run node
instead of nodemon
) 在终端运行sudo nodemon --debug=40155 --nolazy server.js
(40155是稍后连接的调试端口,你可以只运行node
而不是nodemon
) It's then very easy to just go back to the WS terminal window and rerun the server. 然后返回WS终端窗口并重新运行服务器非常容易。
To add to krisp's answer: You probably also want passing environment variables from your WS configuration to work. 添加到krisp的答案:您可能还希望从WS配置中传递环境变量。
To do that add -E
to sudo
in the scipt like this 为此,在这个scipt中添加-E
到sudo
#!/bin/bash
sudo -E node "$@"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.