diff --git a/doc/api/os.markdown b/doc/api/os.markdown index 9202c74914c374..e3e40ee2df85a8 100644 --- a/doc/api/os.markdown +++ b/doc/api/os.markdown @@ -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 diff --git a/lib/os.js b/lib/os.js index cd4eb1c12f49bc..50a17b3e33f411 100644 --- a/lib/os.js +++ b/lib/os.js @@ -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; +}; diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index b5f39973a6f71f..200763c5ed86d3 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -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); +}