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. 回答1: As mentioned in a more recent answer, the preferred way is now simply: const homedir = require('os').homedir(); [Original Answer] : Why not use the USERPROFILE environment variable on win32? function getUserHome() { return process.env[(process.platform ==