Reputation: 105
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.
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.
I tried setting both system and environment variables for HOME = %UserProfile% with no luck. Any ideas why this isn't working?
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.
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.
Upvotes: 0
Views: 765
Reputation: 1787
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):
var os = require('os');
var home = os.homedir();
See https://nodejs.org/dist/latest-v4.x/docs/api/os.html#os_os_homedir
Upvotes: 1