On this page

    M

    process.setgroups

    History
    process.setgroups(groups): void
    Attributes
    groups:integer[]

    The process.setgroups() method sets the supplementary group IDs for the Node.js process. This is a privileged operation that requires the Node.js process to have root or the CAP_SETGID capability.

    The groups array can contain numeric group IDs, group names, or both.

    import process from 'node:process';
    
    if (process.getgroups && process.setgroups) {
      try {
        process.setgroups([501]);
        console.log(process.getgroups()); // new groups
      } catch (err) {
        console.error(`Failed to set groups: ${err}`);
      }
    }
    if (process.getgroups && process.setgroups) {
      try {
        process.setgroups([501]);
        console.log(process.getgroups()); // new groups
      } catch (err) {
        console.error(`Failed to set groups: ${err}`);
      }
    }

    This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in Worker threads.