md-live-viewer
A local, browser-based markdown viewer that updates as the file changes — no manual refresh. Run it in any folder:

npx md-live-viewer
It serves the current directory, opens a browser tab, and re-renders the open file whenever it is written by anything — another editor, a script, or an AI coding agent editing files in the background.
Installation
Run it directly with npx (no install):
npx md-live-viewer
Or install it globally:
npm install -g md-live-viewer
This puts these equivalent commands on your PATH (the examples below use md-view):
md-view
md-viewer
md-live-viewer
You can also install md-live-viewer with pnpm, yarn, or slnpm.
Why
Cursor's markdown preview does not always pick up changes written by an external process (e.g. an AI agent) without toggling between preview and source. This viewer watches the file itself, so any write shows up instantly.
Features
Live preview
- Live updates — the open file re-renders the moment anything writes it (an editor, a script, or an AI agent), pushed over Server-Sent Events.
- Recently changed — changed blocks get a green tint that fades over 5 minutes (tune with
--fade, disable with --no-fade). The clock pauses while the tab is hidden, and a block also clears after a few further updates so bursts don't pile up.
Markdown rendering
- GitHub Flavored Markdown — tables, task lists and strikethrough, via
micromark.
- Math, Mermaid and syntax highlighting —
$inline$ / $$block$$ via KaTeX (currency-safe, so HK$528K is not math), ```mermaid blocks to SVG, and fenced code via Prism (JS/TS/JSX/TSX, JSON, YAML, bash, Python, Markdown, SQL, Go, Rust, CSS) with light/dark themes.
- Relative images and links — resolved against the file's folder and served through the viewer.
Other file types (list them with --all)
- Images, audio, video and PDF open with a built-in viewer; clicking a downscaled image enlarges it.
- Text and code are shown verbatim (never parsed as Markdown) and highlighted by extension, with a Wrap toggle.
- Binaries (pptx/docx/xlsx/zip/…) show a card with the size and an Open action, instead of garbled text.
Finding and opening files
- Cursor-style switcher — Ctrl/Cmd + P: fuzzy, typo-tolerant search by name or path (
chng finds changelog.md).
- Folder + name — space-separated tokens each match a path segment, e.g.
docs config, to disambiguate same-named files in different folders.
- List / Tree toggle — a flat searchable list (default) or a collapsible tree that auto-opens at the current file; recent files come first and the choice is remembered.
- Keyboard and mouse stay in sync — hover,
↑/↓ and scrolling move the same highlighted row (the one Enter opens); each row has a copy-path button.
- Bookmarkable links — the open file lives in the URL hash (
#file=path/to/file.md); links to other Markdown files open in place.
- Drag & drop — drop a
.md file onto the window to open it (matched against the served folder by name, then size and mtime).
Header
- Copy the raw Markdown (📄) or the absolute path (📁).
- Save as PDF (🖨) — opens the print dialog (the PDF title is set to the file name).
- Theme (🖥️) — cycles system → light → dark; remembered, default follows the OS.
- Wrap — toggles text wrapping for code and plain-text views.
Design
- Scoped by design — serves exactly the folder you launch it with and cannot be re-pointed from the UI or a URL; access is confined to that tree, with a realpath check that rejects escaping symlinks.
- Zero runtime dependencies — the client bundle is prebuilt, so
npx just works.
Usage
md-view [options] [path]
Options and the optional [path] may appear in any order.
Options
| Option |
Description |
[path] |
Folder to serve, or a file to open (reusing a viewer that covers it, else serving its folder). Defaults to the current directory. |
-p, --port <n> |
Port (default 8137; use 0 for a random free port). |
--host <h> |
Host to bind (default localhost). |
-o, --open / -n, --no-open |
Open the browser automatically (default on). |
--all |
List all files, not only markdown. |
-d, --detach |
Serve in the background: print the banner and exit. |
--fade <dur> |
How long the "recently changed" tint lasts (default 5m; e.g. 60s, 5m; 0 or --no-fade disables). |
-l, --list |
List the running viewers (port and served folder). |
-w, --where <path> |
Show which running viewer serves path (exit code 1 if none). |
-v, --version |
Show the version. |
-h, --help |
Show help. |
Long options accept both --port 8200 and --port=8200.
Examples
# serve the repo you are in
cd ~/workspace/github.com/me/project && md-view
# serve your notes on a fixed port, without opening a browser
md-view --port 8200 --no-open ~/notes
# open one file: reuse a viewer that covers it, else serve its folder
md-view ~/notes/todo.md
With npm start, put script flags after --: npm start -- --port 8200 (without --, npm consumes --port as its own config).
Keyboard shortcuts
| Shortcut |
Action |
Ctrl/Cmd + P |
Open the fuzzy file switcher |
↑ / ↓ |
Move the selection |
Enter |
Open the selected file |
Esc |
Close the switcher |
Ctrl/Cmd + R |
Force re-read the current file |
The open file lives in the URL as #file=<path>, so a bookmark or a copied address reopens exactly that file — including in another browser.
The served folder is fixed when you launch the server. To view a different folder, stop it and start again with that folder as the argument, e.g. md-view ~/notes.
How it works
- The Node server (
src/server/) lists files, serves them, and watches the root with fs.watch({ recursive: true }) plus a periodic mtime scan as a safety net (which also catches atomic saves — temp file + rename — that fs.watch alone can miss). Change events are debounced and broadcast over SSE at /api/events.
- The browser client (
src/client/) fetches the file, renders it, and re-fetches only the currently open file when its path changes.
- Edits are view-only by design — the viewer never writes to your files, so it is safe to leave open next to an agent that is editing the same folder. Safe concurrent editing was considered and deliberately left out: a WYSIWYG preview re-serializes the whole file on save (the converter normalizes tables/spacing), so a 1-word edit becomes a whole-file diff and cannot be auto-merged with the agent's whole-file writes without conflicts. Editing in Cursor and keeping this as a live viewer avoids that entirely.
HTTP API
| Endpoint |
Description |
GET /api/files |
List markdown files (relative paths) and the served root. |
GET /api/search?q=&limit= |
Fuzzy-ranked file search (supports space-separated tokens). |
GET /api/file?path= |
Read one file (JSON, content field). |
GET /api/stat?path= |
File size and mtimeMs (used to disambiguate a dropped file). |
GET /api/config |
Client config (currently fadeMs, the "recently changed" fade window). |
GET /raw/<path> |
Serve a file raw (images, attachments). |
GET /api/events |
Server-Sent Events stream of file changes. |
All file endpoints reject paths that escape the served root, including through symlinks. There is no endpoint that changes the served folder or writes files.
License
This project is licensed with BSD-2-Clause
This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:
- The freedom to run the program as you wish, for any purpose
- The freedom to study how the program works, and change it so it does your computing as you wish
- The freedom to redistribute copies so you can help others
- The freedom to distribute copies of your modified versions to others
Markdown rendering logic is adapted from html-markdown-editor (same author, same license) for consistent output.