Install for Node.js
Run Document Authoring headlessly in Node.js to import, edit, and convert documents on the server — converting DOCX files to PDF, filling templates programmatically, or processing documents in a queue. The Node.js entry point exposes the same document API as the browser library, without the visual editor.
Requirements
- Node.js 22 or 24.
- The
@nutrient-sdk/document-authoringpackage.
Edge runtimes (such as Cloudflare Workers or Vercel Edge Functions) and alternative Node-compatible runtimes aren’t supported. Use a standard Node.js server runtime.
Document Authoring for Node.js is a licensed feature. Contact Sales to enable it for production use.
Adding to your project
Install the package:
npm install @nutrient-sdk/document-authoringThe Node.js entry point is the /node subpath of the package and supports both ESM import and CommonJS require. It uses the same document API as the browser library. See working with documents for import and export formats and programmatic editing for changing document content.
No asset setup is required to get started. The engine and support files load from the installed package, and built-in fonts load from Nutrient’s content delivery network (CDN) when they’re needed. For an offline or self-hosted deployment, see Node.js in production.
Importing, editing, and converting a document
Save the following code as process-document.mjs, and place a DOCX file next to it as input.docx. It processes a document end to end:
import { createDocAuthSystem } from '@nutrient-sdk/document-authoring/node';import { readFile, writeFile } from 'node:fs/promises';
const system = await createDocAuthSystem();
try { // `Buffer` extends `Uint8Array`, so it can be passed directly. const document = await system.import(await readFile('input.docx'), { format: 'docx', });
await document.transaction(async ({ draft }) => { const paragraph = draft.body().content().addParagraph(); paragraph.asTextView().setText('Processed on the server.');
return true; });
const pdf = await document.export({ format: 'pdf' }); await writeFile('output.pdf', new Uint8Array(pdf));} finally { system.destroy();}A few details worth noting:
- Binary inputs accept
Bufferand otherUint8Arrayvalues directly, as well asBlob,ArrayBuffer, andResponsevalues. system.import()can detect a format from the content or afileNamehint. Passingformatskips detection when you already know the input format.- Call
system.destroy()when the process shuts down or when the system is no longer needed.
Run it
node process-document.mjsoutput.pdf appears next to the script: the imported DOCX with the added paragraph, converted to PDF on the server. From here, the same document API covers every import and export format and the full programmatic editing surface.
TypeScript configuration
The Node.js entry uses the shared DocAuthSystem API. Its createEditor() method is browser-only and throws if called in Node.js.
Because the shared type definitions also describe the browser API, a Node-only TypeScript project might report that types such as HTMLElement or Document can’t be found. These are TypeScript errors, not missing Node.js runtime dependencies.
Configure the fix in your project’s tsconfig.json file, usually found at the project root. Add "DOM" to the existing compilerOptions.lib array so TypeScript knows about the browser types referenced by the shared API declarations:
{ "compilerOptions": { "lib": ["ES2022", "DOM"] }}The lib setting only makes these type declarations available to the TypeScript compiler. It doesn’t add browser code or browser APIs to the Node.js runtime.
Alternatively, you can tell TypeScript not to check declaration files from dependencies:
{ "compilerOptions": { "skipLibCheck": true }}This still type-checks your application code, but it skips errors inside dependency declaration files.
Next steps
Node.js in production
The scaling model, worker threads, and asset configuration for servers.
Programmatic editing
Transactions and the document editing API — identical in the browser and Node.js.
Working with documents
Import and export formats.