The command-line interface of doc-kit, the
Node.js project's toolkit for API documentation. Its doc-kit command reads
your docs and runs generators that write a website, the search index, JSON,
llms.txt, man pages, or whatever a custom generator produces. Use it to
build your docs locally and in CI.
npm install --save-dev @doc-kit/cli @doc-kit/generator-react
The CLI comes with @doc-kit/core
and its JSON generators. The other generators live in their own packages,
which you install next to the CLI. The command above adds the website
generators; leave @doc-kit/generator-react out if you only need JSON.
| Package | Generators |
|---|---|
@doc-kit/core | json, json-all, json-simple |
@doc-kit/generator-react | html, section-pages, orama-db, sitemap, llms-txt, llms-txt-full |
@node-core/doc-kit | man-page, api-links, addon-verify |
npx doc-kit generate -t html -t orama-db -i "docs/**/*.md" -o out
This builds the website and its search index from every Markdown file under
docs/, and writes them to out/. A run needs at least a target and an
input, from flags or a configuration file:
-t, --target <generator...>string[]The generators to run. Repeat the flag, or list several names after it.-i, --input <patterns...>string[]Glob patterns matching your source files. Quote them, so your shell passes them on unexpanded.-o, --output <directory>stringThe directory the generators write to.
Run npx doc-kit generate --help, or see the
CLI reference, for every option.
npx doc-kit preview
This serves ./out on http://localhost:3000 as it is, without reading your
configuration file. Pass it any generate option and it builds first, then
serves the directory that build wrote to. If your build writes somewhere other
than ./out, pass your configuration file (or -o) so it builds and serves
that directory:
npx doc-kit preview --config-file doc-kit.config.mjs
It builds once and doesn't watch for changes, so run it again after editing. Two options of its own control the server:
--port <number>numberThe port to serve on. Default:3000.--host <host>stringThe host to listen on. Default:'localhost'.
The preview server is meant for checking your docs locally. To put them online, upload the output directory to a static host; see Publishing your docs.
Instead of passing flags on every run, put your options in a configuration file:
export default { target: ['html', 'orama-db'], global: { input: ['docs/**/*.md'], output: 'out', }, };
With this file in place, npx doc-kit generate needs no flags. doc-kit looks
for it in the working directory, as doc-kit.config.mjs (or .js, .cjs),
a .doc-kitrc file in JSON, YAML or JavaScript, or a doc-kit key in
package.json. Pass --config-file <path> to load another file. A flag wins
over the file when both set the same option.
The configuration reference covers every option, including each generator's own.
--target, and target in the configuration file, also take a generator you
wrote or installed: a relative path such as ./my-generator.mjs (resolved
from the working directory), an absolute path, or a package name. The
module's default export must have a name and a generate function.
npx doc-kit generate -t ./my-generator.mjs -i "docs/**/*.md" -o out
Creating generators shows how to write one.
--log-level <level> works with every command. It takes debug, info,
warn, error or fatal, and defaults to info:
npx doc-kit --log-level debug generate
- Getting started: from an empty folder to a site with search.
- CLI: every command and option.
- Configuration: the configuration file and how it merges with flags.
- Generators: what each generator writes.
This package lives in packages/cli of the
nodejs/doc-kit monorepo, which uses
Node.js 24 and pnpm:
git clone https://github.com/nodejs/doc-kit.git cd doc-kit pnpm install # Run the CLI from source node --run run -- generate --help # Run it again whenever a file it imports changes node --run watch -- generate -t json -i "path/to/docs/**/*.md" -o out
Each command is a module in bin/commands/;
Adding a command walks
through writing one. Run the tests with node --run test, and add a changeset
with node --run changeset for any change users will notice. The
contributing guide
has the rest.