Skip to content

Commit f6aa7c8

Browse files
PoojaDurgadtargos
authored andcommitted
doc: add a example code to API doc property
example code added to the process.setgroups() API doc property in process.md PR-URL: #35738 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 86ed87b commit f6aa7c8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/api/process.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,18 @@ The `process.setgroups()` method sets the supplementary group IDs for the
22102210
Node.js process. This is a privileged operation that requires the Node.js
22112211
process to have `root` or the `CAP_SETGID` capability.
22122212

2213-
The `groups` array can contain numeric group IDs, group names or both.
2213+
The `groups` array can contain numeric group IDs, group names, or both.
2214+
2215+
```js
2216+
if (process.getgroups && process.setgroups) {
2217+
try {
2218+
process.setgroups([501]);
2219+
console.log(process.getgroups()); // new groups
2220+
} catch (err) {
2221+
console.log(`Failed to set groups: ${err}`);
2222+
}
2223+
}
2224+
```
22142225

22152226
This function is only available on POSIX platforms (i.e. not Windows or
22162227
Android).

0 commit comments

Comments
 (0)