Skip to content
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
os: add .homedir()
In almost every cli-client that I write I need the current homedir
at a certain point.

While we have a function for getting the directory for storing
temporary files (callled `tmpdir`), a function for receiving the
location of the home directory is still missing.
  • Loading branch information
robertkowalski committed May 10, 2015
commit 8cf14eeb6aea68134f0f0b304a83a5d24ec43793
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);
}