Skip to content

Commit 5288ed7

Browse files
committed
windows: use USERPROFILE to get the user's home dir
Fixes nodejs#3461 Close nodejs#3462 Close nodejs#4093
1 parent 76ddf06 commit 5288ed7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/module.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,24 @@ Module.runMain = function() {
497497
Module._load(process.argv[1], null, true);
498498
};
499499

500-
Module._initPaths = function() {
500+
Module._initPaths = function () {
501+
var isWindows = process.platform === 'win32';
502+
503+
if (isWindows) {
504+
var homeDir = process.env.USERPROFILE;
505+
} else {
506+
var homeDir = process.env.HOME;
507+
}
508+
501509
var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
502510

503-
if (process.env['HOME']) {
504-
paths.unshift(path.resolve(process.env['HOME'], '.node_libraries'));
505-
paths.unshift(path.resolve(process.env['HOME'], '.node_modules'));
511+
if (homeDir) {
512+
paths.unshift(path.resolve(homeDir, '.node_libraries'));
513+
paths.unshift(path.resolve(homeDir, '.node_modules'));
506514
}
507515

508516
if (process.env['NODE_PATH']) {
509-
var splitter = process.platform === 'win32' ? ';' : ':';
517+
var splitter = isWindows ? ';' : ':';
510518
paths = process.env['NODE_PATH'].split(splitter).concat(paths);
511519
}
512520

0 commit comments

Comments
 (0)