setgid

process.setgid(id)

Sets the group identity of the process. (See setgid(2).) This accepts either a numerical ID or a groupname string. If a groupname is specified, this method blocks while resolving it to a numerical ID.

console.log('Current gid: ' + process.getgid());
try {
  process.setgid(70); // example id for _www user
  console.log('New gid: ' + process.getgid());
}
catch (err) {
  console.log('Failed to set gid: ' + err);
}

Alternative using string name for group:

console.log('Current gid: ' + process.getgid());
try {
  process.setgid("_www"); // example id for _www user
  console.log('New gid: ' + process.getgid());
}
catch (err) {
  console.log('Failed to set gid: ' + err);
}
$ sudo node doc_test.js 
Current gid: 0
New gid: 70

Example failure due to insufficient permissions:

$ node doc_test.js 
Current gid: 20
Failed to set gid: Error: EPERM, Operation not permitted

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s