Reputation: 83
I need in my node.js application sudo privileges to run server on port 80, or run some others startup administration stuff. But when I will do that I don't want this privileges anymore because then I will run some external libraries from node_modules.
So, how can I disable my administration privileges from node.js script?
Upvotes: 3
Views: 972
Reputation: 111414
You need to use:
process.setgid('somegroup');
process.setuid('someuser');
See the docs:
See this article for more info:
Another way to bind to low ports without running as root would be to give a capability to bind to low ports if your system supports it - using e.g. CAP_NET_BIND_SERVICE on Linux with something like:
sudo setcap 'cap_net_bind_service=+ep' /path/to/your/program
That way you will not have to run it as root and you will not have to change to a different user later.
Upvotes: 2