Repository navigation
Home
stack-exchange-markdown-retriever gets the markdown source (body_markdown) of one question or answer on Stack Overflow or another Stack Exchange site from the Stack Exchange API, in code or on the command line. It returns the text as the API stores it. It does not render the markdown, unescape HTML entities, search, or fetch comments and answer lists.
npm install stack-exchange-markdown-retrieverimport {retrieveMarkdown} from 'stack-exchange-markdown-retriever';
const markdown = await retrieveMarkdown({site: 'scifi', entityId: 127968});
console.log(markdown);With the fixture described below standing in for the API, that prints (sample content, not the real post; the real one is at https://scifi.stackexchange.com/q/127968):
Sample question body, made up for this wiki (not the real post).
It keeps HTML entities: "quoted" & more.
an indented code line
The one request it made was:
GET https://api.stackexchange.com/2.2/questions/127968?order=asc&filter=!L_(I6pMIzdXP-hC1clc9EY&site=scifi
Every example ran against the published 2.0.0, installed from npm on 2026-09-29, and its output is pasted as printed. No example touched the real API. A local stand-in answered for api.stackexchange.com under its real name, through a proxy on 127.0.0.1 with a throwaway certificate. A guard in every Node process refused connections to any other host. The post texts the stand-in returned are sample content made up for the wiki. Each output that shows a post body says so and links the real post for comparison. Error bodies (ids, the throttling message) also came from the stand-in; the real API's wording can differ.
- Getting started: install with npm, pnpm, yarn, Bun or Deno, run it from npm without installing, CommonJS and ES modules, the TypeScript types.
-
API reference:
retrieveMarkdown, its options, the callback and Promise forms,StackExchangeError, every argument error. - How markdown is retrieved: the exact request, what comes back for each kind of answer, and the callback's timing.
- Commands: the command line tool, every flag, exit codes, stdout and stderr.
- Edge cases and errors: odd ids, odd responses, timeouts, aborts, proxies, and the message each one gives.
- Recipes: saving files, decoding entities, several posts, throttling, proxies, shell loops.
- Versions and upgrading: every release, and moving from 1.x to 2.0.0 with the golden capture of 1.1.7 replayed.
- FAQ: short answers, each linking the page with the detail.
- Development: build, test, the CI matrix and how a release is made.
The current version is 2.0.0, published on 2026-09-26. It needs Node 20 or later and has no runtime dependencies.
This wiki describes stack-exchange-markdown-retriever 2.0.0 and was last updated on 2026-09-29. The library is MIT licensed. Report problems in the issues. On npm: stack-exchange-markdown-retriever.
Using it
The releases
Contributing
Elsewhere