Home · Recipes · Node.js

A Hacker News thread to a Markdown file

Give it a Hacker News link and get thread.md with the title, author, score and the first comments, ready to paste into notes or a report.

tested Run for real on 19 November 2026 against https://api.foxapis.com (Python 3.14 with requests 2.34, Node 20). The code below is the file that ran; the output is what it printed.

What you need

The code

Save as hn_thread.mjs

// Hacker News thread to a Markdown file with FoxAPIs. Node 18+. Usage: node hn_thread.mjs https://news.ycombinator.com/item?id=8863  (3 credits reported on 19 Nov 2026: 1 for the post, 2 for its comments)
import { writeFileSync } from "node:fs";
const KEY = process.env.FOXAPIS_KEY;            // your FoxAPIs key; never paste it into the file
const link = process.argv[2];
if (!KEY || !link) { console.error("Set FOXAPIS_KEY and pass a Hacker News link."); process.exit(1); }
const call = async (path) => {
  const r = await fetch(`https://api.foxapis.com/v1/developer/hackernews/${path}`, { method: "POST", headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ url: link }) });
  if (!r.ok) throw new Error(`${path}: HTTP ${r.status}`);
  return r.json();
};
const [post, thread] = await Promise.all([call("post"), call("comments")]);
const lines = [`# ${post.title}`, "", `By ${post.author_handle || post.author_name}, ${post.published_at}. ${post.likes} points, ${post.comments_count} comments.`, `Source: ${post.url}`, ""];
if (post.text) lines.push(String(post.text).trim(), "");
for (const c of thread.comments.slice(0, 20)) lines.push(`- **${c.author || c.author_handle || "unknown"}**: ${String(c.text || "").replace(/\s+/g, " ").trim().slice(0, 300)}`);
writeFileSync("thread.md", lines.join("\n") + "\n");
console.log(`wrote thread.md: ${thread.comments.length} comments read, ${(post.credits_used || 0) + (thread.credits_used || 0)} credits`);

Run it

  1. Put your key in an environment variable: export FOXAPIS_KEY=your-key (PowerShell: $env:FOXAPIS_KEY = "your-key").
  2. Run node hn_thread.mjs "https://news.ycombinator.com/item?id=8863".

Input used in the test

node hn_thread.mjs "https://news.ycombinator.com/item?id=8863"

What it printed and wrote (19 November 2026)

wrote thread.md: 5 comments read, 3 credits

thread.md (first lines):
# My YC app: Dropbox - Throw away your USB drive

By dhouston, 2007-04-04T19:16:40+00:00. 104 points, 71 comments.
Source: http://www.getdropbox.com/u/2/screencast.html

What a run costs

3 credits for the run: 1 for the post, 2 for its comments. fact: credits the API reported

That is about $0.029 per thread on the Builder plan. Calculated by us: plan price divided by its credits.Formula Plans and credits: pricing.

Official docs, read 19 November 2026

Common questions

Why does the file hold only a few comments?

That is what the comments call returned on the day it was tested; the post line states the real comment total.

Does it need any package?

No. Node 18 and newer has fetch built in.

Start free: get a key   More code samples · All recipes

How we calculate

Data: the FoxAPIs catalog and plans, read 19 November 2026. Every other figure on this page is copied from the record, not calculated by us.

Run this free, then pay per call

Free to start: 100 credits, no card. Then from $10. Credits you buy never expire. Use them at your own pace. Get my free key

One call costs 1 credit. That is $7.96 per 1,000 calls on the Production plan and $9.80 on Builder (plan price divided by its monthly credits). The Free plan gives 100 credits a month with no card.

Run this freeBuy credits

Building an AI agent?

See the MCP server