process.initgroups(user, extraGroup): void
Attributes
The process.initgroups() method reads the /etc/group file and initializes
the group access list, using all groups of which the user is a member. This is
a privileged operation that requires that the Node.js process either have root
access or the CAP_SETGID capability.
Use care when dropping privileges:
import { getgroups, initgroups, setgid } from 'node:process'; console.log(getgroups()); // [ 0 ] initgroups('nodeuser', 1000); // switch user console.log(getgroups()); // [ 27, 30, 46, 1000, 0 ] setgid(1000); // drop root gid console.log(getgroups()); // [ 27, 30, 46, 1000 ]
const { getgroups, initgroups, setgid } = require('node:process'); console.log(getgroups()); // [ 0 ] initgroups('nodeuser', 1000); // switch user console.log(getgroups()); // [ 27, 30, 46, 1000, 0 ] setgid(1000); // drop root gid console.log(getgroups()); // [ 27, 30, 46, 1000 ]
This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in Worker threads.