process.env不包含HOME信息的任何原因?

时间:2021-12-24 11:22:50

I'm trying to use AWS, which checks for credentials information in the user directory. It does this by using process.env, and then extracting the user's home directory.

我正在尝试使用AWS,它会检查用户目录中的凭据信息。它通过使用process.env,然后解压缩用户的主目录来完成此操作。

However, after getting errors that the HOME path isn't set, I checked myself and noticed there was no HOME data output from the process.env call.

但是,在收到未设置HOME路径的错误后,我检查了自己并注意到process.env调用没有输出HOME数据。

I tried setting both system and environment variables for HOME = %UserProfile% with no luck. Any ideas why this isn't working?

我尝试为HOME =%UserProfile%设置系统和环境变量而没有运气。任何想法为什么这不起作用?

I'm using eclipse neon, and I'm developing in NodeJS on a company laptop. In case there are any typical security features that prevent a program from accessing a user's home directory.

我正在使用eclipse neon,我正在使用公司笔记本电脑上的NodeJS进行开发。如果存在任何阻止程序访问用户主目录的典型安全功能。

The output of

的输出

var env = process.env;
console.log(env);

is:

{ 
  APPDATA: 'C:\\Users\\myusername\\AppData\\Roaming',
  PATH: 'C:/Program Files/Java/jre1.8.0_102/bin/server; (ETC... huge list)
  SystemDrive: 'C:',
  SystemRoot: 'C:\\WINDOWS',
  TEMP: 'C:\\Users\\myusername\\AppData\\Local\\Temp',
  TMP: 'C:\\Users\\myusername\\AppData\\Local\\Temp' 
}

Thanks for the insight! Google only returned the man page for login, which is apparently where that field is set? Hope you guys have something.

感谢您的见解!谷歌只返回了登录的手册页,这显然是该字段的设置位置?希望你们有所作为。

Also, I don't know how the security is setup and wouldn't answer those questions anyway. This is mostly just a curiosity thing, possibly with a quick fix somewhere.

此外,我不知道如何设置安全性,无论如何也不会回答这些问题。这主要是一个好奇的事情,可能在某处快速修复。

1 个解决方案

#1


1  

I'm not sure about what security settings you have or what impact they may have on environment variables within Node, but you should be able to get the current user's home directory by using os.homedir() (built into Node):

我不确定您拥有哪些安全设置或它们可能对Node中的环境变量产生什么影响,但您应该能够通过使用os.homedir()(内置到Node)获取当前用户的主目录:

var os = require('os');
var home = os.homedir();

See https://nodejs.org/dist/latest-v4.x/docs/api/os.html#os_os_homedir

#1


1  

I'm not sure about what security settings you have or what impact they may have on environment variables within Node, but you should be able to get the current user's home directory by using os.homedir() (built into Node):

我不确定您拥有哪些安全设置或它们可能对Node中的环境变量产生什么影响,但您应该能够通过使用os.homedir()(内置到Node)获取当前用户的主目录:

var os = require('os');
var home = os.homedir();

See https://nodejs.org/dist/latest-v4.x/docs/api/os.html#os_os_homedir