anydoc in Node.js - @firecrawl/anydoc
API ReferenceNode.js
The Node.js binding is @firecrawl/anydoc — native code running on the libuv thread pool, so converting documents in a high-concurrency service won't block your event loop.
Install
npm install @firecrawl/anydocTypeScript types are bundled; nothing extra to configure.
The three core APIs
import { toMarkdown, toMarkdownBytes, toDocument } from '@firecrawl/anydoc'
// 1. From a path (most common)
const markdown = await toMarkdown('report.docx')
console.log(markdown)
// 2. From bytes (when the file is already in memory)
const buf = await fs.readFile('slides.pptx')
const md = await toMarkdownBytes(buf)
// 3. Stop at the document model (keep embedded assets)
const doc = await toDocument(buf)
// doc exposes raw bytes and media types of images/objectsError handling
try {
await toMarkdown('scanned.pdf')
}
catch (e) {
console.error(e.code) // 'unsupported' | 'malformed' | 'encrypted' | 'resourceLimit' | 'missingPart' | 'io'
}All errors expose a code — the mapping is in Error Handling & Limits.
Common scenarios
Batch-convert a directory
import { readdir } from 'node:fs/promises'
import { toMarkdown } from '@firecrawl/anydoc'
const dir = './docs'
for (const name of await readdir(dir)) {
if (/\.(docx|pptx|xlsx|pdf)$/i.test(name)) {
const md = await toMarkdown(`${dir}/${name}`)
await writeFile(`${dir}/${name}.md`, md)
}
}Convert on web upload
// Given a File object from a form, convert the bytes directly
const bytes = await file.arrayBuffer()
const markdown = await toMarkdownBytes(new Uint8Array(bytes))
// Send the result to the client, or feed it to your LLMHand documents to an AI agent
Wrap toMarkdown as a tool function and expose it to LLM tool calling — your agent can then "read" any uploaded office file:
const convertDoc = async (path) => await toMarkdown(path)
// register as a tool → the agent calls it directlyTips
- Conversion is synchronous under the hood (on the thread pool); there's no separate async API to await beyond the call itself
- Write to disk with
fs.writeFile('out.md', markdown)— the CLI's-oflag does exactly this - Check the changelog on upgrades; error-code naming may adjust across major versions