Installation

$ npm install hack - news

Usage

Top Stories

The examples below show how to access the IDs of the top stories on Hacker News.

var hn = require ( ' hack-news ' ) ; hn . allTopStories ( ( error , allTheStories ) => { if ( error ) { console . log ( error ) ; } console . log ( allTheStories ) ; } ) ; hn . allTopStories ( ) . then ( stories => { console . log ( stories ) ; } ) ; hn . numberOfTopStories ( 10 , ( error , numberOfStories ) => { if ( error ) { console . log ( error ) ; } console . log ( numberOfStories ) ; } ) ; hn . numberOfTopStories ( 10 ) . then ( numberOfStories => { console . log ( numberOfStories ) ; } ) ;

New Stories

The examples below show how to access the IDs of the new stories on Hacker News.

var hn = require ( ' hack-news ' ) ; hn . allNewStories ( ( error , allTheStories ) => { if ( error ) { console . log ( error ) ; } console . log ( allTheStories ) ; } ) ; hn . allNewStories ( ) . then ( stories => { console . log ( stories ) ; } ) ; hn . numberOfNewStories ( 10 , ( error , numOfStories ) => { if ( error ) { console . log ( error ) ; } console . log ( numOfStories ) ; } ) ; hn . numberOfNewStories ( 10 ) . then ( numOfStories => { console . log ( numOfStories ) ; } ) ;

Ask, Show and Job Stories

The examples below show how to access the IDs of Ask, Show and Job stories on Hacker News.

var hn = require ( ' hack-news ' ) ; hn . asjStories ( ' ask ' , ( error , asj ) => { if ( error ) { console . log ( error ) ; } console . log ( asj ) ; } ) ; hn . asjStories ( ' show ' ) . then ( asj => { console . log ( asj ) ; } ) ; hn . numbOfAsjStories ( ' show ' , 10 , ( error , asj ) => { if ( error ) { console . log ( error ) ; } console . log ( asj ) ; } ) ; hn . numbOfAsjStories ( ' job ' , 10 ) . then ( asj => { console . log ( asj ) ; } ) ;

IDs

The examples below show how to select a single story with its ID you can also use the ID method with the other methods provided.

All items have some of the following properties, with required properties in bold.

Field Description id The item's unique id. deleted true if the item is deleted. type The type of item. One of "job", "story", "comment", "poll", or "pollopt". by The username of the item's author. time Creation date of the item, in Unix Time. text The comment, story or poll text. HTML. dead true if the item is dead. parent The item's parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll. kids The ids of the item's comments, in ranked display order. url The URL of the story. score The story's score, or the votes for a pollopt. title The title of the story, poll or job. parts A list of related pollopts, in display order. descendants In the case of stories or polls, the total comment count.

var hn = require ( ' hack-news ' ) ; hn . storyWithId ( 002 , ( error , story ) => { if ( error ) { console . log ( error ) ; } console . log ( story ) ; } ) ; hn . numberOfNewStories ( 10 , ( error , numOfStories ) => { var myArray = numOfStories ; hn . storyWithId ( myArray [ 0 ] , ( error , story ) => { console . log ( story ) ; } ) ; } ) ; hn . storyWithId ( 12303 ) . then ( story => { console . log ( story ) ; } ) ; hn . numbOfAsjStories ( ' job ' , 10 ) . then ( asj => { var myArray = asj ; hn . storyWithId ( myArray [ 6 ] ) . then ( story => { console . log ( story ) ; } ) ; } ) ;

Users

The examples below show how to select a single user with his or hers ID you can also use the user method with the other methods provided.

All users have some of the following properties, with required properties in bold.

Field Description id The user's unique username. Case-sensitive. Required. delay Delay in minutes between a comment's creation and its visibility to other users. created Creation date of the user, in Unix Time. karma The user's karma. about The user's optional self-description. HTML. submitted List of the user's stories, polls and comments.

var hn = require ( ' hack-news ' ) ; hn . userWithId ( ' thefox ' , ( error , user ) => { if ( error ) { console . log ( error ) ; } console . log ( user ) ; } ) ; hn . storyWithId ( 7567 , ( error , story ) => { var myUser = story . by ; hn . userWithId ( myUser , ( error , user ) => { console . log ( user ) ; } ) ; } ) ; hn . userWithId ( ' thefox ' ) . then ( user => { console . log ( user ) ; } ) ; hn . storyWithId ( 7875 ) . then ( story => { var myUser = story . by ; hn . storyWithId ( myUser ) . then ( user => { console . log ( user ) ; } ) ; } ) ;

Changed items and profiles

The examples below show how to access the changed or updated items and profiles on Hacker News.

var hn = require ( ' hack-news ' ) ; hn . changedItemsAndProfiles ( ( error , itemsProfiles ) => { if ( error ) { console . log ( error ) ; } console . log ( itemsProfiles ) ; } ) ; hn . changedItemsAndProfiles ( ) . then ( itemsProfiles => { console . log ( itemsProfiles ) ; } ) ;

Max Item

The examples below show how to grab the max item on hacker news.