Get the passwd user entry from a username or user identifier (UID)
Works on macOS and Linux. See user-info if you need cross-platform support.
npm install passwd-user
import {passwdUser} from 'passwd-user';
console.log(await passwdUser('sindresorhus'));
/*
{
username: 'sindresorhus',
password: '*',
userIdentifier: 501,
groupIdentifier: 20,
fullName: 'Sindre Sorhus',
homeDirectory: '/home/sindresorhus',
shell: '/bin/zsh'
}
*/
await passwdUser(501);
console.log('Got entry for user 501');
const user = await passwdUser();
console.log(`Got entry for user ${user.userIdentifier}`);
Returns an object with:
usernamepassworduserIdentifier: UIDgroupIdentifier: GIDfullName: Name of userhomeDirectory: Home directoryshell: Default shellReturns a Promise<object> with the user entry.
Returns an object with the user entry.
Type: string
The username to look up.
Type: number
Default: process.getuid() (The current user)
The user identifier (UID) to look up.