Node.js process.setgroups() Method
Last Updated :
11 Oct, 2021
Improve
The process.setgroups() method is an inbuilt application programming interface of the process module which is used to set the supplementary group IDs.
Syntax:
javascript
Output:
javascript
Output:
process.setgroups( groups )Parameters: This method accepts a single parameter as mentioned above and described below.
- groups: This is a required parameter, an array of strings or integers or both denotes group ID or group name or both.
// Allocating process module
const process = require('process');
// Printing the supplementary group
// IDs before setting.
console.log(process.getgroups());
// Array of Group Ids
var arr=new Array(300, 400, 2000);
// Setting the supplementary group IDs.
process.setgroups(arr);
// Printing the supplementary group IDs.
console.log(process.getgroups());
[ 0 ] [ 300, 400, 2000, 0 ]Example 2:
// Allocating process module
const process = require('process');
if (process.setgroups) {
var arr=new Array(300, 400, 2000);
// Setting the supplementary group IDs.
process.setgroups(arr);
}
// Checking whether the method exists or not
if (process.getgroups) {
// Printing getgroups()
console.log("The supplementary group IDs :",
process.getgroups());
}
The supplementary group IDs : [ 300, 400, 2000, 0 ]Note: The above program will compile and run by using the node filename.js command, only in POSIX platforms. Reference: https://nodejs.org/api/process.html#process_process_setgroups_groups