Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from sindresorhus/much-fault-tolerant
Browse files Browse the repository at this point in the history
handle the $HOME (and similar) env var not being set
  • Loading branch information
sindresorhus committed Oct 16, 2014
2 parents 26b9cfd + 0ed7cf0 commit a34c42d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
'use strict';
module.exports = process.platform === 'win32' ? (process.env.USERPROFILE || process.env.HOMEDRIVE + process.env.HOMEPATH) : process.env.HOME;
var env = process.env;
var home = env.HOME;
var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME;

if (process.platform === 'win32') {
module.exports = env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home;
} else if (process.platform === 'darwin') {
module.exports = home || (user ? '/Users/' + user : null);
} else if (process.platform === 'linux') {
module.exports = home || (user ? (process.getuid() === 0 ? '/root' : '/home/' + user) : null);
} else {
module.exports = home;
}

0 comments on commit a34c42d

Please sign in to comment.