hackernews-api-ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Hacker News Typescript API

A clean Typescript client for the Hacker News API.

Dependencies

Examples

Get 5 newest top stories

import HackerNews from 'hackernews-api-ts';
 
HackerNews.getStories(HackerNews.TYPE_TOP, 0, 5)
    .then(stories => {
        let i=1;
        stories.forEach(story => console.log(`${i++}${story.title} [${story.score}] (${story.url})}`))
    });

List item/user updates

import HackerNews from 'hackernews-api-ts';
 
HackerNews.getUpdates().then(updates => console.log(updates));

Get user info for user of newest post

import HackerNews from 'hackernews-api-ts';
 
HackerNews.getMaxItem()
    .then(item => HackerNews.getUser(item.by))
    .then(user => { if(user) console.log(`Latest item was posted by ${user.id} [${user.karma}]`) });

Get top posts for each category

import HackerNews from 'hackernews-api-ts';
 
HackerNews.TYPES.forEach(type => {
    HackerNews.getStories(type,0,1)
    .then(stories => console.log(`Top ${type} story: ${stories[0].title}`));
});

Package Sidebar

Install

npm i hackernews-api-ts

Weekly Downloads

0

Version

0.2.0

License

ISC

Unpacked Size

36.6 kB

Total Files

10

Last publish

Collaborators

  • karpour