• 1
name Punditsdkoslkdosdkoskdo

Node.js - Find home directory in platform agnostic way

Process.platform returns "win32" for Windows. On Windows a user's home directory might be C:Users[USERNAME] or C:Documents and Settings[USERNAME] depending on which version of Windows is being used. On Unix this isn't an issue.

const homedir = require('os').homedir();

[Original Answer]: Why not use the USERPROFILE environment variable on win32?

function getUserHome() {
  return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
  • 0
Reply Report