Maybe some one can help me to step in the right direction ? Big Thanks for any Hints.
var credentials = { steam: {}, rpc: {} };
var rawCredentials = JSON.parse(fs.readFileSync("auth.json", { "encoding": "utf8" }));
credentials.steam.accountName = rawCredentials.steam.accountName;
credentials.steam.password = rawCredentials.steam.password;
credentials.steam.shaSentryfile = new Buffer(rawCredentials.steam.shaSentryfile, "hex");
credentials.rpc.username = rawCredentials.rpc.username;
credentials.rpc.password = rawCredentials.rpc.password;
auth.json file
{
"credentials.steam.accountName": "XXX",
"credentials.steam.password": "XXX",
}
Cannot read property 'accountName' of undefined
3 Answers 3
The key of your property is actually "credentials.steam.accountName". You can't use dot-notation to traverse to the objects "credentials" or "steam", as these aren't objects.
To access the values, use: rawCredentials['credentials.steam.accountName'].
Edit: If you want to use rawCredentials.credentials.steam.accountName your JSON would have to look like this:
rawCredentials = {
credentials: {
steam: {accountName: 'foo', ...}
}
}
1 Comment
Those are complete property names which contain dots, not actual nested objects, in your JSON file.
Also, you've forgotten the .credentials part. Instead, use bracket notation:
credentials.steam.accountName = rawCredentials["credentials.steam.accountName"];
credentials.steam.password = rawCredentials["credentials.steam.password"];
(or refactor your JSON)
Comments
Don't know if that could be the problem, but you have a bad syntaxis in your auth.json:
{
"credentials.steam.accountName": "XXX",
"credentials.steam.password": "XXX"
}