0

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?

rene
  • 41,474
  • 78
  • 114
  • 152
Aby James
  • 23
  • 5

2 Answers2

3

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
Six
  • 5,122
  • 3
  • 29
  • 38
1

https://hacker-news.firebaseio.com/v0/user/<user>.json is the only API endpoint to return karma.

So no, there is no better (available) way.

lexicore
  • 42,748
  • 17
  • 132
  • 221