userhomepath
v1.0.6
Published
Platform agnostic user home directory path resolution for Node.js.
Downloads
10
Maintainers
Readme
userhomepath
Platform agnostic user home directory path resolution for Node.js
While os.userInfo().homedir
or os.homedir
can give you the home directory for the current user, this module will give you the home directory for any user, including system users.
Install
npm install --save userhomepath
Usage
const { homedir } = require('userhomepath');
// find the home directory for user "luis", and log it to the console
homedir('luis').then(userPath) {
// success
console.log(userPath);
}).catch(error) {
// error
console.error("error: "+error.message);
});
The homedir function attempts to resolve the home directory of the given (case-sensitive, except on Windows) username. A homedirSync function is also provided, which blocks until the function finishes. If the user does not exist, or if the operation couldn't be completed, an exception is thrown. If the user exists, but does not have a home directory, null is returned. Upon success, a string containing the fully qualified path to the user's home directory is returned.
CLI
For testing purposes, I also included a cli:
# find the home directory for user "luis"
userhomepath luis