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.
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
- How to verify laravel passport api token in node /
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- What file sytems support Java UserDefinedFileAttri
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
os.homedir()
was added by this PR and is part of the public 4.0.0 release of nodejs.Example usage:
Well, it would be more accurate to rely on the feature and not a variable value. Especially as there are 2 possible variables for Windows.
EDIT: as mentioned in a more recent answer, https://stackoverflow.com/a/32556337/103396 is the right way to go (
require('os').homedir()
).As mentioned in a more recent answer, the preferred way is now simply:
[Original Answer]: Why not use the
USERPROFILE
environment variable on win32?Use
osenv.home()
. It's maintained by isaacs and I believe is used by npm itself.https://github.com/isaacs/osenv