npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

doc-docx-converter

v1.0.0

Published

WASM-powered DOC/DOCX converter for Node.js.

Readme

doc-docx-converter

WASM-powered DOC/DOCX conversion for Node.js.

doc-docx-converter converts older Microsoft Word documents (.doc) and modern Word documents (.docx) into common output formats such as PDF, DOCX, ODT, RTF, TXT, HTML, PNG, JPG, and SVG.

It uses LibreOffice compiled to WebAssembly, so your application does not need a native LibreOffice installation.

Features

  • Converts .doc and .docx inputs.
  • Outputs pdf, docx, doc, odt, rtf, txt, html, png, jpg, and svg.
  • Uses a reusable worker-backed LibreOffice WASM converter for server workloads.
  • Provides a one-shot helper for simple scripts.
  • Includes TypeScript types.
  • Normalizes and validates formats before conversion.
  • Supports optional PDF/image settings.

Requirements

  • Node.js 18 or newer.
  • Enough disk space for the LibreOffice WASM assets.
  • Enough memory for LibreOffice WASM initialization and document processing.

No native soffice or LibreOffice installation is required.

Installation

npm install doc-docx-converter

Quick Start

import { convertDocument } from "doc-docx-converter";
import fs from "node:fs";

const input = fs.readFileSync("contract.doc");

const result = await convertDocument(input, {
  inputFormat: "doc",
  outputFormat: "docx",
  filename: "contract.doc"
});

fs.writeFileSync(result.filename, result.data);

Reuse a Converter

For servers and batch jobs, reuse one converter. The first conversion initializes LibreOffice WASM, so reuse is much faster than creating a converter for every file.

import { createDocDocxConverter } from "doc-docx-converter";
import fs from "node:fs";

const converter = await createDocDocxConverter();

try {
  const input = fs.readFileSync("contract.doc");

  const result = await converter.convert(input, {
    inputFormat: "doc",
    outputFormat: "pdf",
    filename: "contract.doc"
  });

  fs.writeFileSync(result.filename, result.data);
} finally {
  await converter.destroy();
}

Express Example

import express from "express";
import multer from "multer";
import { createDocDocxConverter } from "doc-docx-converter";

const app = express();
const upload = multer({
  storage: multer.memoryStorage(),
  limits: {
    fileSize: 20 * 1024 * 1024
  }
});

const converter = await createDocDocxConverter({
  maxInputBytes: 20 * 1024 * 1024
});

app.post("/convert", upload.single("file"), async (req, res, next) => {
  try {
    if (!req.file) {
      res.status(400).json({ message: "Upload a .doc or .docx file." });
      return;
    }

    const result = await converter.convert(req.file.buffer, {
      inputFormat: req.file.originalname.endsWith(".doc") ? "doc" : "docx",
      outputFormat: "pdf",
      filename: req.file.originalname
    });

    res.setHeader("Content-Type", result.mimeType);
    res.setHeader("Content-Disposition", `attachment; filename="${result.filename}"`);
    res.send(Buffer.from(result.data));
  } catch (error) {
    next(error);
  }
});

app.listen(3000);

API

convertDocument(input, options, converterOptions?)

Creates a converter, converts one document, destroys the converter, and returns the result.

Best for scripts, CLIs, and low-volume jobs.

const result = await convertDocument(inputBuffer, {
  inputFormat: "doc",
  outputFormat: "pdf",
  filename: "document.doc"
});

createDocDocxConverter(options?)

Creates a reusable converter.

const converter = await createDocDocxConverter();
const result = await converter.convert(inputBuffer, options);
await converter.destroy();

new DocDocxConverter(options?)

Constructs a converter immediately and starts initialization in the background.

const converter = new DocDocxConverter();
await converter.waitUntilReady();

converter.convert(input, options)

Converts a .doc or .docx document.

const result = await converter.convert(input, {
  inputFormat: "docx",
  outputFormat: "html",
  filename: "proposal.docx"
});

converter.destroy()

Stops the converter worker and releases LibreOffice WASM resources.

Always call this when your script, job, or server is shutting down.

Types

type DocDocxInputFormat = "doc" | "docx";

type DocDocxOutputFormat =
  | "pdf"
  | "docx"
  | "doc"
  | "odt"
  | "rtf"
  | "txt"
  | "html"
  | "png"
  | "jpg"
  | "svg";

interface DocDocxConversionOptions {
  outputFormat: DocDocxOutputFormat;
  inputFormat?: DocDocxInputFormat;
  filename?: string;
  password?: string;
  pdf?: {
    pdfaLevel?: "PDF/A-1b" | "PDF/A-2b" | "PDF/A-3b";
    quality?: number;
  };
  image?: {
    width?: number;
    height?: number;
    dpi?: number;
    pageIndex?: number;
    pages?: number[];
  };
  maxInputBytes?: number;
}

interface DocDocxConversionResult {
  data: Uint8Array;
  mimeType: string;
  filename: string;
  duration: number;
  inputFormat: DocDocxInputFormat;
  outputFormat: DocDocxOutputFormat;
}

PDF Options

const result = await convertDocument(input, {
  inputFormat: "docx",
  outputFormat: "pdf",
  filename: "report.docx",
  pdf: {
    pdfaLevel: "PDF/A-2b",
    quality: 90
  }
});

Image Output

Image outputs render document pages through the LibreOffice WASM engine.

const result = await convertDocument(input, {
  inputFormat: "docx",
  outputFormat: "png",
  filename: "report.docx",
  image: {
    pageIndex: 0,
    dpi: 150
  }
});

Error Handling

Known errors are thrown as DocDocxConverterError.

import { DocDocxConverterError } from "doc-docx-converter";

try {
  await convertDocument(input, {
    inputFormat: "doc",
    outputFormat: "pdf"
  });
} catch (error) {
  if (error instanceof DocDocxConverterError) {
    console.error(error.code, error.message);
  } else {
    console.error(error);
  }
}

Error codes:

  • INVALID_INPUT
  • UNSUPPORTED_INPUT_FORMAT
  • UNSUPPORTED_OUTPUT_FORMAT
  • INPUT_TOO_LARGE
  • CONVERTER_NOT_READY
  • CONVERSION_FAILED

Performance Notes

  • The first conversion is slower because LibreOffice WASM must initialize.
  • Reuse a converter for servers and batch processing.
  • Large .doc files can consume significant memory.
  • For API servers, set upload limits and maxInputBytes.
  • Run conversions outside request-critical paths if you expect high concurrency.

Security Notes

Documents can be complex untrusted binary inputs. For public upload APIs:

  • Enforce file size limits.
  • Restrict accepted extensions and MIME types.
  • Use authentication/rate limits.
  • Run conversion workers with appropriate process isolation for your deployment.
  • Do not trust text or HTML extracted from documents without sanitization.

Supported Formats

Input:

  • doc
  • docx

Output:

  • pdf
  • docx
  • doc
  • odt
  • rtf
  • txt
  • html
  • png
  • jpg
  • svg

Build From Source

npm install
npm run typecheck
npm run test
npm run build

License

MIT