Node.js process.setgroups() Method
Last Updated :
11 Oct, 2021
The process.setgroups() method is an inbuilt application programming interface of the process module which is used to set the supplementary group IDs.
Syntax:
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.
Return: It doesn’t return anything. For setting group Ids the Node.js process needs root permission as it is a privileged operation.
Note: This function will only work on POSIX platforms. Not available on windows or android platform so will cause to an error i.e. TypeError, setgroups is not a function.
Below examples illustrate the use of process.setgroups() method in Node.js:
Example 1:
const process = require( 'process' );
console.log(process.getgroups());
var arr= new Array(300, 400, 2000);
process.setgroups(arr);
console.log(process.getgroups());
|
Output:
[ 0 ]
[ 300, 400, 2000, 0 ]
Example 2:
const process = require( 'process' );
if (process.setgroups) {
var arr= new Array(300, 400, 2000);
process.setgroups(arr);
}
if (process.getgroups) {
console.log( "The supplementary group IDs :" ,
process.getgroups());
}
|
Output:
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...