Skip to content

Commit b2a3daf

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 6d42747 commit b2a3daf

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

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

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

0 commit comments

Comments
 (0)