Platform agnostic user home directory path resolution for Node.js
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.
npm install --save userhomepath
const homedir = ;// find the home directory for user "luis", and log it to the console// successconsole;)// errorconsole;);
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.
For testing purposes, I also included a cli:
# find the home directory for user "luis"userhomepath luis