yaakdoc

Node middleware

Serve the docs from Express, Connect, Fastify, Nitro or any server that takes Connect-style middleware.

yaakdocMiddleware serves the docs from a Node server: Express, Connect, Fastify (with @fastify/middie), Nitro and others.

npm i yaakdoc
server.ts
import express from "express";
import { yaakdocMiddleware } from "yaakdoc";

const app = express();

app.use(await yaakdocMiddleware({ path: "/docs", export: "./yaak.json" }));

app.listen(3000);
  • Development. Unless NODE_ENV is production (or you pass dev: false), it serves the live dev server. HMR uses its own WebSocket port; pass hmr: { server } to share your HTTP server instead.
  • Production. It serves a built site from config.outDir. Build it ahead of time with yaakdoc build --base /docs/, or pass build: true to build when the middleware is created.
  • Other requests. Anything outside path is passed on with next(). app.use("/docs", ...) works too.

The middleware has a close() method that stops the dev server.

Options

OptionDescription
pathWhere the docs are served. Default: /docs. It takes precedence over config.base.
configyaakdoc config, merged over yaakdoc.config.* if there is one. Paths are relative to cwd.
exportPath of the Yaak export. Shorthand for config.export. By default, yaakdoc.json, then yaak.json, is looked up in cwd.
cwdProject directory. Default: process.cwd().
configFileAn explicit config file, or false to not look for one.
publicDirA folder copied to the docs' root as is. Default: none.
devServe the live dev server. Default: true unless NODE_ENV is production.
buildBuild the site when the middleware is created (production only).
hmrVite HMR options, e.g. { server } to share your HTTP server.

For the lower-level building blocks, see the Node API.

On this page