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
Install size
6.43 kB
Created
Weekly downloads
 

Readme

Source

Installation

$ npm install hack-news

Usage

####Top Stories The examples below shows 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( (allTheStories, error) => {
  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, (numberOfStories, error) => {
  if (error) {
    console.log(error);
  }
  console.log(numberOfStories);
});

//Using Promises
hn.numberOfTopStories(10).then(numberOfStories => {console.log(numberOfStories);});

####New Stories The examples below shows 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( (allTheStories, error) => {
  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, (numOfStories, error) => {
  if (error) {
    console.log(error);
  }
  console.log(numOfStories);
});

//Using Promises
hn.numberOfNewStories(10).then(numberOfStories => {console.log(numberOfStories);});

####Ask, Show and Job Stories The examples below shows 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.askShowOrJobStories('ask', (asj, error) => {
  if (error) {
    console.log(error);
  }
  console.log(asj);
});

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

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

Keywords

FAQs

Last updated on 22 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