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
- Create a Word document named
input.docx, type{{field}}and save it in the project directory.
input.docx
{{field}}
- In the same project directory, create a file named
index.mjsand 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');
- 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.
output.docxhas been generated and the{{field}}placeholder has been replaced withAnything you see fit.
output.docx
Anything you see fit