Socket
Socket
Sign inDemoInstall

hack-news

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hack-news

A simple library of methods to help you interact with the Hacker News API. There's more on the way.


Version published
Weekly downloads
9
increased by350%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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');

//Returns an array of all the article ids for the top stories on hacker news

hn.allTopStories( (error, allTheStories) => {
  if (error) {
    console.log(error);
  }
  console.log(allTheStories);
});

//Using Promises
hn.allTopStories().then(stories => {console.log(stories);});

/*Returns an array of article ids in the amount of your choice.
So if you wanted the top ten stories on Hacker News it would look like this.*/

hn.numberOfTopStories(10, (error, numberOfStories) => {
  if (error) {
    console.log(error);
  }
  console.log(numberOfStories);
});

//Using Promises
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');

//Returns an array of all the article ids for the new stories on hacker news
hn.allNewStories( (error, allTheStories) => {
  if (error) {
    console.log(error);
  }
  console.log(allTheStories);
});

//Using Promises
hn.allNewStories().then(stories => {console.log(stories);});

/*Returns an array of article ids in the amount of your choice.
So if you wanted the top ten newest stories on Hacker News it would look like this.*/
hn.numberOfNewStories(10, (error, numOfStories) => {
  if (error) {
    console.log(error);
  }
  console.log(numOfStories);
});

//Using Promises
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');

//Returns an array of all the article ids for Ask, Show and Job stories on hacker news.
//Just place 'ask', 'show', or 'job' as the first parameter to retrieve the array you need.
hn.asjStories('ask', (error, asj) => {
  if (error) {
    console.log(error);
  }
  console.log(asj);
});

//Using Promises
hn.asjStories('show').then(asj => {console.log(asj);});

//If you wanted the Top Ten Ask, Show, Job you ca use the numbOfAskShowOrJobStories method like so.
hn.numbOfAsjStories('show', 10, (error, asj) => {
  if (error) {
    console.log(error);
  }
  console.log(asj);
});

//Using Promises
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.

var hn = require('hack-news');

//This will return a object filled with data corresponding to the ID that was used.
hn.storyWithId(002, (error, story) => {
  if (error) {
    console.log(error);
  }
  console.log(story);
});

//Used with another method
hn.numberOfNewStories(10, (error, numOfStories) => {
  var myArray = numOfStories;
  hn.storyWithId(myArray[0], (error, story) => {
    console.log(story);
  });
});

//Using Promises
hn.storyWithId(12303).then(story => {console.log(story);});

//Used with another method.
hn.numbOfAsjStories('job', 10).then(asj => {
  var myArray = asj;
  hn.storyWithId(myArray[6]).then(story => {console.log(story);});
});

This is it for now but stay tuned I will be adding a lot more.

Keywords

FAQs

Last updated on 26 Feb 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc