Skip to content
Ferromark

Ferromark / Node.js

Start with Node.js

Render Markdown in a Node.js application with a synchronous, native API. Use Node.js 22.12 or newer. TypeScript declarations are included.

Install

npm install ferromark

npm's latest channel carries v3.7.0. V3 is a breaking change from v2. Read the v2-to-v3 migration guide before upgrading. For a v1 upgrade, follow the v1-to-v2 migration guide first, then the v2-to-v3 guide.

Save this as example.mjs and run node example.mjs:

import { toHtml } from "ferromark";

const html = toHtml("# Hello\n\n**World**");
console.log(html);

The result is:

<h1 id="hello">Hello</h1>
<p><strong>World</strong></p>

For CommonJS, use const { toHtml } = require('ferromark') on a supported Node.js version. You do not need to install a compiler: npm selects a prebuilt native package for your platform.

Choose your API

Your taskAPIResult
Render one documenttoHtml(markdown, options?)HTML string
Send HTML as bytestoHtmlBuffer(markdown, options?)UTF-8 Buffer
Get HTML and metadatatransform(markdown, options?)HTML, headings, optional front matter
Render many documentsnew Renderer(options?)Reuses native parser scratch
Highlight codetoHtmlWithHighlighter()HTML with custom code-block output
Highlight and collect metadatatransformWithHighlighter()HTML, headings, optional front matter

Every call that takes Markdown accepts markdown: string | Uint8Array: a string, or its UTF-8 bytes in a Uint8Array such as a Buffer from fs.readFile(path). Render a file from bytes shows the example.

These calls are synchronous. For sustained CPU work in a server, use a worker thread so rendering does not occupy the request-handling event loop.

Compile JSX for a build pipeline

For trusted authored content, compileJsx produces a JSX body or a complete MDX module. CodeCompiler adds optional native plugins, prepared documents for metadata and repeated rendering, and standalone code-block rendering. Your application's JSX transform compiles the output. See the Node JSX guide for API selection and complete examples, including how to try additions on main before their release. MDX boundaries explains the difference between HTML syntax capture and JSX compilation.

Analyze a prepared document

The document analysis guide shows how to use prepareDocument for reusable analysis without loading highlighting assets. A prepared handle can collect link and image references, extract plain text and search sections, and project static Markdown from MDX. These methods preserve the handle for later rendering. The guides include offline examples and explain source ranges and omitted dynamic content. Build the package from source until these APIs are released.

Next: configure your content

Set rendering options, then build a content pipeline. For installation failures or server deployment, see runtime and deployment.