DEV Community

Cover image for How to get the operating system's current user group id using Node.js?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to get the operating system's current user group id using Node.js?

Originally posted here!

To get the OS current user group id or (gid) in Node.js, you can use the userInfo() method from the os module and then use the gid property from the object returned.

// require os module
const os = require("os");

// invoke userInfo() method
const userInfo = os.userInfo();

// get gid property
// from the userInfo object
const gid = userInfo.gid;

console.log(gid); // 20
Enter fullscreen mode Exit fullscreen mode

See the above code live in repl.it.

That's all! 😃

Feel free to share if you found this useful 😃.


Oldest comments (0)