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

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', ...}
  }
}
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)

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"
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.