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

@docwagen/unoserver-node

v2.2.0

Published

NodeJS Unoserver Wrapper to convert between different document formats

Readme

DocWagen Unoserver-Node

Unoserver-Node is a lightweight NodeJs wrapper for the unoserver python library that interacts with LibreOffice's Universal Network Objects (UNO) APIs to convert between different, supported document formats.

Requirements

To use this package in your node projects, you need to install the following on your computer (or server):

  1. LibreOffice: see installation instructions for your OS platform here
  2. Unoserver: see installation instructions here

Installation

npm i @docwagen/unoserver-node

Usage

Unoserver-Node provides three (3) modules that contain classes that support the three commands provided by unoserver (unoserver, unoconvert, and unocompare). It is worth noting that unoserver must be running before the other commands are run.

Running the unoserver command

The Unoserver class in this package supports the unoserver command which basically starts a libreoffice listener on a specified IP and port for unoconverter and unocompare to connect to to perform their operations.

The arguments or flags to the unoserver command are represented as attributes of an internal object in the Unoserver class. These attributes can be set via the public methods of the class. The builder creational design pattern is used here to allow method chaining of these setAttribute methods. The code snippet below illustrates this.
This way of representing command arguments as attributes and allowing the chaining of class setter methods is general to all the core classes.

const { Unoserver } = require("@docwagen/unoserver-node");
// constructor of all core can accept a `shouldDebug` optional, boolean parameter that specifies if execution messages should be printed to console
// setting `shouldDebug = true` is similar to calling the `allowDebug()` method on all objects of the core classes
const unoserver = new Unoserver(true);
const unoServerProcess = unoserver
  .setServerInterface("127.0.0.1")
  .setPort(2003)
  .makeDaemon()
  .run();

The following attributes can be set (their descriptions are mostly from the unoserver documentation):

  • serverInterface: the interface used by the XMLRPC server (for internal communication between unoserver and the other modules). This defaults to "127.0.0.1" if not set.

  • port: the port used by the XMLRPC server. This defaults to "2003".

  • unoInterface: the interface used by the LibreOffice server. Defaults to "127.0.0.1".

  • unoPort: the port used by the LibreOffice server. Defaults to "2002"

  • daemon: attribute to run unoserver as a daemon. This is the only attribute that does not have a direct setter method. The makeDaemon() method sets it internally.

  • libreOfficePath: the path to the LibreOffice executable.

  • libreOfficeUserProfilePath: the path to the LibreOffice user profile. Will default to a dyamically created temporary directory.

  • processIdFile: the path to a file that the LibreOffice Process ID will be written to. If unoserver is run as a daemon, this file will not be deleted when unoserver exits.

Running the unoconvert command

The Unoconverter class supports the unoconvert command. This connects to a listener to try to convert a document into different, supported formats. See the example code snippet below:

const { Unoconverter } = require("@docwagen/unoserver-node");
// relative paths are relative to the location unoserver was started in so, recommended to use absolute paths
const unoConvertProcess = new Unoconverter(true)
  .setConvertTo("pdf")
  .addFilterOption("UseLosslessCompression", true)
  .addFilterOption("Watermark", "DocWagen")
  .addFilterOption("EncryptFile", false)
  .setInFile("README.md")
  .setOutFile("README.pdf")
  .run();

// When a callback function is not set via the `setRunCallback(callback)` method, the run() method returns a promise
if (isPromise(unoConvertProcess)) {
  unoConvertProcess
    .then((data) => console.log(data))
    .catch((err) => {
      console.log("Unoconverter erroerd: ", err);
    });
}

// converting with the `execCmd` async method
const { stdout, stderr } = await new Unoconverter(true)
  .setConvertTo("pdf")
  .setInFile("README.md")
  .setOutFile("readme.pdf")
  .setPort(2003)
  .execCmd();

The server must be running before this command is executed. The following attributes are available:

  • convertTo: The file type/extension of the result output file (ex pdf). Required when using stdout.

  • inputFilter: The LibreOffice input filter to use (ex 'writer8'), if autodetect fails. This works for the newer unoserver v2.1.

  • outputFilter: The export filter to be used for conversions. It is selected automatically if not specified. This works for the newer unoserver v2.1.

  • filter: The export filter to use when converting. Deprecated alias for outputFilter. Stick with the setFilter method for old unoserver versions.

  • filterOption: Pass an option for the export filter, in name=value format. Use true/false for boolean values. The unoserver library supports repeating this flag for multiple options, this can be achieved by chaining the addFilterOption(name, value) method as many times as the number of filter options desired

  • host: The server host. Defaults to "127.0.0.1".

  • port: The server port, defaults to "2002".

  • hostLocation: This determines the handling of files and can only be one of three values - auto, remote, and local. If you run the client on the same machine as the server, it can be set to local, and the files are sent as paths. If they are different machines, it is remote and the files are sent as binary data. Default is auto, and it will send the file as a path if the host is 127.0.0.1 or localhost, and binary data for other hosts.

  • inFile: The path to the file to be converted (for stdin). This attribute is required.

  • outFile: The path to the converted file (for stdout). Also required.

A note on converting files

The export filter specifies the format, according to libreoffice specifications, to which a file is converted. While an attempt is typically made to automatically select this filter, in some cases, this fails and you have to explicitly specify a filter e.g. conversions from HTML to DOCX. See snippet below:

const { stdout, stderr } = await new Unoconverter(true)
  .setConvertTo("docx")
  .setInFile("PATH_TO_YOUR_HTML_FILE")
  .setOutFile(outFilePath)
  // No need to wrap string arguments with spaces in quotes for shell execution as the package automatically does this
  .setFilter("Office Open XML Text")
  .execCmd();

Running the unocompare command

The unocompare command is supported by the Unocompare class, which connects to a listener, tries to compare two documents, and converts the resulting document. See an example code snippet below:

const { Unocompare } = require("@docwagen/unoserver-node");
const unoCompareProcess = new Unocompare(true)
  .setOldFile(OLD_FILE_PATH)
  .setNewFile(NEW_FILE_PATH)
  .setOutFile(OUT_FILE_PATH)
  .run();

The server must also be running before this command is executed. The following attributes are available:

  • fileType: The file type/extension of the result output file (ex pdf). Required when using stdout.

  • host: The server host. Defaults to "127.0.0.1".

  • port: The server port, defaults to "2002".

  • hostLocation: This determines the handling of files and can only be one of three values - auto, remote, and local. If you run the client on the same machine as the server, it can be set to local, and the files are sent as paths. If they are different machines, it is remote and the files are sent as binary data. Default is auto, and it will send the file as a path if the host is 127.0.0.1 or localhost, and binary data for other hosts.

  • oldFile: The path to the older file to be compared with the original one (for stdin). This attribute is required.

  • newFile: The path to the newer file to be compared with the modified one (for stdin). Also required.

  • outFile: The path to the result of the comparison and converted file (for stdout). Also required.