TX Sheet Control

Node.js Server Applications

Topic

The Node.js server package, @txtextcontrol/tx-sheet-control-server, processes workbooks without a browser. It finds its engine and its fonts inside its own folder in node_modules, so a deployment must contain the installed package complete. It does not need the editor package, a browser or a network connection.

Requirements and Module Formats

  • Node.js 22 or newer, as the engines field of the package requires.
  • ES modules and CommonJS. The package provides both entry points: import { ServerSheetControl } from '@txtextcontrol/tx-sheet-control-server' and require('@txtextcontrol/tx-sheet-control-server'). TypeScript finds the type declarations through the same package name.

Deploy the Installed Package

Deploy node_modules/@txtextcontrol/tx-sheet-control-server complete, about 85 MB: its dist folder contains the engine, the runtime files and the fonts folder with the 30 supplied families and their notices. The package archive is not in the npm registry, so the build or the deployment installs it from the archive in your repository, as Install the npm Packages describes.

Warning

Complete Package. Do not copy only a JavaScript file of the package. The package loads further files from its folder at run time.

Use a Bundler

A bundler such as esbuild, webpack or Rollup must leave the package out of the bundle and load it from node_modules at run time. Bundled in, it fails at the first control with Cannot find module '…/private/runtime.cjs'. Mark it as external, for example with esbuild:

esbuild job.mjs --bundle --platform=node --format=esm --external:@txtextcontrol/tx-sheet-control-server --outfile=dist/job.mjs

Then deploy the bundle together with node_modules/@txtextcontrol/tx-sheet-control-server.

Build a Container Image

In a container image, install the dependencies inside the image and copy the application next to them, so that node_modules/@txtextcontrol/tx-sheet-control-server is complete:

FROM node:22-slim
WORKDIR /app
COPY package.json package-lock.json ./
COPY vendor ./vendor
RUN npm ci --omit=dev
COPY . .
CMD ["node", "job.mjs"]

COPY vendor ./vendor copies the package archive, which package.json references, before npm ci installs it. Pass the license as the environment variable TX_SHEET_LICENSE when you start the container, not in the image.

Fonts

The package uses the fonts in its dist/fonts folder. To add fonts, copy that folder, add your files and set the fontDirectory option or the environment variable TX_SHEET_FONT_DIRECTORY to the copy, as Custom Fonts shows. getFontCatalog() lists the families found. Fonts installed on the computer are not used.

Manage the Lifetime of Each Job

A ServerSheetControl holds a workbook and its processing state. Create one per independent job, await loading and saving, and release it with destroy() in finally:

import { ServerSheetControl, StreamType } from '@txtextcontrol/tx-sheet-control-server';

const control = new ServerSheetControl();
try {
    control.workbook.sheets.at(0).cell('A1').setText('Quarterly report');
    const pdf = await control.save(StreamType.PDF);
} finally {
    control.destroy();
}

A control that you reuse for unrelated requests must load a clean document for each of them. Limit the number of jobs that run at the same time, and stop a job with the signal option of load and save when its request is canceled.

Verify the Deployment

Run a job from the final deployment folder or container image, with the license it uses in production: load an XLSX file, calculate a formula and save a PDF with several pages. A successful import alone does not prove that the engine and the fonts are deployed.

Next Steps