Every time I try to get something back using nodejs I keep getting the following:
sytnax error 1 unexpected token < in json at position 0
I've tried installing packages for parsing HTML, but I cannot seem to get anything to work.
Could you tell me the proper way to log the information I am getting back to the console?
Thanks!
Edit:
I am able to get a return if I alter this code as follows:
function baseRequest(uri, cb) {
request(`${BASE_URL}${uri}`, function (error, response, body) {
debug(`Url: ${BASE_URL}${uri} statusCode: ${response && response.statusCode}`);
//cb(error, JSON.parse(body));
cb(error, body);
});
}
Then if I do a getPlayerInfo("characterName", console.log)
it'll output the entire HTML response to the console.
(using characterName as an example here, I tried it with my own character name)
Edit:::
I figured out what I was doing wrong. I was trying to pass a character name string into getPlayerInfo, but it wanted the actual ID. I was able to get that back using search("playerName", console.log), and then use that id string in getPlayerInfo('playerIdFull', console.log) and it outputted the correct information.
The output below is caused by passing in the wrong information. If you don't give it valid criteria, then it passes back an HTML element.
Thanks!
Output is as follows:
$ node index.js
null '<html>\n<head>\n
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n
<title>Error 404 Not Found</title>\n
</head>\n<body><h2>HTTP ERROR 404</h2>\n
<p>Problem accessing /api/gameinfo/players/characterName. Reason:\n
<pre>Not Found</pre></p>
<hr><i>
<small>Powered by Jetty://</small>
</i><hr/>\n\n</body>\n</html>\n'