Skip to content

karpour/hackernews-api-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}`));
});

About

Typescript API client for Hacker News

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published