Document generator on the OpenSource stack
What will we get?
REST API to which you can send a request to generate a document with a data model using a previously loaded template and in response we will receive a generated document.
We could have ended there, but we will go further and bring this idea to life.
Prerequisites
Before you begin, make sure you have the following programs installed on your machine:
You will also need to clone the repository from GitHub. You can do this by running the command git clone https://github.com/your-repo/document-generator.git in the terminal.
Installation
To install, you need to clone the repository and install all dependencies using npm or yarn.
git clone https://github.com/nikolay-kochubashev/documentGenerator
cd documentGenerator
npm install
Launch
You can start the application using the npm start or yarn start command.
npm start
Deploying minio
Minio is a high-performance distributed object store. You can use Docker to install and run it. Here is an example command to run Minio in Docker:
docker run -p 9000:9000 --name minio1 \
-e "MINIO_ACCESS_KEY=your-access-key" \
-e "MINIO_SECRET_KEY=your-secret-key" \
minio/minio server /data
Once launched, Minio will be available at http://localhost:9090 .
To work with Minio from the application, you need to install and configure the Minio client. Client configuration example:
javascript
const Minio = require('minio')
const minioClient = new Minio.Client({
endPoint: 'localhost',
port: 9000,
useSSL: false,
accessKey: 'your-access-key',
secretKey: 'your-secret-key'
});
Usage
Once the application is installed and launched, you can start using it to create documents. An example of use is given in the application code.
Add access keys
Go to http://localhost:9090/access-keys and generate the keys. Add these keys to your Nodejs code in App.js as shown above.
Add new bucket
Go to http://localhost:9090 / and add a new bucket, for example “general-templates”
Download template
Upload a new document from the “complicated.docx” repository
Send a request via Postman
Enter “localhost:3005/api/render/general-templates/complicated.docx”
Save the answer as a file and you can see the result
You did it!
Conclusion
That's all! You now have a basic document generation application running using CarboneJS, Minio and NodeJS. This is a simple example, but can easily be extended to meet more complex needs.
I hope this guide was helpful. Happy coding!
about the author
My name is Nikolay Kochubashev, I am a solution and application architect in a large company in Kazakhstan. I specialize in low-code solutions and platform engineering.
https://solution-architect.kz https://low-code.kz
Join my blog in the telegram channel in Russian https://t.me/architectkz