3

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

asked Sep 16, 2014 at 19:54
0

3 Answers 3

6

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', ...}
 }
}
answered Sep 16, 2014 at 19:57
Sign up to request clarification or add additional context in comments.

1 Comment

Well-designed JSON documents have keys that play nicely with JavaScript to avoid this sort of mess.
3

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)

answered Sep 16, 2014 at 19:58

Comments

1

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"
}
answered Sep 16, 2014 at 20:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.