
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
The uid-number npm package is used to convert a username/group name into a numeric user id (UID) and group id (GID). It is a simple utility that can be useful when dealing with file system permissions in Node.js applications, especially when interfacing with native system file permissions where numerical IDs are required.
Convert username to UID
This feature allows you to convert a given username to its corresponding numeric user ID (UID). The function takes a username as its first argument and a callback as the second argument. The callback receives an error object (if any), the UID, and the GID associated with the username.
const uidNumber = require('uid-number');
uidNumber('username', (err, uid, gid) => {
if (err) {
console.error('Error getting UID:', err);
} else {
console.log('UID:', uid);
}
});
Convert group name to GID
This feature allows you to convert a given group name to its corresponding numeric group ID (GID). The function takes a group name as its second argument and a callback as the third argument. The callback receives an error object (if any), the UID (which is undefined in this case), and the GID associated with the group name.
const uidNumber = require('uid-number');
uidNumber(undefined, 'groupname', (err, uid, gid) => {
if (err) {
console.error('Error getting GID:', err);
} else {
console.log('GID:', gid);
}
});
The posix npm package provides similar functionality to uid-number by offering methods to get user and group information based on names or IDs. It also provides additional POSIX-related utilities, making it a more comprehensive package for interacting with POSIX systems.
The userid npm package is another alternative that can convert between usernames and UIDs as well as group names and GIDs. It also provides synchronous versions of these methods, which can be useful in certain scenarios where asynchronous execution is not desired.
Use this module to convert a username/groupname to a uid/gid number.
Usage:
npm install uid-number
Then, in your node program:
var uidNumber = require("uid-number")
uidNumber("isaacs", function (er, uid, gid) {
// gid is null because we didn't ask for a group name
// uid === 24561 because that's my number.
})
FAQs
Convert a username/group name to a uid/gid number
The npm package uid-number receives a total of 1,163,388 weekly downloads. As such, uid-number popularity was classified as popular.
We found that uid-number demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.