Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: add .homedir() #1670

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/os.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Use `require('os')` to access this module.

Returns the operating system's default directory for temporary files.

## os.homedir()

Returns the home directory path of the current user.

## os.endianness()

Returns the endianness of the CPU. Possible values are `'BE'` for big endian
Expand Down
5 changes: 5 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ if (binding.isBigEndian)
exports.endianness = function() { return 'BE'; };
else
exports.endianness = function() { return 'LE'; };

exports.homedir = function() {
const location = isWindows ? process.env.USERPROFILE : process.env.HOME;
return location;
};
6 changes: 6 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ switch (platform) {

var EOL = os.EOL;
assert.ok(EOL.length > 0);

if (process.platform === 'win32') {
assert.equal(os.homedir(), process.env.USERPROFILE);
} else {
assert.equal(os.homedir(), process.env.HOME);
}