Skip to content

Commit 4a18940

Browse files
PoojaDurgadBethGriggs
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 <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent 6893672 commit 4a18940

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
@@ -2188,7 +2188,18 @@ The `process.setgroups()` method sets the supplementary group IDs for the
21882188
Node.js process. This is a privileged operation that requires the Node.js
21892189
process to have `root` or the `CAP_SETGID` capability.
21902190

2191-
The `groups` array can contain numeric group IDs, group names or both.
2191+
The `groups` array can contain numeric group IDs, group names, or both.
2192+
2193+
```js
2194+
if (process.getgroups && process.setgroups) {
2195+
try {
2196+
process.setgroups([501]);
2197+
console.log(process.getgroups()); // new groups
2198+
} catch (err) {
2199+
console.log(`Failed to set groups: ${err}`);
2200+
}
2201+
}
2202+
```
21922203

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

0 commit comments

Comments
 (0)