# hacker-news

> Scrapes Hacker News and exposes its API endpoints in a Node Module.

Latest version **0.0.1** (published 2013-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install hacker-news
pnpm add hacker-news
yarn add hacker-news
bun add hacker-news
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2013-05-07 |
| First published | 2013-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Edward Jiang |
| Maintainers | edjiang |

## Links

- npm: https://www.npmjs.com/package/hacker-news
- npm.io page: https://npm.io/package/hacker-news

## Dependencies (1)

- [scraper](https://npm.io/package/scraper.md) ~0.0.9

## Recent versions

- 0.0.1 (latest) — 2013-05-07

## README

#HackerNews.js

HackerNews.js scrapes Hacker News (or how its HTML was rendered on 5/6/13) for data and exposes it in a Node.js module. This tries to be API compatible with the iHackerNews API, except for two cases: we do not return cachedOnUTC, and the newComments and commentThreads endpoint. 

If there's enough demand, I'll add the cachedOnUTC thing, although I'll expose it in the 

This module is exposed in a REST API in another Node.js module which is yet to be written. Expect it soon. 

#Usage

	npm install hacker-news

Insert it into your app using:

	var hackernews = require('hacker-news')

Use it!

	var frontPage = hackernews.news(callback)	

##Warning

Hacker News will block your IP if you query their server too much. I'm not quite sure their rate limits (and will update this as I find out), but it may be ~[30 seconds](https://news.ycombinator.com/item?id=1702488). Most pages seem to be regenerated once in a while, anyways, so it shouldn't be a big deal. 

#API Endpoints

###news

Parameters: [nextid, callback]

Lists the front page news articles in the format:

	{
		nextId: 'id for next page of links'
		items: [{
			title: 'HackerNews.js',
			url: 'URL of article or item?id=selfpostid',
			postedBy: 'EdJiang',
			postedAgo: '1 day ago',
			points: 123,
			id: 1234567,
			commentCount: 32
			}...]
	}

###byUsername

Parameters: username, [nextid, callback]

Lists a user's submitted articles in the format:

	{
		nextId: 'id for next page of links'
		items: [{
			title: 'HackerNews.js',
			url: 'URL of article or item?id=selfpostid',
			postedBy: 'EdJiang',
			postedAgo: '1 day ago',
			points: 123,
			id: 1234567,
			commentCount: 32
			}...]
	}

###new

Parameters: [nextid, callback]

Lists newly submited articles articles in the format:

	{
		nextId: 'id for next page of links'
		items: [{
			title: 'HackerNews.js',
			url: 'URL of article or item?id=selfpostid',
			postedBy: 'EdJiang',
			postedAgo: '1 day ago',
			points: 123,
			id: 1234567,
			commentCount: 32
			}...]
	}

###newComments

Parameters: [nextid, callback]

Endpoint differs from the iHackerNews API by adding a object wrapper with nextId info

Lists newly submitted comments in the format:

	{
		nextId: 'id for next page of links'
		items: [{
			comment: 'This is awesome!',
			id: 1234567,
			parentID: 1234567,
			points: 0, //Note: HN doesn't show comment score, so this is always zero
			postedAgo: '2 hours ago',
			postedBy: 'pg', 
			postId: 12345678
			}...]
	}

###ask

Parameters: [nextid, callback]

Lists the Ask HN articles in the format:

	{
		nextId: 'id for next page of links'
		items: [{
			title: 'HackerNews.js'
			url: 'URL of article or item?id=selfpostid'
			postedBy: 'EdJiang'
			postedAgo: '1 day ago'
			points: 123
			id: 1234567
			commentCount: 32
			}...]
	}

###post

Parameters: postId, [callback]

Lists information about a post in the format:

	{
		title: 'HackerNews.js'
		url: 'URL of article or item?id=selfpostid'
		postedBy: 'EdJiang'
		postedAgo: '1 day ago'
		points: 123
		id: 1234567
		commentCount: 32
		text: 'This is only used for Ask HN or other self posts, otherwise will be an empty string!'
		comments: [{
			children: [...] 
			comment: 'This is awesome!',
			id: 1234567,
			parentID: 1234567,
			points: 0, //Note: HN doesn't show comment score, so this is always zero
			postedAgo: '2 hours ago',
			postedBy: 'pg', 
			postId: 12345678
		}...]
	}

###threads

Parameters: userId, [callback]

Lists a user's comments and replies in a threaded format:

	{
		nextId: 'id for next page of links'
		comments: [{
			children: [...] 
			comment: 'This is awesome!',
			id: 1234567,
			parentID: 1234567,
			points: 0, //Note: HN doesn't show comment score, so this is always zero
			postedAgo: '2 hours ago',
			postedBy: 'pg', 
			postId: 12345678
		}...]
	}

###Profile

Parameters: userId, [callback]

Lists a user's profile information:

	{
		about: 'I am Edward',
		createdAgo:'2 years ago',
		karma: '9001',
		username: 'EdJiang'
	}

---
_Source: https://npm.io/package/hacker-news · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
