Skip to main content

NodeJS Tutorial

Only 5 lines of code to merge an Office document with a JSON object.

Prerequisites

Download and install nodeJS v16+ from https://nodejs.org/.

Tip

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

Installation

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

Terminal

npm init -y
npm i @yumdocs/yumdocs

Getting started

  1. Create a Word document named input.docx, type {{field}} and save it in the project directory.
input.docx
{{field}}
  1. In the same project directory, create a file named index.mjs 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. Open a terminal window in this project directory and run:
Terminal

node index.mjs

Tip

Change the value of "main" for index.mjs in package.json to run node . instead.

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

Anything you see fit