Skip to main content

TypeScript Tutorial

The previous nodeJS tutorial, but in TypeScript.


Download and install nodeJS v16+ from


run node --version from a terminal window to confirm installation.


Create a project directory, make it your working directory, and run from a terminal window:


npm init -y
npm i typescript
npm i ts-node
npm i @yumdocs/yumdocs


Besides transpilers, an alternative to ts-node on top of NodeJS, is Deno.

Also note that you do not have to install type declarations, which are packaged with @yumdocs/yumdocs.

Getting started

  1. Create a Word document named input.docx, type {{field}} and save it in the project directory.
  1. In the same project directory, create a file named index.ts and copy-paste:
import {YumTemplate} from '@yumdocs/yumdocs';
const t = new YumTemplate();
await t.load('./input.docx');
await t.render({field: 'Anything you see fit'});
await t.saveAs('./output.docx');
  1. In the same project directory, create a file named tsconfig.json and copy-paste:
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"target": "es2017"
  1. Open package.json with a text editor and add a type:
"type": "module",
  1. Open a terminal window in this project directory and run:

node --loader ts-node/esm index.ts

  1. output.docx has been generated and the {{field}} placeholder has been replaced with Anything you see fit.

Anything you see fit