Node.js - 以平台不可知的方式查找主目录 [英] Node.js - Find home directory in platform agnostic way
本文介绍了Node.js - 以平台不可知的方式查找主目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
USERPROFILE $ c $>在Unix上,这不是一个问题。
解决方案 c>在win32环境变量?
$ b function getUserHome(){
return process。 env [(process.platform =='win32')? 'USERPROFILE':'HOME'];
$ / code> 编辑:如最近的回答, https://stackoverflow.com/a/32556337/103396 是正确的路要走( require('os')。homedir()
)。
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.
解决方案 Why not use the USERPROFILE
environment variable on win32?
function getUserHome() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
EDIT: as mentioned in a more recent answer, https://stackoverflow.com/a/32556337/103396 is the right way to go (require('os').homedir()
).
这篇关于Node.js - 以平台不可知的方式查找主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文