CLI reference
The package installs a single binary: headless-prerender.
bash
headless-prerender <command> [options]| Command | Purpose |
|---|---|
serve | Start the prerender HTTP server |
render <url> | Render one URL and print or save the HTML |
help | Print usage (also --help) |
serve
Starts a long-running HTTP server.
bash
headless-prerender serve --port 3000 --cache-ttl 60000Endpoints
| Route | Description |
|---|---|
GET /render?url=<page> | Returns the fully-rendered HTML of <page> |
GET /health | Returns {"ok":true} |
Options
| Flag | Default | Description |
|---|---|---|
--port <n> | 3000 | TCP port to listen on |
--host <host> | 0.0.0.0 | Interface to bind |
--cache-ttl <ms> | 0 | In-memory cache TTL; 0 disables caching |
--token <string> | none | Require this token via ?token= or x-prerender-token |
Plus all common render options.
render <url>
Renders one page and exits.
bash
headless-prerender render https://example.com --extra-wait 500 --out page.html| Flag | Default | Description |
|---|---|---|
--out <file> | stdout | Write the HTML to a file instead of standard output |
Plus all common render options.
Progress and result details are written to stderr, so --out is optional and piping the HTML on stdout stays clean:
bash
headless-prerender render https://example.com > page.htmlCommon render options
These apply to both serve and render.
| Flag | Default | Description |
|---|---|---|
--timeout <ms> | 20000 | Navigation timeout |
--wait-until <event> | networkidle2 | load, domcontentloaded, networkidle0, or networkidle2 |
--extra-wait <ms> | 0 | Extra settle time after the page is considered loaded |
--user-agent <string> | Mozilla/5.0 (compatible; headless-prerender) | User-Agent sent to the target page |
--allow-origin <origin> | none | Only render URLs on this origin; repeatable |
--executable-path <path> | bundled Chromium | Path to a Chromium binary |
Restricting origins
Pass --allow-origin more than once to allow several origins:
bash
headless-prerender serve \
--allow-origin https://www.example.com \
--allow-origin https://blog.example.comAny request for a URL outside the list returns an error.
Exit codes
| Code | Meaning |
|---|---|
0 | Success |
1 | Invalid arguments, or a render/serve error |