index.js 470 B

1234567891011121314151617181920212223
  1. // references
  2. var path = require('path');
  3. var home = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
  4. // exports
  5. module.exports = homedir;
  6. /**
  7. * Resolves the path to the user's home directory.
  8. *
  9. * @param {String} [username]
  10. * Username of user whose path you seek.
  11. *
  12. * @return {String}
  13. * The full path to the user's home directory.
  14. */
  15. function homedir(username) {
  16. return username ? path.resolve(path.dirname(home), username) : home;
  17. }