I am trying to find karma (points) of each Hacker News user using the official API. I am new to programming.
The following is the code snippet I have written to get karma of one specific user. There are close to 300k user accounts on HN.
var request = require("request");
request(
"https://hacker-news.firebaseio.com/v0/user/pg.json",
function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(JSON.parse(body).karma);
}
});
I ran this code, but it is not fast. Is there a better way to do this?
There is a faster way. Use the following API endpoint:
https://hacker-news.firebaseio.com/v0/user/${username}/karma.json
For comparison, here are the elapsed times for the respective calls:
/v0/user/pg.json: 9.560ms
/v0/user/pg/karma.json: 3.061ms